/ [pam-modules] / trunk / common.c
To checkout: svn checkout http://svn.gnu.org.ua/sources/pam-modules/trunk/common.c
Puszcza

Contents of /trunk/common.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 58 - (show annotations)
Tue Aug 14 08:50:50 2007 UTC (14 years, 2 months ago) by gray
File MIME type: text/plain
File size: 3846 byte(s)
* pam_fshadow/pam_fshadow.c: Include config.h and time.h
* pam_sql/pam_mysql.c, pam_sql/pam_pgsql.c, pam_sql/pam_sql.c: Use
_pam_log for diagnostics.
* pam_regex/pam_regex.c (pam_sm_authenticate): Remove unused variable.
* configure.ac: New option --enable-debug
* common.c (wait_debug): Bugfix
* pam_log/pam_log.c: Include ctype.h
(parse_priority): Change return type.
* pam_fshadow/Makefile.am, pam_log/Makefile.am,
pam_regex/Makefile.am, pam_sql/Makefile.am: Use CPPFLAGS in cc rules.

1 /* This file is part of pam-modules.
2 Copyright (C) 2001, 2007 Sergey Poznyakoff
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 3 of the License, or (at your
7 option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef PAM_CONV_AGAIN
18 # define PAM_CONV_AGAIN PAM_TRY_AGAIN
19 #endif
20 #ifndef PAM_AUTHTOK_RECOVER_ERR
21 # define PAM_AUTHTOK_RECOVER_ERR PAM_AUTHTOK_RECOVERY_ERR
22 #endif
23 #ifndef PAM_EXTERN
24 # define PAM_EXTERN
25 #endif
26
27 #include <regex.h>
28
29 #define XSTRDUP(s) (s) ? strdup(s) : NULL
30
31 #define PAM_OVERWRITE(s) \
32 do { \
33 register char *p; \
34 if ((p = s) != NULL) \
35 while (*p) *p++ = 0; \
36 } while (0)
37
38 #define PAM_DROP_REPLY(reply, nrepl) \
39 do { \
40 int i; \
41 for (i=0; i<nrepl; i++) { \
42 PAM_OVERWRITE(reply[i].resp); \
43 free(reply[i].resp); \
44 } \
45 if (reply) \
46 free(reply); \
47 } while (0)
48
49 static void
50 _pam_delete(char *x)
51 {
52 PAM_OVERWRITE(x);
53 free(x);
54 }
55
56 static void
57 _cleanup_string(pam_handle_t *pamh, void *x, int error_status)
58 {
59 _pam_delete(x);
60 }
61
62 static void
63 _cleanup_regex(pam_handle_t *pamh, void *x, int error_status)
64 {
65 regfree((regex_t*)x);
66 }
67
68 static void _pam_log(int err, const char *format, ...);
69
70 static void
71 make_str(pam_handle_t *pamh, const char *str, const char *name, char **ret)
72 {
73 int retval;
74 char *newstr = XSTRDUP(str);
75
76 retval = pam_set_data(pamh, name, (void *)newstr, _cleanup_string);
77 if (retval != PAM_SUCCESS) {
78 _pam_log(LOG_CRIT,
79 "can't keep data [%s]: %s",
80 name,
81 pam_strerror(pamh, retval));
82 _pam_delete(newstr);
83 } else {
84 *ret = newstr;
85 newstr = NULL;
86 }
87 }
88
89 #define MAKE_STR(pamh, str, var) \
90 make_str(pamh,str,#var,&var)
91
92 /* Syslog functions */
93 static int syslog_dont_open = 0;
94 static const char *syslog_tag = MODULE_NAME;
95 static int facility = LOG_AUTHPRIV;
96
97 static void
98 _pam_vlog(int err, const char *format, va_list args)
99 {
100 if (syslog_dont_open)
101 err |= facility;
102 else
103 openlog(syslog_tag, LOG_CONS|LOG_PID, facility);
104 vsyslog(err, format, args);
105 if (!syslog_dont_open)
106 closelog();
107 }
108
109 static void
110 _pam_log(int err, const char *format, ...)
111 {
112 va_list args;
113
114 va_start(args, format);
115 _pam_vlog(err, format, args);
116 va_end(args);
117 }
118
119 static void
120 _pam_debug(const char *format, ...)
121 {
122 va_list args;
123
124 va_start(args, format);
125 _pam_vlog(LOG_DEBUG, format, args);
126 va_end(args);
127 }
128
129 void
130 wait_debug(size_t interval, const char *file, size_t line)
131 {
132 #ifdef DEBUG_MODE
133 if (!interval)
134 interval = 3600;
135 _pam_log(LOG_CRIT, "WAITING FOR DEBUG AT %s:%d",
136 file, (unsigned long)line);
137 while (interval-- > 0)
138 sleep(1);
139 #else
140 _pam_log(LOG_NOTICE, "Debugging is not configured");
141 #endif
142 }
143
144 #define WAITDEBUG(arg) do { size_t line = __LINE__; \
145 if ((arg)[0] == '=') \
146 wait_debug(atoi((arg)+1), __FILE__, line); \
147 else \
148 wait_debug(0, __FILE__, line); \
149 } while (0)

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

Send suggestions and bug reports to Sergey Poznyakoff
ViewVC Help
Powered by ViewVC 1.1.20