openafs: Improved calling of get-token script
[hcoop/debian/courier-authlib.git] / preauthuserdbcommon.c
index 6c29778..9fcafe3 100644 (file)
 #if    HAVE_UNISTD_H
 #include       <unistd.h>
 #endif
 #if    HAVE_UNISTD_H
 #include       <unistd.h>
 #endif
+#include <sys/types.h>
+#include <sys/wait.h>
 
 #include       "auth.h"
 #include       "courierauthdebug.h"
 #include       "userdb/userdb.h"
 
 #include       "auth.h"
 #include       "courierauthdebug.h"
 #include       "userdb/userdb.h"
-
-
-#define TOKEN_CMD "/etc/courier/get-token "
+#include       "numlib/numlib.h"
 
 int auth_userdb_pre_common(const char *userid, const char *service,
        int needpass,
 
 int auth_userdb_pre_common(const char *userid, const char *service,
        int needpass,
@@ -108,18 +108,24 @@ int       rc;
        auth.quota=udb->udb_quota;
 
         /* Get tokens for AFS */
        auth.quota=udb->udb_quota;
 
         /* Get tokens for AFS */
-        { char uidstr[32] = "<null>";
-          char *token_cmd;
+       {
           if (auth.sysuserid)
           if (auth.sysuserid)
-            {
-              snprintf(uidstr, sizeof(uidstr), "%ld", (long)*auth.sysuserid);
-              if ((token_cmd=malloc(sizeof(TOKEN_CMD)+strlen(uidstr))))
-                {
-                  strcat(strcpy(token_cmd, TOKEN_CMD),uidstr);
-                  system(token_cmd);
-                  free(token_cmd);
-                }
-            }
+          {
+           pid_t pid = fork ();
+
+           if (pid == 0)
+           {
+             char uidstr[32] = "<null>";
+             snprintf(uidstr, sizeof(uidstr), "%ld", (long)*auth.sysuserid);
+
+             libmail_changeuidgid (*auth.sysuserid, auth.sysgroupid);
+             execl ("/etc/courier/get-token", "get-token", uidstr, NULL);
+           }
+           else
+           {
+              waitpid (pid, NULL, 0);
+           }
+         }
         }
 
        courier_authdebug_authinfo("DEBUG: authuserdb: ", &auth, 0, passwords);
         }
 
        courier_authdebug_authinfo("DEBUG: authuserdb: ", &auth, 0, passwords);