]> arthur.barton.de Git - netatalk.git/commitdiff
Remove all references to CAPDIR. Add a config file option for authprintdir
authorsamnoble <samnoble>
Wed, 23 May 2001 23:55:23 +0000 (23:55 +0000)
committersamnoble <samnoble>
Wed, 23 May 2001 23:55:23 +0000 (23:55 +0000)
authprintdir is configured per-server and per printer.

The 'ca' flag in papd.conf now takes a directory ie "ca=/tmp/print"

etc/afpd/afp_asp.c
etc/afpd/afp_options.c
etc/afpd/auth.c
etc/afpd/globals.h
etc/afpd/main.c
etc/papd/lp.c
etc/papd/main.c
etc/papd/printer.h

index ceacf85906bd2bf47ccdfbb28fc7aa6cd21e6d3a..b2ef07e333eb6f08f35649fb854d3b6ab124f0cd 100644 (file)
 
 extern struct oforks   *writtenfork;
 
-/* for CAP style authenticated printing */
-#ifdef CAPDIR
-extern int addr_net, addr_node, addr_uid;
-#endif /* CAPDIR */
-
 static AFPObj *child;
 
 static __inline__ void afp_asp_close(AFPObj *obj)
@@ -102,11 +97,6 @@ void afp_over_asp(AFPObj *obj)
     struct sigaction  action;
     int                func, ccnt = 0, reply = 0;
 
-#ifdef CAPDIR
-    char addr_filename[256];
-    struct stat cap_st;
-#endif /* CAPDIR */
-
     obj->exit = afp_asp_die;
     obj->reply = (int (*)()) asp_cmdreply;
     obj->attention = (int (*)(void *, AFPUserBytes)) asp_attention;
@@ -131,11 +121,6 @@ void afp_over_asp(AFPObj *obj)
        afp_asp_die(1);
     }
 
