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 $
9 * $DragonFly: src/contrib/libpam/libpam/include/security/Attic/_pam_macros.h,v 1.2 2003/06/17 04:24:03 dillon Exp $
12 /* a 'safe' version of strdup */
14 extern char *strdup(const char *s);
15 #define x_strdup(s) ( (s) ? strdup(s):NULL )
17 /* Good policy to strike out passwords with some characters not just
20 #define _pam_overwrite(x) \
22 register char *__xx__; \
29 * Don't just free it, forget it too.
32 #define _pam_drop(X) \
40 #define _pam_drop_reply(/* struct pam_response * */ reply, /* int */ replies) \
44 for (reply_i=0; reply_i<replies; ++reply_i) { \
45 if (reply[reply_i].resp) { \
46 _pam_overwrite(reply[reply_i].resp); \
47 free(reply[reply_i].resp); \
54 /* some debugging code */
59 * This provides the necessary function to do debugging in PAM.
60 * Cristian Gafton <gafton@redhat.com>
64 #include <sys/types.h>
70 * This is for debugging purposes ONLY. DO NOT use on live systems !!!
71 * You have been warned :-) - CG
73 * to get automated debugging to the log file, it must be created manually.
74 * _PAM_LOGFILE must exist, mode 666
78 #define _PAM_LOGFILE "/tmp/pam-debug.log"
81 static void _pam_output_debug_info(const char *file, const char *fn
87 if (!(logfile = fopen(_PAM_LOGFILE,"a"))) {
91 fprintf(logfile,"[%s:%s(%d)] ",file, fn, line);
98 static void _pam_output_debug(const char *format, ...)
104 va_start(args, format);
106 if (!(logfile = fopen(_PAM_LOGFILE,"a"))) {
110 vfprintf(logfile, format, args);
111 fprintf(logfile, "\n");
121 _pam_output_debug_info(__FILE__, __FUNCTION__, __LINE__); \
122 _pam_output_debug x ; \
125 #define _pam_show_mem(X,XS) do { \
127 register unsigned char *x; \
128 x = (unsigned char *)X; \
129 fprintf(stderr, " <start at %p>\n", X); \
130 for (i = 0; i < XS ; ++x, ++i) { \
131 fprintf(stderr, " %02X. <%p:%02X>\n", i, x, *x); \
133 fprintf(stderr, " <end for %p after %d bytes>\n", X, XS); \
136 #define _pam_show_reply(/* struct pam_response * */reply, /* int */replies) \
139 setbuf(stderr, NULL); \
140 fprintf(stderr, "array at %p of size %d\n",reply,replies); \
143 for (reply_i = 0; reply_i < replies; reply_i++) { \
144 fprintf(stderr, " elem# %d at %p: resp = %p, retcode = %d\n", \
145 reply_i, reply+reply_i, reply[reply_i].resp, \
146 reply[reply_i].resp, _retcode); \
148 if (reply[reply_i].resp) { \
149 fprintf(stderr, " resp[%d] = '%s'\n", \
150 strlen(reply[reply_i].resp), reply[reply_i].resp); \
155 fprintf(stderr, "done here\n"); \
161 #define D(x) do { } while (0)
162 #define _pam_show_mem(X,XS) do { } while (0)
163 #define _pam_show_reply(reply, replies) do { } while (0)
167 #endif /* PAM_MACROS_H */