]> arthur.barton.de Git - netatalk.git/blobdiff - etc/papd/main.c
replaced all #include <sys/syslog.h> with #include <syslog.h>
[netatalk.git] / etc / papd / main.c
index 4b2239b390e3a03cf7c6292aaa9db9fae17a3b14..94e3ec0ec594ee8a620829c12179b9f16c3e9cff 100644 (file)
@@ -1,29 +1,62 @@
 /*
+ * $Id: main.c,v 1.14 2002-01-03 17:49:39 sibaz Exp $
+ *
  * Copyright (c) 1990,1995 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
 #include <sys/param.h>
-#include <sys/types.h>
 #include <sys/time.h>
 #include <sys/uio.h>
 #if defined( sun ) && defined( __svr4__ )
 #include </usr/ucbinclude/sys/file.h>
-#else sun __svr4__
+#else /* sun && __svr4__ */
 #include <sys/file.h>
-#endif sun __svr4__
+#endif /* sun && __svr4__ */
 #include <sys/socket.h>
-#include <sys/syslog.h>
+#include <syslog.h>
+
+/* POSIX.1 sys/wait.h check */
+#include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
 #include <sys/wait.h>
+#endif /* HAVE_SYS_WAIT_H */
+#ifndef WEXITSTATUS
+#define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
+#endif /* ! WEXITSTATUS */
+#ifndef WIFEXITED
+#define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
+#endif /* ! WIFEXITED */
+
 #include <errno.h>
 
+/* STDC check */
+#if STDC_HEADERS
 #include <string.h>
+#else /* STDC_HEADERS */
+#ifndef HAVE_STRCHR
+#define strchr index
+#define strrchr index
+#endif /* HAVE_STRCHR */
+char *strchr (), *strrchr ();
+#ifndef HAVE_MEMCPY
+#define memcpy(d,s,n) bcopy ((s), (d), (n))
+#define memmove(d,s,n) bcopy ((s), (d), (n))
+#endif /* ! HAVE_MEMCPY */
+#endif /* STDC_HEADERS */
+
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <netdb.h>
 #include <fcntl.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif /* HAVE_UNISTD_H */
 
 #include <netatalk/endian.h>
 #include <netatalk/at.h>
 #include <atalk/pap.h>
 #include <atalk/paths.h>
 #include <atalk/util.h>
+#include <atalk/nbp.h>
 
 #include "printer.h"
+#include "printcap.h"
+#include "session.h"
+#include "uam_auth.h"
 
 #define _PATH_PAPDPPDFILE      ".ppd"
 
@@ -51,24 +88,37 @@ struct printer      *printer = NULL;
 char           *version = VERSION;
 static char      *pidfile = _PATH_PAPDLOCK;
 
+char           *uamlist;
+char           *uampath = _PATH_PAPDUAMPATH;
+
+/* Prototypes for locally used functions */
+int getstatus( struct printer *pr, char *buf );
+int rprintcap( struct printer *pr );
+void getprinters( char *cf );
+
+
 /* this only needs to be used by the server process */
 static void papd_exit(const int i)
 {
   server_unlock(pidfile);
+  auth_unload();
   exit(i);
 }
 
 #if !defined( ibm032 ) && !defined( _IBMR2 )
     void
