X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=etc%2Fafpd%2Fuid.c;h=a3e4d59704592e9626734bdde323a992953241b1;hb=130d356c840ea83c31c4724c8ae92660360eb07b;hp=5173c32b2117833b51a6b7284a0f995ec34b23c8;hpb=3f8355e24db08a7828f6eeafc02ff3dfd8ff4a39;p=netatalk.git diff --git a/etc/afpd/uid.c b/etc/afpd/uid.c index 5173c32b..a3e4d597 100644 --- a/etc/afpd/uid.c +++ b/etc/afpd/uid.c @@ -1,5 +1,4 @@ /* - * $Id: uid.c,v 1.9 2002-01-19 21:29:55 jmarcus Exp $ * code: jeff@univrel.pr.uconn.edu * * These functions are abstracted here, so that all calls for resolving @@ -11,107 +10,3 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ -/* don't compile this file at all unless FORCE_UIDGID is set */ -#ifdef FORCE_UIDGID - -#include -#include -#include - -/* functions for username and group */ -#include -#include -#include "uid.h" - -#ifdef HAVE_UNISTD_H -#include -#endif /* HAVE_UNISTD_H */ - -void save_uidgid ( pair ) -uidgidset **pair; -{ - /* allocate the memory */ - pair = malloc ( sizeof ( uidgidset ) ); - - /* then assign the values */ - (*pair)->uid = geteuid (); - (*pair)->gid = getegid (); -} /* end function void save_uidgid ( pair ) */ - -void restore_uidgid ( pair ) -uidgidset **pair; -{ - if ( seteuid ( (*pair)->uid ) < 0 ) - LOG(log_error, logtype_default, "restore_uidgid: unable to seteuid '%s': %m", - (*pair)->uid ); - if ( setegid ( (*pair)->gid ) < 0 ) - LOG(log_error, logtype_default, "restore_uidgid: unable to setegid '%s': %m", - (*pair)->gid ); -} /* end function void restore_uidgid ( pair ) */ - -void set_uidgid ( this_volume ) -const struct vol *this_volume; -{ - int uid, gid; /* derived ones go in here */ - - /* check to see if we have to switch users */ - if ( uid = user_to_uid ( (this_volume)->v_forceuid ) ) { - if ( seteuid ( uid ) < 0 ) - LOG(log_error, logtype_default, "set_uidgid: unable to seteuid '%s': %m", - (this_volume)->v_forceuid ); - } /* end of checking for (this_volume)->v_forceuid */ - - /* check to see if we have to switch groups */ - if ( gid = group_to_gid ( (this_volume)->v_forcegid ) ) { - if ( seteuid ( gid ) < 0 ) - LOG(log_error, logtype_default, "set_uidgid: unable to setegid '%s': %m", - (this_volume)->v_forcegid ); - } /* end of checking for (this_volume)->v_forcegid */ - -} /* end function void set_uidgid ( username, group ) */ - -int user_to_uid ( username ) -char *username; -{ - struct passwd *this_passwd; - - /* free memory for pointer */ - this_passwd = malloc ( sizeof ( struct passwd ) ); - - /* check for anything */ - if ( strlen ( username ) < 1 ) return 0; - - /* grab the /etc/passwd record relating to username */ - this_passwd = getpwnam ( username ); - - /* return false if there is no structure returned */ - if (this_passwd == NULL) return 0; - - /* return proper uid */ - return this_passwd->pw_uid; - -} /* end function int user_to_uid ( username ) */ - -int group_to_gid ( group ) -char *group; -{ - struct group *this_group; - - /* free memory for pointer */ - this_group = malloc ( sizeof ( struct group ) ); - - /* check for anything */ - if ( strlen ( group ) < 1 ) return 0; - - /* grab the /etc/groups record relating to group */ - this_group = getgrnam ( group ); - - /* return false if there is no structure returned */ - if (this_group == NULL) return 0; - - /* return proper gid */ - return this_group->gr_gid; - -} /* end function int group_to_gid ( group ) */ - -#endif /* FORCE_UIDGID */