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  * - Solar Designer
7  */
8 
9 #ifndef PAM_PASSWDQC_MACROS_H__
10 #define PAM_PASSWDQC_MACROS_H__
11 
12 #include <string.h>
13 #include <stdlib.h>
14 
15 static __inline void
16 pwqc_overwrite_string(char *x)
17 {
18 	if (x)
19 		memset(x, 0, strlen(x));
20 }
21 
22 static __inline void
23 pwqc_drop_mem(void *x)
24 {
25 	if (x) {
26 		free(x);
27 		x = NULL;
28 	}
29 }
30 
31 static __inline void
32 pwqc_drop_pam_reply(struct pam_response *reply, int replies)
33 {
34 	if (reply) {
35 		int reply_i;
36 
37 		for (reply_i = 0; reply_i < replies; ++reply_i) {
38 			pwqc_overwrite_string(reply[reply_i].resp);
39 			pwqc_drop_mem(reply[reply_i].resp);
40 		}
41 		pwqc_drop_mem(reply);
42 	}
43 }
44 
45 #endif /* PAM_PASSWDQC_MACROS_H__ */
46