installer - Several improvements
[dragonfly.git] / contrib / pam_passwdqc / pam_macros.h
1 /*
2  * These macros are partially based on Linux-PAM's <security/_pam_macros.h>,
3  * which were organized by Cristian Gafton and I believe are in the public
4  * domain.
5  */
6
7 #ifndef PAM_PASSWDQC_MACROS_H__
8 #define PAM_PASSWDQC_MACROS_H__
9
10 #include <string.h>
11 #include <stdlib.h>
12
13 #define pwqc_overwrite_string(x) \
14 do { \
15         if (x) \
16                 memset((x), 0, strlen(x)); \
17 } while (0)
18
19 #define pwqc_drop_mem(x) \
20 do { \
21         if (x) { \
22                 free(x); \
23                 (x) = NULL; \
24         } \
25 } while (0)
26
27 #define pwqc_drop_pam_reply(/* struct pam_response* */ reply, /* int */ replies) \
28 do { \
29         if (reply) { \
30                 int reply_i; \
31 \
32                 for (reply_i = 0; reply_i < (replies); ++reply_i) { \
33                         pwqc_overwrite_string((reply)[reply_i].resp); \
34                         pwqc_drop_mem((reply)[reply_i].resp); \
35                 } \
36                 pwqc_drop_mem(reply); \
37         } \
38 } while (0)
39
40 #endif /* PAM_PASSWDQC_MACROS_H__ */