diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2011-03-06 14:23:07 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2011-03-06 14:23:07 +0000 |
commit | eccf3173adb444c257557c088d3ebcc9c6099939 (patch) | |
tree | 94d334fe801b262916ab174a8015429dac5c5b90 | |
parent | ed26036f39e8e5f8ae58de40382ab7b6f175e5f7 (diff) |
ensure that session id is only logged while handling a connection
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1375 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r-- | nslcd/log.c | 20 | ||||
-rw-r--r-- | nslcd/log.h | 7 | ||||
-rw-r--r-- | nslcd/nslcd.c | 6 |
3 files changed, 26 insertions, 7 deletions
diff --git a/nslcd/log.c b/nslcd/log.c index 6206d61..bc39398 100644 --- a/nslcd/log.c +++ b/nslcd/log.c @@ -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 @@ void log_startlogging(void) } +/* 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 @@ void log_log(int pri,const char *format, ...) { 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 @@ void log_log(int pri,const char *format, ...) { 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 @@ void log_log(int pri,const char *format, ...) { 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); diff --git a/nslcd/log.h b/nslcd/log.h index a979fb2..9b7259f 100644 --- a/nslcd/log.h +++ b/nslcd/log.h @@ -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_startlogging(void); 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, ...) diff --git a/nslcd/nslcd.c b/nslcd/nslcd.c index 0421c04..e5d26b7 100644 --- a/nslcd/nslcd.c +++ b/nslcd/nslcd.c @@ -392,8 +392,6 @@ static void handleconnection(int sock,MYLDAP_SESSION *session) 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 @@ static void *worker(void UNUSED(*arg)) 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; |