]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_asp.c
Update NEWS
[netatalk.git] / etc / afpd / afp_asp.c
index 94a0cd2d942e2640cba7edb22925a923c36dd2d9..3e208f74a102d1db449b49b317908f508e8a75ec 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: afp_asp.c,v 1.25 2009-10-14 01:38:28 didg Exp $
+ * $Id: afp_asp.c,v 1.29 2010-03-09 06:55:12 franklahm Exp $
  *
  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
@@ -32,8 +32,8 @@
 #include <atalk/asp.h>
 #include <atalk/compat.h>
 #include <atalk/util.h>
+#include <atalk/globals.h>
 
-#include "globals.h"
 #include "switch.h"
 #include "auth.h"
 #include "fork.h"
@@ -51,6 +51,10 @@ static void afp_asp_close(AFPObj *obj)
 {
     ASP asp = obj->handle;
 
+    if (seteuid( obj->uid ) < 0) {
+        LOG(log_error, logtype_afpd, "can't seteuid back %s", strerror(errno));
+        exit(EXITERR_SYS);
+    }
     close_all_vol();
     if (obj->options.authprintdir) afp_authprint_remove(obj);
 
@@ -77,14 +81,13 @@ static void afp_authprint_remove(AFPObj *obj)
 
     memset( addr_filename_buff, 0, 256 );
 
-    if(stat(addr_filename, &cap_st) == 0) {
+    if(lstat(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';
@@ -112,6 +115,8 @@ static void afp_authprint_remove(AFPObj *obj)
            } else {
                LOG(log_info, logtype_afpd, "couldn't read data from %s", addr_filename );
            }
+        if (capfd != -1)
+            close(capfd);
        } else {
            LOG(log_info, logtype_afpd, "%s is not a regular file", addr_filename );
        }
@@ -156,7 +161,7 @@ static void afp_asp_timedown(int sig _U_)
     it.it_interval.tv_usec = 0;
     it.it_value.tv_sec = 300;
     it.it_value.tv_usec = 0;
-    if ( setitimer( ITIMER_REAL, &it, 0 ) < 0 ) {
+    if ( setitimer( ITIMER_REAL, &it, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_timedown: setitimer: %s", strerror(errno) );
         afp_asp_die(EXITERR_SYS);
     }
@@ -167,7 +172,7 @@ static void afp_asp_timedown(int sig _U_)
     sigaddset(&sv.sa_mask, SIGHUP);
     sigaddset(&sv.sa_mask, SIGTERM);
     sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGALRM, &sv, 0 ) < 0 ) {
+    if ( sigaction( SIGALRM, &sv, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_timedown: sigaction: %s", strerror(errno) );
         afp_asp_die(EXITERR_SYS);
     }
@@ -176,7 +181,7 @@ static void afp_asp_timedown(int sig _U_)
     sv.sa_handler = SIG_IGN;
     sigemptyset( &sv.sa_mask );
     sv.sa_flags = SA_RESTART;
-    if ( sigaction( SIGUSR1, &sv, 0 ) < 0 ) {
+    if ( sigaction( SIGUSR1, &sv, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_timedown: sigaction SIGUSR1: %s", strerror(errno) );
         afp_asp_die(EXITERR_SYS);
     }
@@ -211,6 +216,7 @@ void afp_over_asp(AFPObj *obj)
     int ccnt = 0;
 #endif    
 
+    AFPobj = obj;
     obj->exit = afp_asp_die;
     obj->reply = (int (*)()) asp_cmdreply;
     obj->attention = (int (*)(void *, AFPUserBytes)) asp_attention;
@@ -231,7 +237,7 @@ void afp_over_asp(AFPObj *obj)
     sigaddset(&action.sa_mask, SIGUSR2);
 #endif    
     action.sa_flags = SA_RESTART;
-    if ( sigaction( SIGHUP, &action, 0 ) < 0 ) {
+    if ( sigaction( SIGHUP, &action, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_asp: sigaction: %s", strerror(errno) );
         afp_asp_die(EXITERR_SYS);
     }
@@ -245,7 +251,7 @@ void afp_over_asp(AFPObj *obj)
     sigaddset(&action.sa_mask, SIGUSR2);
 #endif    
     action.sa_flags = SA_RESTART;
-    if ( sigaction( SIGTERM, &action, 0 ) < 0 ) {
+    if ( sigaction( SIGTERM, &action, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_asp: sigaction: %s", strerror(errno) );
         afp_asp_die(EXITERR_SYS);
     }
@@ -258,7 +264,7 @@ void afp_over_asp(AFPObj *obj)
     sigaddset(&action.sa_mask, SIGUSR1);
     sigaddset(&action.sa_mask, SIGHUP);
     action.sa_flags = SA_RESTART;
-    if ( sigaction( SIGUSR2, &action, 0) < 0 ) {
+    if ( sigaction( SIGUSR2, &action, NULL) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_asp: sigaction: %s", strerror(errno) );
         afp_asp_die(EXITERR_SYS);
     }
@@ -273,11 +279,16 @@ void afp_over_asp(AFPObj *obj)
     sigaddset(&action.sa_mask, SIGUSR2);
 #endif    
     action.sa_flags = SA_RESTART;
-    if ( sigaction( SIGUSR1, &action, 0 ) < 0 ) {
+    if ( sigaction( SIGUSR1, &action, NULL ) < 0 ) {
         LOG(log_error, logtype_afpd, "afp_over_asp: sigaction: %s", strerror(errno) );
         afp_asp_die(EXITERR_SYS);
     }
 
+    if (dircache_init(obj->options.dircachesize) != 0) {
+        LOG(log_error, logtype_afpd, "afp_over_asp: dircache_init error");
+        afp_asp_die(EXITERR_SYS);
+    }
+
     LOG(log_info, logtype_afpd, "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,