Make sure we don't clobber the stack when response consists of the empty
[Samba/gebeck_regimport.git] / source3 / pam_smbpass / general.h
blob4f13d6013132eb1aae9469d764ea779dc4774f0b
1 #ifndef LINUX
2 /* This is only needed by modules in the Sun implementation. */
3 #include <security/pam_appl.h>
4 #endif /* LINUX */
6 #include <security/pam_modules.h>
8 #ifndef PAM_AUTHTOK_RECOVER_ERR
9 #define PAM_AUTHTOK_RECOVER_ERR PAM_AUTHTOK_RECOVERY_ERR
10 #endif
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <syslog.h>
15 #include <unistd.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <sys/wait.h>
21 * here is the string to inform the user that the new passwords they
22 * typed were not the same.
25 #define MISTYPED_PASS "Sorry, passwords do not match"
27 /* type definition for the control options */
29 typedef struct {
30 const char *token;
31 unsigned int mask; /* shall assume 32 bits of flags */
32 unsigned int flag;
33 } SMB_Ctrls;
35 #ifndef False
36 #define False (0)
37 #endif
39 #ifndef True
40 #define True (1)
41 #endif
43 /* macro to determine if a given flag is on */
44 #define on(x,ctrl) (smb_args[x].flag & ctrl)
46 /* macro to determine that a given flag is NOT on */
47 #define off(x,ctrl) (!on(x,ctrl))
49 /* macro to turn on/off a ctrl flag manually */
50 #define set(x,ctrl) (ctrl = ((ctrl)&smb_args[x].mask)|smb_args[x].flag)
51 #define unset(x,ctrl) (ctrl &= ~(smb_args[x].flag))
53 #ifndef __linux__
54 #define strncasecmp(s1,s2,n) StrnCaseCmp(s1,s2,n)
55 #endif
57 /* the generic mask */
58 #define _ALL_ON_ (~0U)
60 /* end of macro definitions definitions for the control flags */
63 * These are the options supported by the smb password module, very
64 * similar to the pwdb options
67 #define SMB__OLD_PASSWD 0 /* internal */
68 #define SMB__VERIFY_PASSWD 1 /* internal */
70 #define SMB_AUDIT 2 /* print more things than debug..
71 some information may be sensitive */
72 #define SMB_USE_FIRST_PASS 3
73 #define SMB_TRY_FIRST_PASS 4
74 #define SMB_NOT_SET_PASS 5 /* don't set the AUTHTOK items */
76 #define SMB__NONULL 6 /* internal */
77 #define SMB__QUIET 7 /* internal */
78 #define SMB_USE_AUTHTOK 8 /* insist on reading PAM_AUTHTOK */
79 #define SMB__NULLOK 9 /* Null token ok */
80 #define SMB_DEBUG 10 /* send more info to syslog(3) */
81 #define SMB_NODELAY 11 /* admin does not want a fail-delay */
82 #define SMB_MIGRATE 12 /* Does no authentication, just
83 updates the smb database. */
84 #define SMB_CONF_FILE 13 /* Alternate location of smb.conf */
86 #define SMB_CTRLS_ 14 /* number of ctrl arguments defined */
88 static const SMB_Ctrls smb_args[SMB_CTRLS_] = {
89 /* symbol token name ctrl mask ctrl *
90 * ------------------ ------------------ -------------- ---------- */
92 /* SMB__OLD_PASSWD */ { NULL, _ALL_ON_, 01 },
93 /* SMB__VERIFY_PASSWD */ { NULL, _ALL_ON_, 02 },
94 /* SMB_AUDIT */ { "audit", _ALL_ON_, 04 },
95 /* SMB_USE_FIRST_PASS */ { "use_first_pass", _ALL_ON_^(030), 010 },
96 /* SMB_TRY_FIRST_PASS */ { "try_first_pass", _ALL_ON_^(030), 020 },
97 /* SMB_NOT_SET_PASS */ { "not_set_pass", _ALL_ON_, 040 },
98 /* SMB__NONULL */ { "nonull", _ALL_ON_, 0100 },
99 /* SMB__QUIET */ { NULL, _ALL_ON_, 0200 },
100 /* SMB_USE_AUTHTOK */ { "use_authtok", _ALL_ON_, 0400 },
101 /* SMB__NULLOK */ { "nullok", _ALL_ON_^(0100), 0 },
102 /* SMB_DEBUG */ { "debug", _ALL_ON_, 01000 },
103 /* SMB_NODELAY */ { "nodelay", _ALL_ON_, 02000 },
104 /* SMB_MIGRATE */ { "migrate", _ALL_ON_^(0100), 04000 },
105 /* SMB_CONF_FILE */ { "smbconf=", _ALL_ON_, 0 },
108 #define SMB_DEFAULTS (smb_args[SMB__NONULL].flag)
111 * the following is used to keep track of the number of times a user fails
112 * to authenticate themself.
115 #define FAIL_PREFIX "-SMB-FAIL-"
116 #define SMB_MAX_RETRIES 3
118 struct _pam_failed_auth {
119 char *user; /* user that's failed to be authenticated */
120 int id; /* uid of requested user */
121 char *agent; /* attempt from user with name */
122 int count; /* number of failures so far */
126 * General use functions go here
129 /* from support.c */
130 int make_remark(pam_handle_t *, unsigned int, int, const char *);