hcoop release
[hcoop/debian/courier-authlib.git] / authdaemond.c
index 0387384..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.
 */
 
 #include       <fcntl.h>
 #include       <ctype.h>
 #include       "numlib/numlib.h"
-#include       "liblock/config.h"
 #include       "liblock/liblock.h"
 #include       "auth.h"
 #include       "authdaemonrc.h"
 #include       "courierauthdebug.h"
 #include       "pkglibdir.h"
-#include       "authstaticlist.h"
+#include       "courierauth.h"
+#include       "courierauthstaticlist.h"
 #include        "libhmac/hmac.h"
-#include        "cramlib.h"
 #include       <ltdl.h>
 
-static const char rcsid[]="$Id: authdaemond.c,v 1.34 2008/07/10 02:43:55 mrsam Exp $";
 
 #ifndef        SOMAXCONN
 #define        SOMAXCONN       5
 #endif
 
-#include       "authstaticlist.h"
+#include       "courierauthstaticlist.h"
 
 static unsigned ndaemons;
 
@@ -58,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);
@@ -442,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;
@@ -460,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)
@@ -616,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)
@@ -848,7 +848,7 @@ char        *p;
 
 static int sighup_pipe= -1;
 
-static RETSIGTYPE sighup(int n)
+static void sighup(int n)
 {
        if (sighup_pipe >= 0)
        {
@@ -856,14 +856,11 @@ static RETSIGTYPE sighup(int n)
                sighup_pipe= -1;
        }
        signal(SIGHUP, sighup);
-#if    RETSIGTYPE != void
-       return (1);
-#endif
 }
 
 static int sigterm_received=0;
 
-static RETSIGTYPE sigterm(int n)
+static void sigterm(int n)
 {
        sigterm_received=1;
        if (sighup_pipe >= 0)
@@ -876,10 +873,6 @@ static RETSIGTYPE sigterm(int n)
                kill(0, SIGTERM);
                _exit(0);
        }
-
-#if    RETSIGTYPE != void
-       return (0);
-#endif
 }
 
 static int startchildren(int *pipefd)
@@ -1032,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");
                }
@@ -1041,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);
-}