Merge branch 'debian'
[hcoop/debian/courier-authlib.git] / authdaemond.c
index 44ad65e..3000907 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** Copyright 2000-2008 Double Precision, Inc.  See COPYING for
+** Copyright 2000-2018 Double Precision, Inc.  See COPYING for
 ** distribution information.
 */
 
@@ -23,9 +23,9 @@
 #include       "authdaemonrc.h"
 #include       "courierauthdebug.h"
 #include       "pkglibdir.h"
+#include       "courierauth.h"
 #include       "courierauthstaticlist.h"
 #include        "libhmac/hmac.h"
-#include        "cramlib.h"
 #include       <ltdl.h>
 
 
@@ -56,10 +56,11 @@ struct      sockaddr_un skun;
        strcat(skun.sun_path, ".tmp");
        unlink(skun.sun_path);
        if (bind(fd, (const struct sockaddr *)&skun, sizeof(skun)) ||
-               listen(fd, SOMAXCONN) ||
-               chmod(skun.sun_path, 0777) ||
-               rename(skun.sun_path, AUTHDAEMONSOCK) ||
-               fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+           listen(fd, SOMAXCONN) ||
+           chmod(skun.sun_path, 0777) ||
+           rename(skun.sun_path, AUTHDAEMONSOCK) ||
+           fcntl(fd, F_SETFD, FD_CLOEXEC) < 0 ||
+           fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
        {
                perror(AUTHDAEMONSOCK);
                close(fd);
@@ -440,9 +441,9 @@ static int printauth(struct authinfo *authinfo, void *vp)
                        return (1);
        if (authinfo->fullname)
        {
-               /* 
-                * Only the first field of the comma-seperated GECOS field is the 
-                * full username. 
+               /*
+                * Only the first field of the comma-seperated GECOS field is the
+                * full username.
                 */
                char *fullname;
                char *p;
@@ -458,7 +459,7 @@ static int printauth(struct authinfo *authinfo, void *vp)
                p = fullname;
                while (*p != ',' && *p != '\0')
                        p++;
-               *p=0; 
+               *p=0;
                retval = writeenvval(fd, "NAME", fullname);
                free(fullname);
                if(retval)
@@ -614,6 +615,7 @@ static void enumerate(int fd)
        struct authstaticinfolist *l;
 
        ei.fd=fd;
+       ei.buf_ptr=ei.buffer;
        ei.buf_left=0;
 
        for (l=modulelist; l; l=l->next)
@@ -1023,7 +1025,8 @@ int start()
                saddr_len=sizeof(saddr);
                if ((fd=accept(s, &saddr, &saddr_len)) < 0)
                        continue;
-               if (fcntl(fd, F_SETFL, 0) < 0)
+               if (fcntl(fd, F_SETFL, 0) < 0 ||
+                   fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
                {
                        perror("CRIT: fcntl() failed");
                }
@@ -1032,18 +1035,3 @@ int start()
                close(fd);
        }
 }
-
-int main(int argc, char **argv)
-{
-       courier_authdebug_login_init();
-
-       if (argc > 1)
-       {
-               fprintf(stderr, "Error: authdaemond no longer handles its own daemonizing.\n"
-                       "Use new startup script.\n");
-               exit(1);
-       }
-
-       start();
-       return (0);
-}