00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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 }