diff options
Diffstat (limited to 'contrib/pam_modules/pam_passwdqc/pam_macros.h')
-rw-r--r-- | contrib/pam_modules/pam_passwdqc/pam_macros.h | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/contrib/pam_modules/pam_passwdqc/pam_macros.h b/contrib/pam_modules/pam_passwdqc/pam_macros.h index adc04bcb1f77..e4741bc307cc 100644 --- a/contrib/pam_modules/pam_passwdqc/pam_macros.h +++ b/contrib/pam_modules/pam_passwdqc/pam_macros.h @@ -2,27 +2,41 @@ * 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 */ -#if !defined(_PAM_MACROS_H) && !defined(_pam_overwrite) -#define _PAM_MACROS_H +#ifndef PAM_PASSWDQC_MACROS_H__ +#define PAM_PASSWDQC_MACROS_H__ #include <string.h> #include <stdlib.h> -#define _pam_overwrite(x) \ - memset((x), 0, strlen((x))) +#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 _pam_drop_reply(/* struct pam_response * */ reply, /* int */ replies) \ +#define pwqc_drop_pam_reply(/* struct pam_response* */ reply, /* int */ replies) \ do { \ - int i; \ + if (reply) { \ + int reply_i; \ \ - for (i = 0; i < (replies); i++) \ - if ((reply)[i].resp) { \ - _pam_overwrite((reply)[i].resp); \ - free((reply)[i].resp); \ + 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); \ } \ - if ((reply)) free((reply)); \ } while (0) -#endif +#endif /* PAM_PASSWDQC_MACROS_H__ */ |