Proposed patch for auth.c
Hello, I've mad a small patch to the rad_authlog function in auth.c The purpose of this patch is to make a pair with the auth log message in it (Auth: login Ok ....). For this I use the Reply-Message attribute. What do you think, is it safe to use this one ? Or should I define a new one ? Thank you Here is the new function : /* * Make sure user/pass are clean * and then log them */ static int rad_authlog(const char *msg, REQUEST *request, int goodpass) { char clean_password[1024]; char clean_username[1024]; char buf[1024]; char msg_log[1024]; VALUE_PAIR *username = NULL; VALUE_PAIR *log_pair; if (!mainconfig.log_auth) { return 0; } /* * Get the correct username based on the configured value */ if (log_stripped_names == 0) { username = pairfind(request->packet->vps, PW_USER_NAME); } else { username = request->username; } /* * Clean up the username */ if (username == NULL) { strcpy(clean_username, "<no User-Name attribute>"); } else { librad_safeprint((char *)username->strvalue, username->length, clean_username, sizeof(clean_username)); } /* * Clean up the password */ if (mainconfig.log_auth_badpass || mainconfig.log_auth_goodpass) { if (!request->password) { strcpy(clean_password, "<no User-Password attribute>"); } else if (request->password->attribute == PW_CHAP_PASSWORD) { strcpy(clean_password, "<CHAP-Password>"); } else { librad_safeprint((char *)request->password->strvalue, request->password->length, clean_password, sizeof(clean_password)); } } if (goodpass) { sprintf(msg_log, "%s: [%s%s%s] (%s)", msg, clean_username, mainconfig.log_auth_goodpass ? "/" : "", mainconfig.log_auth_goodpass ? clean_password : "", auth_name(buf, sizeof(buf), request, 1)); } else { sprintf(msg_log, "%s: [%s%s%s] (%s)", msg, clean_username, mainconfig.log_auth_badpass ? "/" : "", mainconfig.log_auth_badpass ? clean_password : "", auth_name(buf, sizeof(buf), request, 1)); } radlog(L_AUTH, msg_log); log_pair = paircreate(PW_REPLY_MESSAGE, PW_TYPE_STRING); if (log_pair == NULL) { radlog(L_ERR|L_CONS, "no memory"); exit(1); } sprintf((char *)log_pair->strvalue, "%s", msg_log); log_pair->length = strlen((char *)log_pair->strvalue); pairadd(&request->reply->vps, log_pair); return 0; }
Alain cocconi <cocconi@net-outremer.nc> wrote:
I've mad a small patch to the rad_authlog function in auth.c The purpose of this patch is to make a pair with the auth log message in it (Auth: login Ok ....). For this I use the Reply-Message attribute. What do you think, is it safe to use this one ? Or should I define a new one ?
Ok... why is trhis necessary, or even useful?
Here is the new function :
Don't send the new function. Send the patch. Alan DeKok.
Le 04:09 19/11/2005,Alan DeKok écrit:
Alain cocconi <cocconi@net-outremer.nc> wrote:
I've mad a small patch to the rad_authlog function in auth.c The purpose of this patch is to make a pair with the auth log message in it (Auth: login Ok ....). For this I use the Reply-Message attribute. What do you think, is it safe to use this one ? Or should I define a new one ?
Ok... why is trhis necessary, or even useful?
It is usefull to be used in postauth to store it in a database for helpdesk .... without parsing a log file
Here is the new function :
Don't send the new function. Send the patch.
ok: --- auth.c.orig 2005-08-25 11:10:28.000000000 +1100 +++ auth.c 2005-11-18 12:04:41.694075060 +1100 @@ -116,7 +116,10 @@ char clean_password[1024]; char clean_username[1024]; char buf[1024]; + char msg_log[1024]; VALUE_PAIR *username = NULL; + VALUE_PAIR *log_pair = NULL; + if (!mainconfig.log_auth) { return 0; @@ -157,21 +160,32 @@ } } + if (goodpass) { - radlog(L_AUTH, "%s: [%s%s%s] (%s)", + sprintf(msg_log, "%s: [%s%s%s] (%s)", msg, clean_username, mainconfig.log_auth_goodpass ? "/" : "", mainconfig.log_auth_goodpass ? clean_password : "", auth_name(buf, sizeof(buf), request, 1)); } else { - radlog(L_AUTH, "%s: [%s%s%s] (%s)", + sprintf(msg_log, "%s: [%s%s%s] (%s)", msg, clean_username, mainconfig.log_auth_badpass ? "/" : "", mainconfig.log_auth_badpass ? clean_password : "", auth_name(buf, sizeof(buf), request, 1)); } + radlog(L_AUTH, msg_log); + + log_pair = paircreate(PW_REPLY_MESSAGE, PW_TYPE_STRING); + if (log_pair == NULL) { + radlog(L_ERR|L_CONS, "no memory"); + exit(1); + } + sprintf((char *)log_pair->strvalue, "%s", msg_log); + log_pair->length = strlen((char *)log_pair->strvalue); + pairadd(&request->reply->vps, log_pair); return 0; }
Alan DeKok. - List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
participants (2)
-
Alain cocconi -
Alan DeKok