5 * All kind of macros used by PAM, but usable in some other
7 * Organized by Cristian Gafton <gafton@redhat.com>
8 * $FreeBSD: src/contrib/libpam/libpam/include/security/_pam_macros.h,v 1.1.1.1.6.2 2001/06/11 15:28:14 markm Exp $
11 /* a 'safe' version of strdup */
13 extern char *strdup(const char *s);
14 #define x_strdup(s) ( (s) ? strdup(s):NULL )
16 /* Good policy to strike out passwords with some characters not just
19 #define _pam_overwrite(x) \
21 register char *__xx__; \
28 * Don't just free it, forget it too.
31 #define _pam_drop(X) \
39 #define _pam_drop_reply(/* struct pam_response * */ reply, /* int */ replies) \
43 for (reply_i=0; reply_i<replies; ++reply_i) { \
44 if (reply[reply_i].resp) { \
45 _pam_overwrite(reply[reply_i].resp); \
46 free(reply[reply_i].resp); \
53 /* some debugging code */
58 * This provides the necessary function to do debugging in PAM.
59 * Cristian Gafton <gafton@redhat.com>
63 #include <sys/types.h>
69 * This is for debugging purposes ONLY. DO NOT use on live systems !!!
70 * You have been warned :-) - CG
72 * to get automated debugging to the log file, it must be created manually.
73 * _PAM_LOGFILE must exist, mode 666
77 #define _PAM_LOGFILE "/tmp/pam-debug.log"
80 static void _pam_output_debug_info(const char *file, const char *fn
86 if (!(logfile = fopen(_PAM_LOGFILE,"a"))) {
90 fprintf(logfile,"[%s:%s(%d)] ",file, fn, line);
97 static void _pam_output_debug(const char *format, ...)
103 va_start(args, format);
105 if (!(logfile = fopen(_PAM_LOGFILE,"a"))) {
109 vfprintf(logfile, format, args);
110 fprintf(logfile, "\n");
120 _pam_output_debug_info(__FILE__, __FUNCTION__, __LINE__); \
121 _pam_output_debug x ; \
124 #define _pam_show_mem(X,XS) do { \
126 register unsigned char *x; \
127 x = (unsigned char *)X; \
128 fprintf(stderr, " <start at %p>\n", X); \
129 for (i = 0; i < XS ; ++x, ++i) { \
130 fprintf(stderr, " %02X. <%p:%02X>\n", i, x, *x); \
132 fprintf(stderr, " <end for %p after %d bytes>\n", X, XS); \
135 #define _pam_show_reply(/* struct pam_response * */reply, /* int */replies) \
138 setbuf(stderr, NULL); \
139 fprintf(stderr, "array at %p of size %d\n",reply,replies); \
142 for (reply_i = 0; reply_i < replies; reply_i++) { \
143 fprintf(stderr, " elem# %d at %p: resp = %p, retcode = %d\n", \
144 reply_i, reply+reply_i, reply[reply_i].resp, \
145 reply[reply_i].resp, _retcode); \
147 if (reply[reply_i].resp) { \
148 fprintf(stderr, " resp[%d] = '%s'\n", \
149 strlen(reply[reply_i].resp), reply[reply_i].resp); \
154 fprintf(stderr, "done here\n"); \
160 #define D(x) do { } while (0)
161 #define _pam_show_mem(X,XS) do { } while (0)
162 #define _pam_show_reply(reply, replies) do { } while (0)
166 #endif /* PAM_MACROS_H */