]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/uid.c
BIG commit to improve code style using astyle as well as fix up CNID DB
[netatalk.git] / etc / afpd / uid.c
index b8a256a1269d9990a97fd5f98a3c1b4b88dc7ad5..3758f4d5b326928a4318e09ac3af7533f7e3a1d0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: uid.c,v 1.2 2001-01-27 17:54:26 itlm019 Exp $
+ * $Id: uid.c,v 1.5.2.1 2001-12-03 05:01:04 jmarcus Exp $
  * code: jeff@univrel.pr.uconn.edu
  *
  * These functions are abstracted here, so that all calls for resolving
@@ -7,12 +7,12 @@
  * across the package).
  */
 
-/* don't compile this file at all unless FORCE_UIDGID is set */
-#ifdef FORCE_UIDGID
-
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
+#endif /* HAVE_CONFIG_H */
+
+/* don't compile this file at all unless FORCE_UIDGID is set */
+#ifdef FORCE_UIDGID
 
 #include <stdio.h>
 #include <string.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif
+#endif /* HAVE_UNISTD_H */
 
 void save_uidgid ( pair )
-       uidgidset *pair;
+uidgidset **pair;
 {
-       (pair)->uid = geteuid ();
-       (pair)->gid = getegid ();
+    /* 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;
+uidgidset **pair;
 {
-       if ( seteuid ( (pair)->uid ) < 0 )
-               syslog ( LOG_ERR, "restore_uidgid: unable to seteuid '%s': %m",
-                       (pair)->uid );
-       if ( setegid ( (pair)->gid ) < 0 )
-               syslog ( LOG_ERR, "restore_uidgid: unable to setegid '%s': %m",
-                       (pair)->gid );
+    if ( seteuid ( (*pair)->uid ) < 0 )
+        syslog ( LOG_ERR, "restore_uidgid: unable to seteuid '%s': %m",
+                 (*pair)->uid );
+    if ( setegid ( (*pair)->gid ) < 0 )
+        syslog ( LOG_ERR, "restore_uidgid: unable to setegid '%s': %m",
+                 (*pair)->gid );
 } /* end function void restore_uidgid ( pair ) */
 
 void set_uidgid ( this_volume )
-       struct vol      *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 )
-                       syslog ( LOG_ERR, "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 )
-                       syslog ( LOG_ERR, "set_uidgid: unable to setegid '%s': %m",
-                               (this_volume)->v_forcegid );
-       } /* end of checking for (this_volume)->v_forcegid */
+    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 )
+            syslog ( LOG_ERR, "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 )
+            syslog ( LOG_ERR, "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;
+char   *username;
 {
-       struct passwd *this_passwd;
+    struct passwd *this_passwd;
 
-       /* check for anything */
-       if ( strlen ( username ) < 1 ) return 0;
+    /* free memory for pointer */
+    this_passwd = malloc ( sizeof ( struct passwd ) );
 
-       /* grab the /etc/passwd record relating to username */
-       this_passwd = getpwnam ( username );
+    /* check for anything */
+    if ( strlen ( username ) < 1 ) return 0;
 
-       /* return false if there is no structure returned */
-       if (this_passwd == NULL) return 0;
+    /* grab the /etc/passwd record relating to username */
+    this_passwd = getpwnam ( username );
 
-       /* return proper uid */
-       return this_passwd->pw_uid;
+    /* 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;
+char   *group;
 {
-       struct group *this_group;
+    struct group *this_group;
+
+    /* free memory for pointer */
+    this_group = malloc ( sizeof ( struct group ) );
 
-       /* check for anything */
-       if ( strlen ( group ) < 1 ) return 0;
+    /* check for anything */
+    if ( strlen ( group ) < 1 ) return 0;
 
-       /* grab the /etc/groups record relating to group */
-       this_group = getgrnam ( group );
+    /* 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 false if there is no structure returned */
+    if (this_group == NULL) return 0;
 
-       /* return proper gid */
-       return this_group->gr_gid;
+    /* return proper gid */
+    return this_group->gr_gid;
 
 } /* end function int group_to_gid ( group ) */
 
-#endif FORCE_UIDGID
+#endif /* FORCE_UIDGID */