-#ifdef CAPDIR
-    addr_net = ntohs( asp->asp_sat.sat_addr.s_net );
-    addr_node  = asp->asp_sat.sat_addr.s_node;
-#endif /* CAPDIR */
-
     syslog( LOG_INFO, "session from %u.%u:%u on %u.%u:%u",
            ntohs( asp->asp_sat.sat_addr.s_net ),
            asp->asp_sat.sat_addr.s_node, asp->asp_sat.sat_port,
@@ -146,21 +131,28 @@ void afp_over_asp(AFPObj *obj)
     while ((reply = asp_getrequest(asp))) {
       switch (reply) {
       case ASPFUNC_CLOSE :
-       afp_asp_close(obj);
-       syslog( LOG_INFO, "done" );
+       if (obj->options.authprintdir) {
+         char addr_filename[256];
+         struct stat cap_st;
+
+         sprintf(addr_filename, "%s/net%d.%dnode%d", obj->options.authprintdir, 
+               ntohs( asp->asp_sat.sat_addr.s_net )/256, 
+               ntohs( asp->asp_sat.sat_addr.s_net )%256, 
+               asp->asp_sat.sat_addr.s_node );
 
-#ifdef CAPDIR
-       sprintf(addr_filename, "%s/net%d.%dnode%d", CAPDIR, addr_net/256, addr_net%256, addr_node);
-       if(stat(addr_filename, &cap_st) == 0) {
+         if(stat(addr_filename, &cap_st) == 0) {
                if(unlink(addr_filename) == 0) {
                        syslog(LOG_INFO, "removed %s", addr_filename);
                } else {
                        syslog(LOG_INFO, "error removing %s: %m", addr_filename);
                }
-       } else {
+         } else {
                syslog(LOG_INFO, "error stat'ing %s: %m", addr_filename);
+         }
        }
-#endif /* CAPDIR */
+
+       afp_asp_close(obj);
+       syslog( LOG_INFO, "done" );
 
        if ( obj->options.flags & OPTION_DEBUG ) {
          printf( "done\n" );
index eb8fc25cc8e9129aea3aed939d964d39f55f2bdb..2b50abf040d6a13a34ac3b9f14d0e179781484dd 100644 (file)
@@ -119,6 +119,7 @@ void afp_options_init(struct afp_options *options)
   options->transports = AFPTRANS_ALL;
   options->passwdfile = _PATH_AFPDPWFILE;
   options->tickleval = 30;
+  options->authprintdir = NULL;
 #ifdef ADMIN_GRP
   options->admingid = 0;
 #endif ADMIN_GRP
@@ -214,6 +215,9 @@ int afp_options_parseline(char *buf, struct afp_options *options)
     }
   } 
 #endif
+
+  if ((c = getoption(buf, "-authprintdir")) && (opt = strdup(c)))
+    options->authprintdir = opt;
   if ((c = getoption(buf, "-uampath")) && (opt = strdup(c)))
     options->uampath = opt;
   if ((c = getoption(buf, "-uamlist")) && (opt = strdup(c)))
index a163d57bea5023b9b71ea5d4219aebcc2b351b00..dbc7f573fc2ec6cb20ed1c76ca43d816b138d1ab 100644 (file)
@@ -69,12 +69,6 @@ static struct uam_obj uam_changepw = {"", "", 0, {{NULL}}, &uam_changepw,
 static struct uam_obj *afp_uam = NULL;
 
 
-/* Variables for CAP style printer authentication */
-#ifdef CAPDIR
-extern int addr_net, addr_node, addr_uid;
-extern char addr_name[32];
-#endif /* CAPDIR */
-
 void status_versions( data )
     char       *data;
 {
@@ -140,13 +134,8 @@ static int send_reply(const AFPObj *obj, const int err)
 
 static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void))
 {
-#ifdef CAPDIR
-    char nodename[256];
-    FILE *fp;
-#endif /* CAPDIR */
 #ifdef ADMIN_GRP
     int admin = 0;
-    struct afp_options *options = &obj->options;
 #endif ADMIN_GRP
 
     /* UAM had syslog control; afpd needs to reassert itself */
@@ -160,18 +149,41 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void))
     syslog( LOG_INFO, "login %s (uid %d, gid %d)", pwd->pw_name,
            pwd->pw_uid, pwd->pw_gid );
 
-#ifdef CAPDIR
-    if(addr_net && addr_node) { /* Do we have a valid Appletalk address? */
-       addr_uid = pwd->pw_uid;
-       strncpy(addr_name, pwd->pw_name, 32);
-       sprintf(nodename, "%s/net%d.%dnode%d", CAPDIR, addr_net / 256, addr_net % 256, addr_node);
-       syslog (LOG_INFO, "registering %s (uid %d) on %u.%u as %s",
-                       addr_name, addr_uid, addr_net, addr_node, nodename);
-       fp = fopen(nodename, "w");
-       fprintf(fp, "%s\n", addr_name);
-       fclose(fp);
-    }
-#endif /* CAPDIR */
+    if (obj->proto == AFPPROTO_ASP) {
+      ASP asp = obj->handle;
+      int addr_net = ntohs( asp->asp_sat.sat_addr.s_net );
+      int addr_node  = asp->asp_sat.sat_addr.s_node;
+
+      if (obj->options.authprintdir) {
+       if(addr_net && addr_node) { /* Do we have a valid Appletalk address? */
+         char nodename[256];
+         FILE *fp;
+         struct stat stat_buf;
+
+         sprintf(nodename, "%s/net%d.%dnode%d", obj->options.authprintdir, 
+               addr_net / 256, addr_net % 256, addr_node);
+         syslog (LOG_INFO, "registering %s (uid %d) on %u.%u as %s",
+                       pwd->pw_name, pwd->pw_uid, addr_net, addr_node, nodename);
+
+         if (stat(nodename, &stat_buf) == 0) { /* file exists */
+           if (S_ISREG(stat_buf.st_mode)) { /* normal file */
+               unlink(nodename);
+               fp = fopen(nodename, "w");
+               fprintf(fp, "%s\n", pwd->pw_name);
+               fclose(fp);
+               chown( nodename, pwd->pw_uid, -1 );
+           } else { /* somebody is messing with us */
+               syslog( LOG_ERR, "print authfile %s is not a normal file, it will not be modified", nodename );
+           }
+         } else { /* file 'nodename' does not exist */
+           fp = fopen(nodename, "w");
+           fprintf(fp, "%s\n", pwd->pw_name);
+           fclose(fp);
+           chown( nodename, pwd->pw_uid, -1 );
+         }
+       } /* if (addr_net && addr_node ) */
+      } /* if (options->authprintdir) */
+    } /* if (obj->proto == AFPPROTO_ASP) */
 
     if (initgroups( pwd->pw_name, pwd->pw_gid ) < 0) {
 #ifdef RUN_AS_USER
@@ -191,12 +203,12 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void))
     }
 #ifdef ADMIN_GRP
 #ifdef DEBUG
-    syslog(LOG_INFO, "options->admingid == %d", options->admingid);
+    syslog(LOG_INFO, "obj->options.admingid == %d", obj->options.admingid);
 #endif DEBUG
