dsdb: Use write_data() to write to the password check script
[Samba.git] / auth / auth_util.c
blobf3586f1fc1e0515722b0335c0fc97e07cbc93920
1 /*
2 Unix SMB/CIFS implementation.
3 Authentication utility functions
5 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2017
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "librpc/ndr/libndr.h"
23 #include "librpc/gen_ndr/ndr_auth.h"
24 #include "auth_util.h"
26 struct auth_session_info *copy_session_info(TALLOC_CTX *mem_ctx,
27 const struct auth_session_info *src)
29 struct auth_session_info *dst;
30 DATA_BLOB blob;
31 enum ndr_err_code ndr_err;
33 ndr_err = ndr_push_struct_blob(
34 &blob,
35 talloc_tos(),
36 src,
37 (ndr_push_flags_fn_t)ndr_push_auth_session_info);
38 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
39 DBG_ERR("copy_session_info(): ndr_push_auth_session_info "
40 "failed: %s\n",
41 ndr_errstr(ndr_err));
42 return NULL;
45 dst = talloc(mem_ctx, struct auth_session_info);
46 if (dst == NULL) {
47 DBG_ERR("talloc failed\n");
48 TALLOC_FREE(blob.data);
49 return NULL;
52 ndr_err = ndr_pull_struct_blob(
53 &blob,
54 dst,
55 dst,
56 (ndr_pull_flags_fn_t)ndr_pull_auth_session_info);
57 TALLOC_FREE(blob.data);
59 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
60 DBG_ERR("copy_session_info(): ndr_pull_auth_session_info "
61 "failed: %s\n",
62 ndr_errstr(ndr_err));
63 TALLOC_FREE(dst);
64 return NULL;
67 return dst;