Blame SOURCES/tftp-enhanced-logging.patch

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