Refactor dsgetdcname to be called via a wrapper function.
[Samba.git] / nsswitch / pam_winbind.h
blob0d9529e726a970660258d8c86cc71b37fa03057f
1 /*
2 * Copyright (c) Andrew Tridgell <tridge@samba.org> 2000
3 * Copyright (c) Tim Potter <tpot@samba.org> 2000
4 * Copyright (c) Andrew Bartlettt <abartlet@samba.org> 2002
5 * Copyright (c) Guenther Deschner <gd@samba.org> 2005-2008
6 * Copyright (c) Jan Rêkorajski 1999.
7 * Copyright (c) Andrew G. Morgan 1996-8.
8 * Copyright (c) Alex O. Yuriev, 1996.
9 * Copyright (c) Cristian Gafton 1996.
10 * Copyright (C) Elliot Lee <sopwith@redhat.com> 1996, Red Hat Software.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, and the entire permission notice in its entirety,
17 * including the disclaimer of warranties.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. The name of the author may not be used to endorse or promote
22 * products derived from this software without specific prior
23 * written permission.
25 * ALTERNATIVELY, this product may be distributed under the terms of
26 * the GNU Public License, in which case the provisions of the GPL are
27 * required INSTEAD OF the above restrictions. (This clause is
28 * necessary due to a potential bad interaction between the GPL and
29 * the restrictions contained in a BSD-style copyright.)
31 * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED
32 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
34 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
35 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
41 * OF THE POSSIBILITY OF SUCH DAMAGE.
44 /* pam_winbind header file
45 (Solaris needs some macros from Linux for common PAM code)
47 Shirish Kalele 2000
50 #ifndef _NSSWITCH_PAM_WINBIND_H_
51 #define _NSSWITCH_PAM_WINBIND_H_
53 #include "../lib/replace/replace.h"
54 #include "system/syslog.h"
55 #include "system/time.h"
56 #include <talloc.h>
57 #include "libwbclient/wbclient.h"
59 #define MODULE_NAME "pam_winbind"
60 #define PAM_SM_AUTH
61 #define PAM_SM_ACCOUNT
62 #define PAM_SM_PASSWORD
63 #define PAM_SM_SESSION
65 #ifndef PAM_WINBIND_CONFIG_FILE
66 #define PAM_WINBIND_CONFIG_FILE "/etc/security/pam_winbind.conf"
67 #endif
69 #include <iniparser.h>
71 #ifdef HAVE_LIBINTL_H
72 #include <libintl.h>
73 #endif
75 #if defined(LINUX)
77 /* newer versions of PAM have this in _pam_compat.h */
78 #ifndef PAM_AUTHTOK_RECOVERY_ERR
79 #define PAM_AUTHTOK_RECOVERY_ERR PAM_AUTHTOK_RECOVER_ERR
80 #endif
82 #else /* !LINUX */
84 /* Solaris always uses dynamic pam modules */
85 #define PAM_EXTERN extern
86 #if defined(HAVE_SECURITY_PAM_APPL_H)
87 #include <security/pam_appl.h>
88 #elif defined(HAVE_PAM_PAM_APPL_H)
89 #include <pam/pam_appl.h>
90 #endif
92 #ifndef PAM_AUTHTOK_RECOVER_ERR
93 #define PAM_AUTHTOK_RECOVER_ERR PAM_AUTHTOK_RECOVERY_ERR
94 #endif
96 #endif /* defined(SUNOS5) || defined(SUNOS4) || defined(HPUX) || defined(FREEBSD) || defined(AIX) */
98 #if defined(HAVE_SECURITY_PAM_MODULES_H)
99 #include <security/pam_modules.h>
100 #elif defined(HAVE_PAM_PAM_MODULES_H)
101 #include <pam/pam_modules.h>
102 #endif
104 #if defined(HAVE_SECURITY__PAM_MACROS_H)
105 #include <security/_pam_macros.h>
106 #elif defined(HAVE_PAM__PAM_MACROS_H)
107 #include <pam/_pam_macros.h>
108 #else
109 /* Define required macros from (Linux PAM 0.68) security/_pam_macros.h */
110 #define _pam_drop_reply(/* struct pam_response * */ reply, /* int */ replies) \
111 do { \
112 int reply_i; \
114 for (reply_i=0; reply_i<replies; ++reply_i) { \
115 if (reply[reply_i].resp) { \
116 _pam_overwrite(reply[reply_i].resp); \
117 free(reply[reply_i].resp); \
120 if (reply) \
121 free(reply); \
122 } while (0)
124 #define _pam_overwrite(x) \
125 do { \
126 register char *__xx__; \
127 if ((__xx__=(x))) \
128 while (*__xx__) \
129 *__xx__++ = '\0'; \
130 } while (0)
133 * Don't just free it, forget it too.
136 #define _pam_drop(X) SAFE_FREE(X)
138 #define x_strdup(s) ( (s) ? strdup(s):NULL )
139 #endif /* HAVE_SECURITY__PAM_MACROS_H */
141 #ifdef HAVE_SECURITY_PAM_EXT_H
142 #include <security/pam_ext.h>
143 #endif
145 #define WINBIND_DEBUG_ARG 0x00000001
146 #define WINBIND_USE_AUTHTOK_ARG 0x00000002
147 #define WINBIND_UNKNOWN_OK_ARG 0x00000004
148 #define WINBIND_TRY_FIRST_PASS_ARG 0x00000008
149 #define WINBIND_USE_FIRST_PASS_ARG 0x00000010
150 #define WINBIND__OLD_PASSWORD 0x00000020
151 #define WINBIND_REQUIRED_MEMBERSHIP 0x00000040
152 #define WINBIND_KRB5_AUTH 0x00000080
153 #define WINBIND_KRB5_CCACHE_TYPE 0x00000100
154 #define WINBIND_CACHED_LOGIN 0x00000200
155 #define WINBIND_CONFIG_FILE 0x00000400
156 #define WINBIND_SILENT 0x00000800
157 #define WINBIND_DEBUG_STATE 0x00001000
158 #define WINBIND_WARN_PWD_EXPIRE 0x00002000
159 #define WINBIND_MKHOMEDIR 0x00004000
161 #if defined(HAVE_GETTEXT) && !defined(__LCLINT__)
162 #define _(string) dgettext(MODULE_NAME, string)
163 #else
164 #define _(string) string
165 #endif
167 #define N_(string) string
170 * here is the string to inform the user that the new passwords they
171 * typed were not the same.
174 #define MISTYPED_PASS _("Sorry, passwords do not match")
176 #define on(x, y) (x & y)
177 #define off(x, y) (!(x & y))
179 #define PAM_WINBIND_NEW_AUTHTOK_REQD "PAM_WINBIND_NEW_AUTHTOK_REQD"
180 #define PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH "PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH"
181 #define PAM_WINBIND_HOMEDIR "PAM_WINBIND_HOMEDIR"
182 #define PAM_WINBIND_LOGONSCRIPT "PAM_WINBIND_LOGONSCRIPT"
183 #define PAM_WINBIND_LOGONSERVER "PAM_WINBIND_LOGONSERVER"
184 #define PAM_WINBIND_PROFILEPATH "PAM_WINBIND_PROFILEPATH"
185 #define PAM_WINBIND_PWD_LAST_SET "PAM_WINBIND_PWD_LAST_SET"
187 #define SECONDS_PER_DAY 86400
189 #define DEFAULT_DAYS_TO_WARN_BEFORE_PWD_EXPIRES 14
191 #include "winbind_client.h"
193 #define PAM_WB_REMARK_DIRECT(c,x)\
195 const char *error_string = NULL; \
196 error_string = _get_ntstatus_error_string(x);\
197 if (error_string != NULL) {\
198 _make_remark(c, PAM_ERROR_MSG, error_string);\
199 } else {\
200 _make_remark(c, PAM_ERROR_MSG, x);\
204 #define LOGON_KRB5_FAIL_CLOCK_SKEW 0x02000000
206 #define PAM_WB_CACHED_LOGON(x) (x & WBC_AUTH_USER_INFO_CACHED_ACCOUNT)
207 #define PAM_WB_KRB5_CLOCK_SKEW(x) (x & LOGON_KRB5_FAIL_CLOCK_SKEW)
208 #define PAM_WB_GRACE_LOGON(x) ((WBC_AUTH_USER_INFO_CACHED_ACCOUNT|WBC_AUTH_USER_INFO_GRACE_LOGON) == ( x & (WBC_AUTH_USER_INFO_CACHED_ACCOUNT|WBC_AUTH_USER_INFO_GRACE_LOGON)))
210 struct pwb_context {
211 pam_handle_t *pamh;
212 int flags;
213 int argc;
214 const char **argv;
215 dictionary *dict;
216 uint32_t ctrl;
219 #ifndef TALLOC_FREE
220 #define TALLOC_FREE(ctx) do { talloc_free(ctx); ctx=NULL; } while(0)
221 #endif
222 #define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
223 #define TALLOC_P(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
225 #endif /* _NSSWITCH_PAM_WINBIND_H_ */