Extend the logging capabilities of auth good/badpass
authorAlan T. DeKok <aland@freeradius.org>
Thu, 2 Jul 2009 13:51:24 +0000 (15:51 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 2 Jul 2009 13:51:24 +0000 (15:51 +0200)
raddb/radiusd.conf.in
src/include/radiusd.h
src/main/auth.c
src/main/mainconfig.c

index 0bfbc6b..265001e 100644 (file)
@@ -450,6 +450,18 @@ log {
        #
        auth_badpass = no
        auth_goodpass = no
+
+       #  Log additional text at the end of the "Login OK" messages.
+       #  for these to work, the "auth" and "auth_goopass" or "auth_badpass"
+       #  configurations above have to be set to "yes".
+       #
+       #  The strings below are dynamically expanded, which means that
+       #  you can put anything you want in them.  However, note that
+       #  this expansion can be slow, and can negatively impact server
+       #  performance.
+       #
+#      msg_goodpass = ""
+#      msg_badpass = ""
 }
 
 #  The program to execute to do concurrency checks.
index 6a9dadf..6c84c2b 100644 (file)
@@ -368,6 +368,8 @@ typedef struct main_config_t {
        radlog_dest_t   radlog_dest;
        CONF_SECTION    *config;
        const char      *name;
+       const char      *auth_badpass_msg;
+       const char      *auth_goodpass_msg;
 } MAIN_CONFIG_T;
 
 #define DEBUG  if(debug_flag)log_debug
index 4653970..e61b62c 100644 (file)
@@ -60,11 +60,14 @@ char *auth_name(char *buf, size_t buflen, REQUEST *request, int do_cli)
  * Make sure user/pass are clean
  * and then log them
  */
-static int rad_authlog(const char *msg, REQUEST *request, int goodpass) {
-
+static int rad_authlog(const char *msg, REQUEST *request, int goodpass)
+{
+       int logit;
+       const char *extra_msg = NULL;
        char clean_password[1024];
        char clean_username[1024];
        char buf[1024];
+       char extra[1024];
        VALUE_PAIR *username = NULL;
 
        if (!request->root->log_auth) {
@@ -117,21 +120,29 @@ static int rad_authlog(const char *msg, REQUEST *request, int goodpass) {
        }
 
        if (goodpass) {
-               radlog_request(L_AUTH, 0, request, "%s: [%s%s%s] (%s)",
-                               msg,
-                               clean_username,
-                               request->root->log_auth_goodpass ? "/" : "",
-                               request->root->log_auth_goodpass ? clean_password : "",
-                               auth_name(buf, sizeof(buf), request, 1));
+               logit = request->root->log_auth_goodpass;
+               extra_msg = request->root->auth_goodpass_msg;
+       } else {
+               logit = request->root->log_auth_badpass;
+               extra_msg = request->root->auth_badpass_msg;
+       }
+
+       if (extra_msg) {
+               extra[0] = ' ';
+               radius_xlat(extra + 1, sizeof(extra) - 1, extra_msg, request,
+                           NULL);
        } else {
-               radlog_request(L_AUTH, 0, request, "%s: [%s%s%s] (%s)",
-                               msg,
-                               clean_username,
-                               request->root->log_auth_badpass ? "/" : "",
-                               request->root->log_auth_badpass ? clean_password : "",
-                               auth_name(buf, sizeof(buf), request, 1));
+               *extra = '\0';
        }
 
+       radlog_request(L_AUTH, 0, request, "%s: [%s%s%s] (%s)%s",
+                      msg,
+                      clean_username,
+                      logit ? "/" : "",
+                      logit ? clean_password : "",
+                      auth_name(buf, sizeof(buf), request, 1),
+                      extra);
+
        return 0;
 }
 
index e371bb7..25d642a 100644 (file)
@@ -192,6 +192,8 @@ static const CONF_PARSER log_config_nodest[] = {
        { "auth", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth, "no" },
        { "auth_badpass", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth_badpass, "no" },
        { "auth_goodpass", PW_TYPE_BOOLEAN, 0, &mainconfig.log_auth_goodpass, "no" },
+       { "msg_badpass", PW_TYPE_STRING_PTR, 0, &mainconfig.auth_badpass_msg, NULL},
+       { "msg_goodpass", PW_TYPE_STRING_PTR, 0, &mainconfig.auth_goodpass_msg, NULL},
 
        { NULL, -1, 0, NULL, NULL }
 };