]> granicus.if.org Git - linux-pam/commitdiff
Relevant BUGIDs: none
authorThorsten Kukuk <kukuk@thkukuk.de>
Mon, 5 Sep 2005 07:58:19 +0000 (07:58 +0000)
committerThorsten Kukuk <kukuk@thkukuk.de>
Mon, 5 Sep 2005 07:58:19 +0000 (07:58 +0000)
Purpose of commit: cleanup

Commit summary:
---------------

Replace own conversation function with pam_info.
Replace _log_err with pam_syslog.

modules/pam_mail/pam_mail.c

index e064746508a94d3baf15b277ad93ca4b1794e96b..1c2c60431d1803a39d2857b63668edaa4963bb39 100644 (file)
 #include <unistd.h>
 #include <dirent.h>
 
-#ifdef WANT_PWDB
-#include <pwdb/pwdb_public.h>
-#endif
-
 #define DEFAULT_MAIL_DIRECTORY    PAM_PATH_MAILDIR
 #define MAIL_FILE_FORMAT          "%s%s/%s"
 #define MAIL_ENV_NAME             "MAIL"
 #include <security/pam_modules.h>
 #include <security/_pam_macros.h>
 #include <security/_pam_modutil.h>
-
-/* some syslogging */
-
-static void _log_err(int err, const char *format, ...)
-{
-    va_list args;
-
-    va_start(args, format);
-    openlog("PAM-mail", LOG_CONS|LOG_PID, LOG_AUTH);
-    vsyslog(err, format, args);
-    va_end(args);
-    closelog();
-}
+#include <security/pam_ext.h>
 
 /* argument parsing */
 
@@ -74,8 +58,9 @@ static void _log_err(int err, const char *format, ...)
 #define PAM_STANDARD_MAIL      0x0400
 #define PAM_QUIET_MAIL         0x1000
 
-static int _pam_parse(int flags, int argc, const char **argv, char **maildir,
-                     size_t *hashcount)
+static int
+_pam_parse (const pam_handle_t *pamh, int flags, int argc,
+           const char **argv, char **maildir, size_t *hashcount)
 {
     int ctrl=0;
 
@@ -102,8 +87,8 @@ static int _pam_parse(int flags, int argc, const char **argv, char **maildir,
                D(("new mail directory: %s", *maildir));
                ctrl |= PAM_NEW_MAIL_DIR;
            } else {
-               _log_err(LOG_CRIT,
-                        "failed to duplicate mail directory - ignored");
+               pam_syslog (pamh, LOG_CRIT,
+                           "failed to duplicate mail directory - ignored");
            }
        } else if (!strncmp(*argv,"hash=",5)) {
            char *ep = NULL;
@@ -120,7 +105,7 @@ static int _pam_parse(int flags, int argc, const char **argv, char **maildir,
        } else if (!strcmp(*argv,"empty")) {
            ctrl |= PAM_EMPTY_TOO;
        } else {
-           _log_err(LOG_ERR,"pam_parse: unknown option; %s",*argv);
+           pam_syslog(pamh,LOG_ERR,"pam_parse: unknown option; %s",*argv);
        }
     }
 
@@ -132,44 +117,6 @@ static int _pam_parse(int flags, int argc, const char **argv, char **maildir,
     return ctrl;
 }
 
