clausklein / rpms / tftp

Forked from rpms/tftp 5 years ago
Clone

Blame SOURCES/tftp-enhanced-logging.patch

364356
--- a/tftpd/tftpd.c	2016-03-02 11:32:30.710775130 +0100
364356
+++ b/tftpd/tftpd.c	2016-03-02 11:36:24.086541019 +0100
364356
@@ -1056,14 +1056,14 @@ int main(int argc, char **argv)
364356
 
364356
 static char *rewrite_access(char *, int, const char **);
364356
 static int validate_access(char *, int, const struct formats *, const char **);
364356
-static void tftp_sendfile(const struct formats *, struct tftphdr *, int);
364356
+static void tftp_sendfile(const struct formats *, struct tftphdr *, int, char *);
364356
 static void tftp_recvfile(const struct formats *, struct tftphdr *, int);
364356
 
364356
 struct formats {
364356
     const char *f_mode;
364356
     char *(*f_rewrite) (char *, int, const char **);
364356
     int (*f_validate) (char *, int, const struct formats *, const char **);
364356
-    void (*f_send) (const struct formats *, struct tftphdr *, int);
364356
+    void (*f_send) (const struct formats *, struct tftphdr *, int, char *);
364356
     void (*f_recv) (const struct formats *, struct tftphdr *, int);
364356
     int f_convert;
364356
 };
364356
@@ -1129,6 +1129,9 @@ int tftp(struct tftphdr *tp, int size)
364356
                 nak(EACCESS, errmsgptr);        /* File denied by mapping rule */
364356
                 exit(0);
364356
             }
364356
+	    ecode =
364356
+                (*pf->f_validate) (filename, tp_opcode, pf, &errmsgptr);
364356
+
364356
             if (verbosity >= 1) {
364356
                 tmp_p = (char *)inet_ntop(from.sa.sa_family, SOCKADDR_P(&from),
364356
                                           tmpbuf, INET6_ADDRSTRLEN);
364356
@@ -1147,9 +1150,14 @@ int tftp(struct tftphdr *tp, int size)
364356
                            tp_opcode == WRQ ? "WRQ" : "RRQ",
364356
                            tmp_p, origfilename,
364356
                            filename);
364356
+
364356
+                if (ecode == 1) {
364356
+                    syslog(LOG_NOTICE, "Client %s File not found %s\n",
364356
+                    tmp_p,filename);
364356
+                }
364356
+
364356
             }
364356
-            ecode =
364356
-                (*pf->f_validate) (filename, tp_opcode, pf, &errmsgptr);
364356
+
364356
             if (ecode) {
364356
                 nak(ecode, errmsgptr);
364356
                 exit(0);
364356
@@ -1172,12 +1180,12 @@ int tftp(struct tftphdr *tp, int size)
364356
         if (tp_opcode == WRQ)
364356
             (*pf->f_recv) (pf, (struct tftphdr *)ackbuf, ap - ackbuf);
364356
         else
364356
-            (*pf->f_send) (pf, (struct tftphdr *)ackbuf, ap - ackbuf);
364356
+            (*pf->f_send) (pf, (struct tftphdr *)ackbuf, ap - ackbuf, origfilename);
364356
     } else {
364356
         if (tp_opcode == WRQ)
364356
             (*pf->f_recv) (pf, NULL, 0);
364356
         else
364356
-            (*pf->f_send) (pf, NULL, 0);
364356
+            (*pf->f_send) (pf, NULL, 0, origfilename);
364356
     }
364356
     exit(0);                    /* Request completed */
364356
 }
364356
@@ -1557,7 +1565,7 @@ static int validate_access(char *filenam
364356
 /*
364356
  * Send the requested file.
364356
  */
364356
-static void tftp_sendfile(const struct formats *pf, struct tftphdr *oap, int oacklen)
364356
+static void tftp_sendfile(const struct formats *pf, struct tftphdr *oap, int oacklen, char *filename)
364356
 {
364356
     struct tftphdr *dp;
364356
     struct tftphdr *ap;         /* ack packet */
364356
@@ -1648,6 +1656,13 @@ static void tftp_sendfile(const struct f
364356
 	if (!++block)
364356
 	  block = rollover_val;
364356
     } while (size == segsize);
364356
+    tmp_p = (char *)inet_ntop(from.sa.sa_family, SOCKADDR_P(&from),
364356
+                                          tmpbuf, INET6_ADDRSTRLEN);
364356
+    if (!tmp_p) {
364356
+            tmp_p = tmpbuf;
364356
+            strcpy(tmpbuf, "???");
364356
+    }
364356
+    syslog(LOG_NOTICE, "Client %s finished %s",tmp_p,filename);
364356
   abort:
364356
     (void)fclose(file);
364356
 }