lists.arthurdejong.org
RSS feed

nss-pam-ldapd commit: r1375 - nss-pam-ldapd/nslcd

[Date Prev][Date Next] [Thread Prev][Thread Next]

nss-pam-ldapd commit: r1375 - nss-pam-ldapd/nslcd



Author: arthur
Date: Sun Mar  6 15:23:07 2011
New Revision: 1375
URL: http://arthurdejong.org/viewvc/nss-pam-ldapd?view=rev&revision=1375

Log:
ensure that session id is only logged while handling a connection

Modified:
   nss-pam-ldapd/nslcd/log.c
   nss-pam-ldapd/nslcd/log.h
   nss-pam-ldapd/nslcd/nslcd.c

Modified: nss-pam-ldapd/nslcd/log.c
==============================================================================
--- nss-pam-ldapd/nslcd/log.c   Sun Mar  6 14:01:28 2011        (r1374)
+++ nss-pam-ldapd/nslcd/log.c   Sun Mar  6 15:23:07 2011        (r1375)
@@ -1,7 +1,7 @@
 /*
    log.c - logging funtions
 
-   Copyright (C) 2002, 2003, 2008, 2010 Arthur de Jong
+   Copyright (C) 2002, 2003, 2008, 2010, 2011 Arthur de Jong
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -134,6 +134,18 @@
 }
 
 
+/* indicate that we should clear any session identifiers set by
+   log_newsession */
+void log_clearsession(void)
+{
+  /* set the session id to empty */
+  if (sessionid!=NULL)
+    sessionid[0]='\0';
+  /* set the request id to empty */
+  if (requestid!=NULL)
+    requestid[0]='\0';
+}
+
 /* indicate that a session id should be included in the output
    and set it to a new value */
 void log_newsession(void)
@@ -207,7 +219,7 @@
     {
       if ((requestid!=NULL)&&(requestid[0]!='\0'))
         fprintf(stderr,"%s: [%s] <%s> 
%s%s\n",PACKAGE,sessionid,requestid,pri==LOG_DEBUG?"DEBUG: ":"",buffer);
-      else if (sessionid)
+      else if ((sessionid!=NULL)&&(sessionid[0]!='\0'))
         fprintf(stderr,"%s: [%s] 
%s%s\n",PACKAGE,sessionid,pri==LOG_DEBUG?"DEBUG: ":"",buffer);
       else
         fprintf(stderr,"%s: %s%s\n",PACKAGE,pri==LOG_DEBUG?"DEBUG: 
":"",buffer);
@@ -223,7 +235,7 @@
         {
           if ((requestid!=NULL)&&(requestid[0]!='\0'))
             syslog(pri,"[%s] <%s> %s",sessionid,requestid,buffer);
-          else if (sessionid)
+          else if ((sessionid!=NULL)&&(sessionid[0]!='\0'))
             syslog(pri,"[%s] %s",sessionid,buffer);
           else
             syslog(pri,"%s",buffer);
@@ -232,7 +244,7 @@
         {
           if ((requestid!=NULL)&&(requestid[0]!='\0'))
             fprintf(lst->fp,"%s: [%s] <%s> 
%s\n",sessionid,requestid,PACKAGE,buffer);
-          else if (sessionid)
+          else if ((sessionid!=NULL)&&(sessionid[0]!='\0'))
             fprintf(lst->fp,"%s: [%s] %s\n",sessionid,PACKAGE,buffer);
           else
             fprintf(lst->fp,"%s: %s\n",PACKAGE,buffer);

Modified: nss-pam-ldapd/nslcd/log.h
==============================================================================
--- nss-pam-ldapd/nslcd/log.h   Sun Mar  6 14:01:28 2011        (r1374)
+++ nss-pam-ldapd/nslcd/log.h   Sun Mar  6 15:23:07 2011        (r1375)
@@ -1,7 +1,7 @@
 /*
    log.h - definitions of logging funtions
 
-   Copyright (C) 2002, 2003, 2007, 2008, 2010 Arthur de Jong
+   Copyright (C) 2002, 2003, 2007, 2008, 2010, 2011 Arthur de Jong
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -54,6 +54,11 @@
 void log_newsession(void);
 
 
+/* indicate that we should clear any session identifiers set by
+   log_newsession */
+void log_clearsession(void);
+
+
 /* indicate that a request identifier should be included in the output
    from this point on, until log_newsession() is called */
 void log_setrequest(const char *format, ...)

Modified: nss-pam-ldapd/nslcd/nslcd.c
==============================================================================
--- nss-pam-ldapd/nslcd/nslcd.c Sun Mar  6 14:01:28 2011        (r1374)
+++ nss-pam-ldapd/nslcd/nslcd.c Sun Mar  6 15:23:07 2011        (r1375)
@@ -392,8 +392,6 @@
   uid_t uid;
   gid_t gid;
   pid_t pid;
-  /* indicate new connection to logging module (genrates unique id) */
-  log_newsession();
   /* log connection */
   if (getpeercred(sock,&uid,&gid,&pid))
     log_log(LOG_DEBUG,"connection from unknown client: %s",strerror(errno));
@@ -609,8 +607,12 @@
         log_log(LOG_WARNING,"problem closing socket: %s",strerror(errno));
       continue;
     }
+    /* indicate new connection to logging module (genrates unique id) */
+    log_newsession();
     /* handle the connection */
     handleconnection(csock,session);
+    /* indicate end of session in log messages */
+    log_clearsession();
   }
   pthread_cleanup_pop(1);
   return NULL;
-- 
To unsubscribe send an email to
nss-pam-ldapd-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-commits