Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 May 2003 10:32:57 -0700 (PDT)
From:      Dag-Erling Smorgrav <des@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 31788 for review
Message-ID:  <200305241732.h4OHWv4d087044@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <ctype.h>
@@ -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.
+ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200305241732.h4OHWv4d087044>