include updates
[tomato.git] / release / src-rt-6.x.4708 / router / samba-3.0.25b / source / utils / net_util.c
blobbe39a754656e26d383128d293954b29aaf72debd
1 /*
2 * Unix SMB/CIFS implementation.
3 * Helper routines for net
4 * Copyright (C) Volker Lendecke 2006
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 #include "utils/net.h"
25 BOOL is_valid_policy_hnd(const POLICY_HND *hnd)
27 POLICY_HND tmp;
28 ZERO_STRUCT(tmp);
29 return (memcmp(&tmp, hnd, sizeof(tmp)) != 0);
32 NTSTATUS net_rpc_lookup_name(TALLOC_CTX *mem_ctx, struct cli_state *cli,
33 const char *name, const char **ret_domain,
34 const char **ret_name, DOM_SID *ret_sid,
35 enum lsa_SidType *ret_type)
37 struct rpc_pipe_client *lsa_pipe;
38 POLICY_HND pol;
39 NTSTATUS result = NT_STATUS_OK;
40 const char **dom_names;
41 DOM_SID *sids;
42 enum lsa_SidType *types;
44 ZERO_STRUCT(pol);
46 lsa_pipe = cli_rpc_pipe_open_noauth(cli, PI_LSARPC, &result);
47 if (lsa_pipe == NULL) {
48 d_fprintf(stderr, "Could not initialise lsa pipe\n");
49 return result;
52 result = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, False,
53 SEC_RIGHTS_MAXIMUM_ALLOWED,
54 &pol);
55 if (!NT_STATUS_IS_OK(result)) {
56 d_fprintf(stderr, "open_policy failed: %s\n",
57 nt_errstr(result));
58 return result;
61 result = rpccli_lsa_lookup_names(lsa_pipe, mem_ctx, &pol, 1,
62 &name, &dom_names, &sids, &types);
64 if (!NT_STATUS_IS_OK(result)) {
65 /* This can happen easily, don't log an error */
66 goto done;
69 if (ret_domain != NULL) {
70 *ret_domain = dom_names[0];
72 if (ret_name != NULL) {
73 *ret_name = talloc_strdup(mem_ctx, name);
75 if (ret_sid != NULL) {
76 sid_copy(ret_sid, &sids[0]);
78 if (ret_type != NULL) {
79 *ret_type = types[0];
82 done:
83 if (is_valid_policy_hnd(&pol)) {
84 rpccli_lsa_close(lsa_pipe, mem_ctx, &pol);
86 cli_rpc_pipe_close(lsa_pipe);
88 return result;