File: pam_macros.h

package info (click to toggle)
passwdqc 2.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 508 kB
  • sloc: ansic: 9,510; makefile: 232; php: 35; sh: 10
file content (42 lines) | stat: -rw-r--r-- 851 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * These macros are partially based on Linux-PAM's <security/_pam_macros.h>,
 * which were organized by Cristian Gafton and I believe are in the public
 * domain.
 *
 * - Solar Designer
 */

#ifndef PAM_PASSWDQC_MACROS_H__
#define PAM_PASSWDQC_MACROS_H__

#include <string.h>
#include <stdlib.h>

#define pwqc_overwrite_string(x) \
do { \
	if (x) \
		memset((x), 0, strlen(x)); \
} while (0)

#define pwqc_drop_mem(x) \
do { \
	if (x) { \
		free(x); \
		(x) = NULL; \
	} \
} while (0)

#define pwqc_drop_pam_reply(/* struct pam_response* */ reply, /* int */ replies) \
do { \
	if (reply) { \
		int reply_i; \
\
		for (reply_i = 0; reply_i < (replies); ++reply_i) { \
			pwqc_overwrite_string((reply)[reply_i].resp); \
			pwqc_drop_mem((reply)[reply_i].resp); \
		} \
		pwqc_drop_mem(reply); \
	} \
} while (0)

#endif /* PAM_PASSWDQC_MACROS_H__ */