-#endif ibm032 _IBMR2
+#endif /* ! ibm032 && ! _IBMR2 */
 die( n )
     int                        n;
 {
     struct printer     *pr;
+    struct at_addr     addr;
+
+    memset(&addr, 0, sizeof(addr));
 
     for ( pr = printers; pr; pr = pr->p_next ) {
        if ( pr->p_flags & P_REGISTERED ) {
-           if ( nbp_unrgstr( pr->p_name, pr->p_type, pr->p_zone ) < 0 ) {
+           if ( nbp_unrgstr( pr->p_name, pr->p_type, pr->p_zone, &addr ) < 0 ) {
                syslog( LOG_ERR, "can't unregister %s:%s@%s\n", pr->p_name,
                        pr->p_type, pr->p_zone );
                papd_exit( n + 1 );
@@ -82,7 +132,7 @@ die( n )
 
 #if !defined( ibm032 ) && !defined( _IBMR2 )
     void
-#endif ibm032 _IBMR2
+#endif /* ! ibm032 && ! _IBMR2 */
 reap()
 {
     int                status;
@@ -110,12 +160,11 @@ reap()
 
 char           rbuf[ 255 + 1 + 8 ];
 
-main( ac, av )
+int main( ac, av )
     int                ac;
     char       **av;
 {
     extern char         *optarg;
-    extern int          optind;
 
     ATP                        atp;
     struct atp_block   atpb;
@@ -148,21 +197,21 @@ main( ac, av )
 #ifdef __svr4__
     defprinter.p_flags = P_PIPED;
     defprinter.p_printer = "/usr/bin/lp -T PS";
-#else
+#else /* __svr4__ */
     defprinter.p_flags = P_SPOOLED;
     defprinter.p_printer = "lp";
-#endif
+#endif /* __svr4__ */
     defprinter.p_operator = "operator";
     defprinter.p_spool = _PATH_PAPDSPOOLDIR;
 #ifdef ABS_PRINT
     defprinter.p_role = NULL;
     defprinter.p_srvid = 0;
-#endif ABS_PRINT
+#endif /* ABS_PRINT */
     defprinter.p_pagecost = 200;               /* default cost */
     defprinter.p_pagecost_msg = NULL;
     defprinter.p_lock = "lock";
 
-    while (( c = getopt( ac, av, "adf:p:P:" )) != EOF ) {
+    while (( c = getopt( ac, av, "adf:p:P:v" )) != EOF ) {
        switch ( c ) {
        case 'a' :              /* for compatibility with old papd */
            break;
@@ -183,6 +232,11 @@ main( ac, av )
            pidfile = optarg;
            break;
 
+       case 'v' :              /* version */
+           printf( "papd (version %s)\n", VERSION );
+           exit ( 1 );
+           break;
+
        default :
            fprintf( stderr,
                    "Usage:\t%s [ -d ] [ -f conffile ] [ -p printcap ]\n",
@@ -216,9 +270,9 @@ main( ac, av )
     }
 #ifdef ultrix
     openlog( p, LOG_PID );
-#else ultrix
+#else /* ultrix */
     openlog( p, LOG_NDELAY|LOG_PID, LOG_LPR );
-#endif ultrix
+#endif /* ultrix */
 
     syslog( LOG_INFO, "restart (%s)", version );
 
@@ -236,6 +290,12 @@ main( ac, av )
                    pr->p_zone );
            die( 1 );
        }
+       if ( pr->p_flags & P_AUTH ) {
+               syslog( LOG_INFO, "Authentication enabled: %s", pr->p_name );
+       }
+       else {
+               syslog( LOG_INFO, "Authentication disabled: %s", pr->p_name );
+       }
        syslog( LOG_INFO, "register %s:%s@%s", pr->p_name, pr->p_type,
                pr->p_zone );
        pr->p_flags |= P_REGISTERED;
@@ -258,6 +318,11 @@ main( ac, av )
        papd_exit( 1 );
     }
 
+    /*
+     * Load UAMS
+     */
+    auth_load(uampath, uamlist);
+
     /*
      * Begin accepting connections.
      */
@@ -278,10 +343,10 @@ main( ac, av )
            if ( FD_ISSET( atp_fileno( pr->p_atp ), &fdset )) {
                int             err = 0;
 
-               bzero( &sat, sizeof( struct sockaddr_at ));
+               memset( &sat, 0, sizeof( struct sockaddr_at ));
 #ifdef BSD4_4
                sat.sat_len = sizeof( struct sockaddr_at );
-#endif BSD4_4
+#endif /* BSD4_4 */
                sat.sat_family = AF_APPLETALK;
                sat.sat_addr.s_net = ATADDR_ANYNET;
                sat.sat_addr.s_node = ATADDR_ANYNODE;
@@ -430,17 +495,18 @@ main( ac, av )
                if ( atp_sresp( pr->p_atp, &atpb ) < 0 ) {
                    syslog( LOG_ERR, "atp_sresp: %m" );
                }
-#endif notdef
+#endif /* notdef */
            }
        }
     }
+    return 0;
 }
 
 /*
  * We assume buf is big enough for 255 bytes of data and a length byte.
  */
-    int
-getstatus( pr, buf )
+
+int getstatus( pr, buf )
     struct printer     *pr;
     char               *buf;
 {
@@ -473,7 +539,7 @@ getstatus( pr, buf )
 char   *pgetstr();
 char   *getpname();
 
-getprinters( cf )
+void getprinters( cf )
     char       *cf;
 {
     char               buf[ 1024 ], area[ 1024 ], *a, *p, *name, *type, *zone;
@@ -495,7 +561,7 @@ getprinters( cf )
            perror( "malloc" );
            exit( 1 );
        }
-       bzero( pr, sizeof( struct printer ));
+       memset( pr, 0, sizeof( struct printer ));
 
        name = defprinter.p_name;
        type = defprinter.p_type;
@@ -570,6 +636,32 @@ getprinters( cf )
            strcpy( pr->p_printer, p );
        }
 
+       /*
+        * Do we want authenticated printing?
+        */
+       if ((p = pgetstr( "ca", &a )) != NULL ) {
+           if ((pr->p_authprintdir = (char *)malloc(strlen(p)+1)) == NULL) {
+               perror( "malloc" );
+               exit(1);
+           }
+           strcpy( pr->p_authprintdir, p );
+           pr->p_flags |= P_AUTH;
+           pr->p_flags |= P_AUTH_CAP;
+       } else { pr->p_authprintdir = NULL; }
+
+       if ( pgetflag( "sp" ) == 1 ) {
+           pr->p_flags |= P_AUTH;
+           pr->p_flags |= P_AUTH_PSSP;
+       }
+
+       if ((p = pgetstr("am", &a)) != NULL ) {
+               if ((uamlist = (char *)malloc(strlen(p)+1)) == NULL ) {
+                       perror("malloc");
+                       exit(1);
+               }
+               strcpy(uamlist, p);
+       }
+
        if ( pr->p_flags & P_SPOOLED ) {
            /*
             * Get operator name.
@@ -602,7 +694,7 @@ getprinters( cf )
     }
 }
 
-rprintcap( pr )
+int rprintcap( pr )
     struct printer     *pr;
 {
     char               buf[ 1024 ], area[ 1024 ], *a, *p;
@@ -663,7 +755,7 @@ rprintcap( pr )
            } else {
                pr->p_srvid = c;
            }
-#endif ABS_PRINT
+#endif /* ABS_PRINT */
        }
 
 
@@ -714,11 +806,11 @@ rprintcap( pr )
         * Must Kerberos authenticate?
         */
        if ( pgetflag( "ka" ) == 1 ) {
-           pr->p_flags |= P_AUTH;
+           pr->p_flags |= P_KRB;
        } else {
-           pr->p_flags &= ~P_AUTH;
+           pr->p_flags &= ~P_KRB;
        }
-#endif
+#endif /* KRB */
 
        endprent();
     }