1 /* user.c - set user id, group id and group access list
3 * Copyright 1999 by PM Lashley and The OpenLDAP Foundation.
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
14 #if defined(HAVE_PWD_H) && defined(HAVE_GRP_H)
22 #include <ac/unistd.h>
28 * Set real and effective user id and group id, and group access list
32 slap_init_user( char *user, char *group )
34 uid_t uid = (gid_t) -1;
35 gid_t gid = (gid_t) -1;
39 if ( isdigit( (unsigned char) *user )) {
42 pwd = getpwuid( uid );
46 pwd = getpwnam( user );
49 Debug( LDAP_DEBUG_ANY, "No passwd entry for user %s\n",
55 user = (pwd != NULL ? ch_strdup( pwd->pw_name ) : NULL);
68 if ( isdigit( (unsigned char) *group )) {
71 grp = getgrgid( gid );
75 grp = getgrnam( group );
80 Debug( LDAP_DEBUG_ANY, "No group entry for group %s\n",
89 if ( getuid() == 0 && initgroups( user, gid ) != 0 ) {
90 Debug( LDAP_DEBUG_ANY,
91 "Could not set the group access (gid) list\n", 0, 0, 0 );
102 if ( setgid( gid ) != 0 ) {
103 Debug( LDAP_DEBUG_ANY, "Could not set real group id to %d\n",
107 if ( setegid( gid ) != 0 ) {
108 Debug( LDAP_DEBUG_ANY, "Could not set effective group id to %d\n",
115 if ( setuid( uid ) != 0 ) {
116 Debug( LDAP_DEBUG_ANY, "Could not set effective user id to %d\n",
120 if ( seteuid( uid ) != 0 ) {
121 Debug( LDAP_DEBUG_ANY, "Could not set real user id to %d\n",
128 #endif /* HAVE_PWD_H && HAVE_GRP_H */