iRODS/server/core/src/miscServerFunct.cpp
int
changeToServiceUser() {
    int prev_errno, my_errno;

    if ( !isServiceUserSet() ) {
        /* not configured ... just return */
        return 0;
    }

#ifndef windows_platform
    prev_errno = errno;

    if ( setegid( ServiceGid ) == -1 ) {
        /* if only setegid fails, log error but continue */
        rodsLog( LOG_ERROR, "changeToServiceUser: setegid() failed, errno = %d", errno );
        errno = prev_errno;
    }

    if ( seteuid( ServiceUid ) == -1 ) {
        my_errno = errno;
        errno = prev_errno;
        rodsLogError( LOG_ERROR, SYS_USER_NO_PERMISSION - my_errno,
                      "changeToServiceUser: can't change to service user id" );
        return SYS_USER_NO_PERMISSION - my_errno;
    }
#endif

    return 0;
}
/* changeToServiceUser - set the process effective uid to that of the
 *                       configured service user. Normally used to give
 *                       up root permission.
 */
set the process effective uid to that of the
configured service user. Normally used to give
up root permission.
set the process effective uid to that of the configured service user . Normally used to give up root permission .
int
changeToServiceUser() {
    int prev_errno, my_errno;
    if ( !isServiceUserSet() ) {
        return 0;
    }
#ifndef windows_platform
    prev_errno = errno;
    if ( setegid( ServiceGid ) == -1 ) {
        rodsLog( LOG_ERROR, "changeToServiceUser: setegid() failed, errno = %d", errno );
        errno = prev_errno;
    }
    if ( seteuid( ServiceUid ) == -1 ) {
        my_errno = errno;
        errno = prev_errno;
        rodsLogError( LOG_ERROR, SYS_USER_NO_PERMISSION - my_errno,
                      "changeToServiceUser: can't change to service user id" );
        return SYS_USER_NO_PERMISSION - my_errno;
    }
#endif
    return 0;
}
int changeToServiceUser ( ) { int prev_errno , my_errno ; if ( ! isServiceUserSet ( ) ) { return 0 ; } #ifndef windows_platform prev_errno = errno ; if ( setegid ( ServiceGid ) == -1 ) { rodsLog ( LOG_ERROR , " " , errno ) ; errno = prev_errno ; } if ( seteuid ( ServiceUid ) == -1 ) { my_errno = errno ; errno = prev_errno ; rodsLogError ( LOG_ERROR , SYS_USER_NO_PERMISSION - my_errno , " " ) ; return SYS_USER_NO_PERMISSION - my_errno ; } #endif return 0 ; }
changeToServiceUser - set the process effective uid to that of the
                       configured service user.
changeToServiceUser - set the process effective uid to that of the configured service user .
/* not configured ... just return */ /* if only setegid fails, log error but continue */