From owner-p4-projects@FreeBSD.ORG Sat May 24 10:32:59 2003 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2B37F37B404; Sat, 24 May 2003 10:32:59 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BA54837B401 for ; Sat, 24 May 2003 10:32:58 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4084743F93 for ; Sat, 24 May 2003 10:32:58 -0700 (PDT) (envelope-from des@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.6/8.12.6) with ESMTP id h4OHWw0U087047 for ; Sat, 24 May 2003 10:32:58 -0700 (PDT) (envelope-from des@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.6/8.12.6/Submit) id h4OHWv4d087044 for perforce@freebsd.org; Sat, 24 May 2003 10:32:57 -0700 (PDT) Date: Sat, 24 May 2003 10:32:57 -0700 (PDT) Message-Id: <200305241732.h4OHWv4d087044@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to des@freebsd.org using -f From: Dag-Erling Smorgrav To: Perforce Change Reviews Subject: PERFORCE change 31788 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 May 2003 17:33:00 -0000 http://perforce.freebsd.org/chv.cgi?CH=31788 Change 31788 by des@des.at.des.thinksec.com on 2003/05/24 10:32:38 Reorganize. Document. Replace malloc() + sprintf() with asprintf(). Affected files ... .. //depot/projects/openpam/lib/openpam_log.c#21 edit Differences ... ==== //depot/projects/openpam/lib/openpam_log.c#21 (text+ko) ==== @@ -31,7 +31,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $P4: //depot/projects/openpam/lib/openpam_log.c#20 $ + * $P4: //depot/projects/openpam/lib/openpam_log.c#21 $ */ #include @@ -47,20 +47,19 @@ int _openpam_debug = 0; -#if defined(openpam_log) +#if !defined(openpam_log) /* * OpenPAM extension * - * Log a message through syslog(3) + * Log a message through syslog */ void -_openpam_log(int level, const char *func, const char *fmt, ...) +openpam_log(int level, const char *fmt, ...) { va_list ap; - char *format; - int len, priority; + int priority; switch (level) { case PAM_LOG_DEBUG: @@ -80,30 +79,17 @@ break; } va_start(ap, fmt); - for (len = strlen(fmt); len > 0 && isspace(fmt[len]); len--) - /* nothing */; - if ((format = malloc(strlen(func) + len + 16)) != NULL) { - sprintf(format, "in %s(): %.*s\n", func, len, fmt); - vsyslog(priority, format, ap); - free(format); - } else { - vsyslog(priority, fmt, ap); - } + vsyslog(priority, fmt, ap); va_end(ap); } #else -/* - * If openpam_log isn't defined as a macro, we're on a platform that - * doesn't support varadic macros (or it does but we aren't aware of - * it). Do the next best thing. - */ - void -openpam_log(int level, const char *fmt, ...) +_openpam_log(int level, const char *func, const char *fmt, ...) { va_list ap; + char *format; int priority; switch (level) { @@ -124,8 +110,40 @@ break; } va_start(ap, fmt); - vsyslog(priority, fmt, ap); + if (asprintf(&format, "in %s(): %s", func, fmt) > 0) { + vsyslog(priority, format, ap); + free(format); + } else { + vsyslog(priority, fmt, ap); + } va_end(ap); } #endif + +/** + * The =openpam_log function logs messages using =syslog. It is primarily + * intended for internal use by the library and modules. + * + * The =level argument indicates the importance of the message. The + * following levels are defined: + * + * =PAM_LOG_DEBUG: + * Debugging messages. These messages are normally not + * logged unless the global integer variable :_openpam_debug + * is set to a non-zero value, in which case they are logged + * with a =syslog priority of =LOG_DEBUG. + * =PAM_LOG_VERBOSE: + * Information about the progress of the authentication + * process, or other non-essential messages. These messages + * are logged with a =syslog priority of =LOG_INFO. + * =PAM_LOG_NOTICE: + * Messages relating to non-fatal errors. These messages are + * logged with a =syslog priority of =LOG_NOTICE. + * =PAM_LOG_ERROR: + * Messages relating to serious errors. These messages are + * logged with a =syslog priority of =LOG_ERR. + * + * The remaining arguments are a =printf format string and the + * corresponding arguments. + */