-/* a front end for conversations */
-
-static int converse(pam_handle_t *pamh, int ctrl, int nargs
-                   , struct pam_message **message
-                   , struct pam_response **response)
-{
-    int retval;
-    const void *void_conv;
-    const struct pam_conv *conv;
-
-    D(("begin to converse"));
-
-    retval = pam_get_item( pamh, PAM_CONV, &void_conv ) ;
-    conv = (const struct pam_conv *) void_conv;
-    if ( retval == PAM_SUCCESS && conv ) {
-
-       retval = conv->conv(nargs, ( const struct pam_message ** ) message
-                           , response, conv->appdata_ptr);
-
-       D(("returned from application's conversation function"));
-
-       if (retval != PAM_SUCCESS && (PAM_DEBUG_ARG & ctrl) ) {
-           _log_err(LOG_DEBUG, "conversation failure [%s]"
-                    , pam_strerror(pamh, retval));
-       }
-
-    } else {
-       _log_err(LOG_ERR, "couldn't obtain coversation function [%s]"
-                , pam_strerror(pamh, retval));
-       if (retval == PAM_SUCCESS)
-         retval = PAM_BAD_ITEM; /* conv was NULL */
-    }
-
-    D(("ready to return from module conversation"));
-
-    return retval;                  /* propagate error status */
-}
-
 static int get_folder(pam_handle_t *pamh, int ctrl,
                      char **path_mail, char **folder_p, size_t hashcount)
 {
@@ -180,7 +127,7 @@ static int get_folder(pam_handle_t *pamh, int ctrl,
 
     retval = pam_get_user(pamh, &user, NULL);
     if (retval != PAM_SUCCESS || user == NULL) {
-       _log_err(LOG_ERR, "no user specified");
+       pam_syslog(pamh,LOG_ERR, "no user specified");
        return PAM_USER_UNKNOWN;
     }
 
@@ -189,7 +136,7 @@ static int get_folder(pam_handle_t *pamh, int ctrl,
        if (*path == '~') {       /* support for $HOME delivery */
            pwd = _pammodutil_getpwnam(pamh, user);
            if (pwd == NULL) {
-               _log_err(LOG_ERR, "user [%s] unknown", user);
+               pam_syslog(pamh,LOG_ERR, "user [%s] unknown", user);
                _pam_overwrite(*path_mail);
                _pam_drop(*path_mail);
                return PAM_USER_UNKNOWN;
@@ -198,14 +145,14 @@ static int get_folder(pam_handle_t *pamh, int ctrl,
             * "~/xxx" and "~xxx" are treated as same
             */
            if (!*++path || (*path == '/' && !*++path)) {
-               _log_err(LOG_ALERT, "badly formed mail path [%s]", *path_mail);
+               pam_syslog(pamh,LOG_ALERT, "badly formed mail path [%s]", *path_mail);
                _pam_overwrite(*path_mail);
                _pam_drop(*path_mail);
                return PAM_ABORT;
            }
            ctrl |= PAM_HOME_MAIL;
            if (hashcount != 0) {
-               _log_err(LOG_ALERT, "can't do hash= and home directory mail");
+               pam_syslog(pamh,LOG_ALERT, "can't do hash= and home directory mail");
            }
        }
     } else {
@@ -242,7 +189,7 @@ static int get_folder(pam_handle_t *pamh, int ctrl,
                _pam_drop(hash);
            } else {
              _pam_drop(folder);
-             _log_err(LOG_CRIT, "out of memory for mail folder");
+             pam_syslog(pamh,LOG_CRIT, "out of memory for mail folder");
              return PAM_BUF_ERR;
            }
        }
@@ -256,7 +203,7 @@ static int get_folder(pam_handle_t *pamh, int ctrl,
     user = NULL;
 
     if (folder == NULL) {
-       _log_err(LOG_CRIT, "out of memory for mail folder");
+       pam_syslog(pamh,LOG_CRIT, "out of memory for mail folder");
        return PAM_BUF_ERR;
     }
 
@@ -324,45 +271,22 @@ static int report_mail(pam_handle_t *pamh, int ctrl
 {
     int retval;
 
-    if (!(ctrl & PAM_MAIL_SILENT) || ((ctrl & PAM_QUIET_MAIL) && strcmp(type, "new"))) {
-       char *remark;
-
+    if (!(ctrl & PAM_MAIL_SILENT) ||
+       ((ctrl & PAM_QUIET_MAIL) && strcmp(type, "new")))
+      {
        if (ctrl & PAM_STANDARD_MAIL)
-           if (!strcmp(type, "no"))
-               remark = malloc(strlen(NO_MAIL_STANDARD_FORMAT)+1);
-           else
-               remark = malloc(strlen(YOUR_MAIL_STANDARD_FORMAT)+strlen(type)+1);
+         if (!strcmp(type, "no"))
+           retval = pam_info (pamh, "%s", NO_MAIL_STANDARD_FORMAT);
+         else
+           retval = pam_info (pamh, YOUR_MAIL_STANDARD_FORMAT, type);
        else
-           remark = malloc(strlen(YOUR_MAIL_VERBOSE_FORMAT)+strlen(type)+strlen(folder)+1);
-       if (remark == NULL) {
-           retval = PAM_BUF_ERR;
-       } else {
-           struct pam_message msg[1], *mesg[1];
-           struct pam_response *resp=NULL;
-
-           if (ctrl & PAM_STANDARD_MAIL)
-               if (!strcmp(type, "no"))
-                   sprintf(remark, NO_MAIL_STANDARD_FORMAT);
-               else
-                   sprintf(remark, YOUR_MAIL_STANDARD_FORMAT, type);
-           else
-               sprintf(remark, YOUR_MAIL_VERBOSE_FORMAT, type, folder);
-
-           mesg[0] = &msg[0];
-           msg[0].msg_style = PAM_TEXT_INFO;
-           msg[0].msg = remark;
-
-           retval = converse(pamh, ctrl, 1, mesg, &resp);
-
-           _pam_overwrite(remark);
-           _pam_drop(remark);
-           if (resp)
-               _pam_drop_reply(resp, 1);
-       }
-    } else {
+         retval = pam_info (pamh, YOUR_MAIL_VERBOSE_FORMAT, type, folder);
+      }
+    else
+      {
        D(("keeping quiet"));
        retval = PAM_SUCCESS;
-    }
+      }
 
     D(("returning %s", pam_strerror(pamh, retval)));
     return retval;
@@ -422,7 +346,7 @@ static int _do_mail(pam_handle_t *pamh, int flags, int argc,
      * the user has any new mail.
      */
 
-    ctrl = _pam_parse(flags, argc, argv, &path_mail, &hashcount);
+    ctrl = _pam_parse(pamh, flags, argc, argv, &path_mail, &hashcount);
 
     /* Do we have anything to do? */
 
@@ -452,11 +376,11 @@ static int _do_mail(pam_handle_t *pamh, int flags, int argc,
            if (retval != PAM_SUCCESS) {
                _pam_overwrite(folder);
                _pam_drop(folder);
-               _log_err(LOG_CRIT, "unable to set " MAIL_ENV_NAME " variable");
+               pam_syslog(pamh,LOG_CRIT, "unable to set " MAIL_ENV_NAME " variable");
                return retval;
            }
        } else {
-           _log_err(LOG_CRIT, "no memory for " MAIL_ENV_NAME " variable");
+           pam_syslog(pamh,LOG_CRIT, "no memory for " MAIL_ENV_NAME " variable");
            _pam_overwrite(folder);
            _pam_drop(folder);
            return retval;