Blame SOURCES/tftp-enhanced-logging.patch

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