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

Contents of /trunk/lib/mem.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 63 - (show annotations)
Thu Mar 13 13:53:32 2008 UTC (13 years, 7 months ago) by gray
File MIME type: text/plain
File size: 1989 byte(s)
* configure.ac (PAM_COMMON_INCLUDES): Add -I${top_srcdir}/lib.
(AC_OUTPUT): Add lib/Makefile.
* doc/pam-modules.texi: Document `transform' option.
* Make.rules: New file.

* lib/mem.c, lib/slist.c, lib/log.c, lib/converse.c,
lib/graypam.h, lib/Makefile.am, lib/transform.c.

* pam_regex/pam_regex.c: Implement user name transformations.

* pam_fshadow/Makefile.am, pam_sql/Makefile.am:
Add ../lib/libgraypam.la to LDADD
* pam_fshadow/pam_fshadow.c, pam_sql/pam_mysql.c,
pam_sql/pam_pgsql.c, pam_sql/pam_sql.c: Use functions from ../lib.

1 /* This file is part of pam-modules.
2 Copyright (C) 2008 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 #include <graypam.h>
18
19 jmp_buf gray_pam_jmp;
20
21 void
22 gray_raise(const char *fmt, ...)
23 {
24 va_list ap;
25 va_start(ap, fmt);
26 _pam_vlog(LOG_ERR, fmt, ap);
27 va_end(ap);
28 longjmp(gray_pam_jmp, 1);
29 }
30
31 void *
32 gray_malloc(size_t size)
33 {
34 void *p = malloc(size);
35 if (!p)
36 gray_raise("Not enough memory");
37 return p;
38 }
39
40 void *
41 gray_zalloc(size_t size)
42 {
43 void *p = malloc(size);
44 if (!p)
45 gray_raise("Not enough memory");
46 memset(p, 0, size);
47 return p;
48 }
49
50 void *
51 gray_realloc(void *ptr, size_t size)
52 {
53 ptr = realloc(ptr, size);
54 if (!ptr)
55 gray_raise("Not enough memory");
56 return ptr;
57 }
58
59
60 void
61 gray_pam_delete(char *x)
62 {
63 PAM_OVERWRITE(x);
64 free(x);
65 }
66
67 void
68 gray_cleanup_string(pam_handle_t *pamh, void *x, int error_status)
69 {
70 gray_pam_delete(x);
71 }
72
73 void
74 gray_cleanup_regex(pam_handle_t *pamh, void *x, int error_status)
75 {
76 regfree((regex_t*)x);
77 }
78
79 void
80 gray_make_str(pam_handle_t *pamh, const char *str, const char *name,
81 char **ret)
82 {
83 int retval;
84 char *newstr = XSTRDUP(str);
85
86 retval = pam_set_data(pamh, name, (void *)newstr, gray_cleanup_string);
87 if (retval != PAM_SUCCESS) {
88 _pam_log(LOG_CRIT,
89 "can't keep data [%s]: %s",
90 name,
91 pam_strerror(pamh, retval));
92 gray_pam_delete(newstr);
93 } else {
94 *ret = newstr;
95 newstr = NULL;
96 }
97 }

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