static int switch_user_permanently(const struct logInfo *log) {
    const gid_t group = getegid();
    const uid_t user = geteuid();

    if (!(log->flags & LOG_FLAG_SU)) {
        return 0;
    }

    if (user != log->suUid) {
        message(MESS_ERROR, "current euid (%u) does not match uid of log configuration (%u) (pid %d)\n",
                (unsigned) user, (unsigned) log->suUid, getpid());
        return 1;
    }
    if (group != log->suGid) {
        message(MESS_ERROR, "current egid (%u) does not match gid of log configuration (%u) (pid %d)\n",
                (unsigned) group, (unsigned) log->suGid, getpid());
        return 1;
    }

    /* we are already the final configuration specified user/group */
    if (getuid() == user && getgid() == group) {
        return 0;
    }

    /* switch to full root first */
    if (setgid(getgid()) || setuid(getuid())) {
        message(MESS_ERROR, "error getting rid of euid != uid (pid %d): %s\n",
                getpid(), strerror(errno));
        return 1;
    }

    message(MESS_DEBUG, "switching uid to %u and gid to %u permanently (pid %d)\n",
            (unsigned) user, (unsigned) group, getpid());
    if (setgid(group) || setuid(user)) {
        message(MESS_ERROR, "error switching uid to %u and gid to %u (pid %d): %s\n",
                (unsigned) user, (unsigned) group, getpid(), strerror(errno));
        return 1;
    }

    if (user != ROOT_UID && setuid(ROOT_UID) != -1) {
        message(MESS_ERROR, "failed to switch user permanently, able to switch back (pid %d)\n",
                getpid());
        return 1;
    }

    return 0;
}
static int switch_user_permanently(const struct logInfo *log) {
    const gid_t group = getegid();
    const uid_t user = geteuid();

    if (!(log->flags & LOG_FLAG_SU)) {
        return 0;
    }

    if (user != log->suUid) {
        message(MESS_ERROR, "current euid (%u) does not match uid of log configuration (%u) (pid %d)\n",
                (unsigned) user, (unsigned) log->suUid, getpid());
        return 1;
    }
    if (group != log->suGid) {
        message(MESS_ERROR, "current egid (%u) does not match gid of log configuration (%u) (pid %d)\n",
                (unsigned) group, (unsigned) log->suGid, getpid());
        return 1;
    }

     
    if (getuid() == user && getgid() == group) {
        return 0;
    }

     
    if (setgid(getgid()) || setuid(getuid())) {
        message(MESS_ERROR, "error getting rid of euid != uid (pid %d): %s\n",
                getpid(), strerror(errno));
        return 1;
    }

    message(MESS_DEBUG, "switching uid to %u and gid to %u permanently (pid %d)\n",
            (unsigned) user, (unsigned) group, getpid());
    if (setgid(group) || setuid(user)) {
        message(MESS_ERROR, "error switching uid to %u and gid to %u (pid %d): %s\n",
                (unsigned) user, (unsigned) group, getpid(), strerror(errno));
        return 1;
    }

    if (user != ROOT_UID && setuid(ROOT_UID) != -1) {
        message(MESS_ERROR, "failed to switch user permanently, able to switch back (pid %d)\n",
                getpid());
        return 1;
    }

    return 0;
}