]> arthur.barton.de Git - netatalk.git/commitdiff
Fix some issues with CAP-style printer authentication by changing where the
authormorgana <morgana>
Wed, 20 Mar 2002 20:53:57 +0000 (20:53 +0000)
committermorgana <morgana>
Wed, 20 Mar 2002 20:53:57 +0000 (20:53 +0000)
cleanup occurs to afp_asp_close() and storing the pid of afpd in the CAP file.
Credit goes to Sam Noble <ns@shadow.org> for this patch.

etc/afpd/afp_asp.c
etc/afpd/auth.c
etc/papd/lp.c

index a5fd741e435d6843cd9570e87d0331b77bd800b7..2dd3132ed6c0cdd4ce336d6ad2a73e53432924b7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: afp_asp.c,v 1.13 2002-03-16 20:38:09 jmarcus Exp $
+ * $Id: afp_asp.c,v 1.14 2002-03-20 20:53:57 morgana Exp $
  *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
@@ -42,10 +42,14 @@ extern struct oforks        *writtenfork;
 
 static AFPObj *child;
 
+static __inline__ void afp_authprint_remove(AFPObj *);
+
 static __inline__ void afp_asp_close(AFPObj *obj)
 {
     ASP asp = obj->handle;
 
+    if (obj->options.authprintdir) afp_authprint_remove(obj);
+
     if (obj->logout)
         (*obj->logout)();
 
@@ -54,6 +58,65 @@ static __inline__ void afp_asp_close(AFPObj *obj)
     asp_close( asp );
 }
 
+/* removes the authprint trailing when appropriate */
+static __inline__ void afp_authprint_remove(AFPObj *obj)
+{
+    ASP asp = obj->handle;
+    char addr_filename[256];
+    char addr_filename_buff[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 );
+
+    memset( addr_filename_buff, 0, 256 );
+
+    if(stat(addr_filename, &cap_st) == 0) {
+       if( S_ISREG(cap_st.st_mode) ) {
+           int len;
+           int capfd = open( addr_filename, O_RDONLY );
+           if ((len = read( capfd, addr_filename_buff, 256 )) > 0) {
+               int file_pid;
+               char *p_filepid;
+               close(capfd);
+               addr_filename_buff[len] = 0;
+               if ( (p_filepid = strrchr(addr_filename_buff, ':')) != NULL) {
+                   *p_filepid = '\0';
+                   p_filepid++;
+                   file_pid = atoi(p_filepid);
+                   if (file_pid == (int)getpid()) {
+                       if(unlink(addr_filename) == 0) {
+                           syslog(LOG_INFO, "removed %s", addr_filename);
+                       } else {
+                           syslog(LOG_INFO, "error removing %s: %s",
+                                   addr_filename, strerror(errno));
+                       }
+                   } else {
+                       syslog( LOG_INFO, "%s belongs to another pid %d",
+                            addr_filename, file_pid );
+                   }
+               } else { /* no pid info */
+                   if (unlink(addr_filename) == 0) {
+                       syslog( LOG_INFO, "removed %s", addr_filename );
+                   } else {
+                       syslog(LOG_INFO, "error removing %s: %s",
+                               addr_filename, strerror(errno));
+                   }
+               }
+           } else {
+               syslog( LOG_INFO, "couldn't read data from %s", addr_filename );
+           }
+       } else {
+           syslog( LOG_INFO, "%s is not a regular file", addr_filename );
+       }
+    } else {
+        syslog(LOG_INFO, "error stat'ing %s: %s",
+                   addr_filename, strerror(errno));
+    }
+}
+
 static void afp_asp_die(const int sig)
 {
     ASP asp = child->handle;
@@ -138,28 +201,6 @@ void afp_over_asp(AFPObj *obj)
     while ((reply = asp_getrequest(asp))) {
         switch (reply) {
         case ASPFUNC_CLOSE :
-            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 );
-
-                if(stat(addr_filename, &cap_st) == 0) {
-                    if(unlink(addr_filename) == 0) {
-                        LOG(log_info, logtype_default, "removed %s", addr_filename);
-                    } else {
-                        LOG(log_info, logtype_default, "error removing %s: %s",
-                            addr_filename, strerror(errno));
-                    }
-                } else {
-                    LOG(log_info, logtype_default, "error stat'ing %s: %s",
-                        addr_filename, strerror(errno));
-                }
-            }
-
             afp_asp_close(obj);
             LOG(log_info, logtype_default, "done" );
 
index d2bae1349b4cb45d893d5a9a265e3e4f4fd43448..8b50d0de46fa1c4f179a0d418fef50b8a21da4c4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: auth.c,v 1.25 2002-02-28 21:20:39 jmarcus Exp $
+ * $Id: auth.c,v 1.26 2002-03-20 20:53:57 morgana Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -177,6 +177,7 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void))
             if(addr_net && addr_node) { /* Do we have a valid Appletalk address? */
                 char nodename[256];
                 FILE *fp;
+               int mypid = getpid();
                 struct stat stat_buf;
 
                 sprintf(nodename, "%s/net%d.%dnode%d", obj->options.authprintdir,
@@ -188,7 +189,7 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void))
                     if (S_ISREG(stat_buf.st_mode)) { /* normal file */
                         unlink(nodename);
                         fp = fopen(nodename, "w");
-                        fprintf(fp, "%s\n", pwd->pw_name);
+                        fprintf(fp, "%s:%d\n", pwd->pw_name, mypid);
                         fclose(fp);
                         chown( nodename, pwd->pw_uid, -1 );
                     } else { /* somebody is messing with us */
@@ -196,7 +197,7 @@ static int login(AFPObj *obj, struct passwd *pwd, void (*logout)(void))
                     }
                 } else { /* file 'nodename' does not exist */
                     fp = fopen(nodename, "w");
-                    fprintf(fp, "%s\n", pwd->pw_name);
+                    fprintf(fp, "%s:%d\n", pwd->pw_name, mypid);
                     fclose(fp);
                     chown( nodename, pwd->pw_uid, -1 );
                 }
index 4e5c3166897d87604ce5d2979b6f5b05d7c7cf98..59b27f988011b0b05e9a46377044fa3f64fb3ac8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: lp.c,v 1.12 2002-01-04 04:45:47 sibaz Exp $
+ * $Id: lp.c,v 1.13 2002-03-20 20:54:05 morgana Exp $
  *
  * Copyright (c) 1990,1994 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -197,16 +197,23 @@ int lp_init( out, sat )
            int addr_net = ntohs( sat->sat_addr.s_net );
            int addr_node  = sat->sat_addr.s_node;
            char addr_filename[256];
-           char username[32];
+           char auth_string[256];
+           char *username, *afpdpid;
            struct stat cap_st;
            FILE *cap_file;
 
+           memset( auth_string, 0, 256 );
            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) {
+                   if (fgets(auth_string, 256, cap_file) != NULL) {
+                       username = auth_string;
+                       if ((afpdpid = strrchr( auth_string, ':' )) != NULL) {
+                           *afpdpid = '\0';
+                           afpdpid++;
+                       }
                        if (getpwnam(username) != NULL ) {
                            LOG(log_info, logtype_default, "CAP authenticated %s", username);
                            lp_person(username);