utils/net_util.c

説明を見る。
00001 /*
00002  *  Unix SMB/CIFS implementation.
00003  *  Helper routines for net
00004  *  Copyright (C) Volker Lendecke 2006
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 
00022 #include "includes.h"
00023 #include "utils/net.h"
00024 
00025 BOOL is_valid_policy_hnd(const POLICY_HND *hnd)
00026 {
00027         POLICY_HND tmp;
00028         ZERO_STRUCT(tmp);
00029         return (memcmp(&tmp, hnd, sizeof(tmp)) != 0);
00030 }
00031 
00032 NTSTATUS net_rpc_lookup_name(TALLOC_CTX *mem_ctx, struct cli_state *cli,
00033                              const char *name, const char **ret_domain,
00034                              const char **ret_name, DOM_SID *ret_sid,
00035                              enum lsa_SidType *ret_type)
00036 {
00037         struct rpc_pipe_client *lsa_pipe;
00038         POLICY_HND pol;
00039         NTSTATUS result = NT_STATUS_OK;
00040         const char **dom_names;
00041         DOM_SID *sids;
00042         enum lsa_SidType *types;
00043 
00044         ZERO_STRUCT(pol);
00045 
00046         lsa_pipe = cli_rpc_pipe_open_noauth(cli, PI_LSARPC, &result);
00047         if (lsa_pipe == NULL) {
00048                 d_fprintf(stderr, "Could not initialise lsa pipe\n");
00049                 return result;
00050         }
00051 
00052         result = rpccli_lsa_open_policy(lsa_pipe, mem_ctx, False, 
00053                                         SEC_RIGHTS_MAXIMUM_ALLOWED,
00054                                         &pol);
00055         if (!NT_STATUS_IS_OK(result)) {
00056                 d_fprintf(stderr, "open_policy failed: %s\n",
00057                           nt_errstr(result));
00058                 return result;
00059         }
00060 
00061         result = rpccli_lsa_lookup_names(lsa_pipe, mem_ctx, &pol, 1,
00062                                          &name, &dom_names, &sids, &types);
00063 
00064         if (!NT_STATUS_IS_OK(result)) {
00065                 /* This can happen easily, don't log an error */
00066                 goto done;
00067         }
00068 
00069         if (ret_domain != NULL) {
00070                 *ret_domain = dom_names[0];
00071         }
00072         if (ret_name != NULL) {
00073                 *ret_name = talloc_strdup(mem_ctx, name);
00074         }
00075         if (ret_sid != NULL) {
00076                 sid_copy(ret_sid, &sids[0]);
00077         }
00078         if (ret_type != NULL) {
00079                 *ret_type = types[0];
00080         }
00081 
00082  done:
00083         if (is_valid_policy_hnd(&pol)) {
00084                 rpccli_lsa_close(lsa_pipe, mem_ctx, &pol);
00085         }
00086         cli_rpc_pipe_close(lsa_pipe);
00087 
00088         return result;
00089 }

Sambaに対してSat Aug 29 21:23:29 2009に生成されました。  doxygen 1.4.7