2 Unix SMB/CIFS implementation.
3 kerberos authorization data (PAC) utility library
4 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
5 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
6 Copyright (C) Andrew Tridgell 2001
7 Copyright (C) Luke Howard 2002-2003
8 Copyright (C) Stefan Metzmacher 2004-2005
9 Copyright (C) Guenther Deschner 2005,2007,2008
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "librpc/gen_ndr/ndr_krb5pac.h"
28 #include "libads/kerberos_proto.h"
32 /****************************************************************
33 Given a username, password and other details, return the
34 PAC_LOGON_INFO (the structure containing the important user
35 information such as groups).
36 ****************************************************************/
38 NTSTATUS
kerberos_return_pac(TALLOC_CTX
*mem_ctx
,
43 time_t *renew_till_time
,
44 const char *cache_name
,
46 bool add_netbios_addr
,
47 time_t renewable_time
,
48 const char *impersonate_princ_s
,
49 struct PAC_LOGON_INFO
**logon_info
)
52 NTSTATUS status
= NT_STATUS_INVALID_PARAMETER
;
53 DATA_BLOB tkt
, ap_rep
, sesskey1
, sesskey2
;
54 char *client_princ_out
= NULL
;
55 const char *auth_princ
= NULL
;
56 const char *local_service
= NULL
;
57 const char *cc
= "MEMORY:kerberos_return_pac";
61 ZERO_STRUCT(sesskey1
);
62 ZERO_STRUCT(sesskey2
);
65 return NT_STATUS_INVALID_PARAMETER
;
72 if (!strchr_m(name
, '@')) {
73 auth_princ
= talloc_asprintf(mem_ctx
, "%s@%s", name
,
78 NT_STATUS_HAVE_NO_MEMORY(auth_princ
);
80 local_service
= talloc_asprintf(mem_ctx
, "%s$@%s",
81 lp_netbios_name(), lp_realm());
82 NT_STATUS_HAVE_NO_MEMORY(local_service
);
84 ret
= kerberos_kinit_password_ext(auth_princ
,
95 DEBUG(1,("kinit failed for '%s' with: %s (%d)\n",
96 auth_princ
, error_message(ret
), ret
));
97 /* status already set */
101 DEBUG(10,("got TGT for %s in %s\n", auth_princ
, cc
));
103 DEBUGADD(10,("\tvalid until: %s (%d)\n",
104 http_timestring(talloc_tos(), *expire_time
),
107 if (renew_till_time
) {
108 DEBUGADD(10,("\trenewable till: %s (%d)\n",
109 http_timestring(talloc_tos(), *renew_till_time
),
110 (int)*renew_till_time
));
113 /* we cannot continue with krb5 when UF_DONT_REQUIRE_PREAUTH is set,
114 * in that case fallback to NTLM - gd */
116 if (expire_time
&& renew_till_time
&&
117 (*expire_time
== 0) && (*renew_till_time
== 0)) {
118 return NT_STATUS_INVALID_LOGON_TYPE
;
121 ret
= cli_krb5_get_ticket(mem_ctx
,
129 impersonate_princ_s
);
131 DEBUG(1,("failed to get ticket for %s: %s\n",
132 local_service
, error_message(ret
)));
133 if (impersonate_princ_s
) {
134 DEBUGADD(1,("tried S4U2SELF impersonation as: %s\n",
135 impersonate_princ_s
));
137 status
= krb5_to_nt_status(ret
);
140 status
= ads_verify_ticket(mem_ctx
,
149 if (!NT_STATUS_IS_OK(status
)) {
150 DEBUG(1,("ads_verify_ticket failed: %s\n",
156 DEBUG(1,("no PAC\n"));
157 status
= NT_STATUS_INVALID_PARAMETER
;
162 if (cc
!= cache_name
) {
166 data_blob_free(&tkt
);
167 data_blob_free(&ap_rep
);
168 data_blob_free(&sesskey1
);
169 data_blob_free(&sesskey2
);
171 TALLOC_FREE(client_princ_out
);