clausklein / rpms / tftp

Forked from rpms/tftp 5 years ago
Clone

Blame SOURCES/tftp-enhanced-logging.patch

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