-    if (options->admingid != 0) {
+    if (obj->options.admingid != 0) {
        int i;
        for (i = 0; i < ngroups; i++) {
-           if (groups[i] == options->admingid) admin = 1;
+           if (groups[i] == obj->options.admingid) admin = 1;
         }
     }
     if (admin) syslog( LOG_INFO, "admin login -- %s", pwd->pw_name );
index b3312ac06d64aaebde803ccddf7b201593c83e1a..1022b392978c64855539d969b943e81ddee3ec9f 100644 (file)
@@ -45,6 +45,7 @@ struct afp_options {
   char *pidfile, *defaultvol, *systemvol;
   char *guest, *loginmesg, *keyfile, *passwdfile;
   char *uamlist;
+  char *authprintdir;
 #ifdef ADMIN_GRP
   gid_t admingid;
 #endif ADMIN_GRP
index 0be85f39d01c6e5ee0cba10ec9ba456de2542fca..b919386c4ace294d98eead98c01dc34c67ca4b7e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: main.c,v 1.6 2001-05-22 19:13:36 rufustfirefly Exp $
+ * $Id: main.c,v 1.7 2001-05-23 23:55:23 samnoble Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -57,11 +57,6 @@ static AFPConfig *configs;
 static server_child *server_children;
 static fd_set save_rfds;
 
-#ifdef CAPDIR
-int addr_net, addr_node, addr_uid;
-char addr_name[32];
-#endif CAPDIR
-
 static void afp_exit(const int i)
 {
   server_unlock(default_options.pidfile);
index 1de9a4e0c1d3c97aa6eb6b7dd051d30a7e7a2f8b..b90a45a5ec2eb998e66c580c360238441243900a 100644 (file)
@@ -185,21 +185,23 @@ lp_init( out, sat )
     char       cost[ 22 ];
     char       balance[ 22 ];
 #endif ABS_PRINT
-#if defined( CAPDIR ) || defined( USE_CAP )
-    char       username[32];
-    int                addr_net, addr_node;
-    FILE       *cap_file;
-    struct stat        cap_st;
-    char       addr_filename[256];
-#endif /* CAPDIR */
 
     if ( printer->p_flags & P_AUTH ) {
        authenticated = 0;
-#ifdef CAPDIR
-       if ( printer->p_flags & P_AUTH_CAP ) {
-           addr_net = ntohs( sat->sat_addr.s_net );
-           addr_node  = sat->sat_addr.s_node;
-           sprintf(addr_filename, "%s/net%d.%dnode%d", CAPDIR, addr_net/256, addr_net%256, addr_node);
+
+       /* cap style "log on to afp server before printing" authentication */
+
+       if ( printer->p_authprintdir && (printer->p_flags & P_AUTH_CAP) ) {
+           int addr_net = ntohs( sat->sat_addr.s_net );
+           int addr_node  = sat->sat_addr.s_node;
+           char addr_filename[256];
+           char username[32];
+           struct stat cap_st;
+           FILE *cap_file;
+
+           sprintf(addr_filename, "%s/net%d.%dnode%d", 
+               printer->p_authprintdir, addr_net/256, addr_net%256, 
+               addr_node);
            if (stat(addr_filename, &cap_st) == 0) {
                if ((cap_file = fopen(addr_filename, "r")) != NULL) {
                    if (fscanf(cap_file, "%s", username) != EOF) {
@@ -220,7 +222,6 @@ lp_init( out, sat )
                syslog(LOG_INFO, "CAP error: %m");
            }
        }
-#endif /* CAPDIR */
 
        if ( printer->p_flags & P_AUTH_PSSP ) {
            if ( lp.lp_person != NULL ) {
index a98009cd93bc5d375fa66986f081f84dee270259..751284370a077b7a7f895bb3b42afd72e9865ee3 100644 (file)
@@ -592,10 +592,16 @@ getprinters( cf )
        /*
         * Do we want authenticated printing?
         */
-       if ( pgetflag( "ca", &a ) == 1 ) {
+       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", &a ) == 1 ) {
            pr->p_flags |= P_AUTH;
            pr->p_flags |= P_AUTH_PSSP;
index d80c37467babb08b6340303244b8f24051d81b79..369d31e179aa011b662d642da057c589f257c45b 100644 (file)
@@ -12,6 +12,7 @@ struct printer {
     char               *p_psetdir;
 #endif notdef
     char               *p_ppdfile;
+    char               *p_authprintdir;
     int                        p_flags;
     struct at_addr      p_addr;
     union {