cli_samr.c
来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 1,888 行 · 第 1/3 页
C
1,888 行
/* Unix SMB/CIFS implementation. RPC pipe client Copyright (C) Tim Potter 2000-2001, Copyright (C) Andrew Tridgell 1992-1997,2000, Copyright (C) Rafal Szczesniak 2002. Copyright (C) Jeremy Allison 2005. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "includes.h"/* Connect to SAMR database */NTSTATUS rpccli_samr_connect(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, uint32 access_mask, POLICY_HND *connect_pol){ prs_struct qbuf, rbuf; SAMR_Q_CONNECT q; SAMR_R_CONNECT r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_connect to %s\n", cli->cli->desthost)); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_connect(&q, cli->cli->desthost, access_mask); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CONNECT, q, r, qbuf, rbuf, samr_io_q_connect, samr_io_r_connect, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (NT_STATUS_IS_OK(result = r.status)) { *connect_pol = r.connect_pol;#ifdef __INSURE__ connect_pol->marker = malloc(1);#endif } return result;}/* Connect to SAMR database */NTSTATUS rpccli_samr_connect4(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, uint32 access_mask, POLICY_HND *connect_pol){ prs_struct qbuf, rbuf; SAMR_Q_CONNECT4 q; SAMR_R_CONNECT4 r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_connect4(&q, cli->cli->desthost, access_mask); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CONNECT4, q, r, qbuf, rbuf, samr_io_q_connect4, samr_io_r_connect4, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (NT_STATUS_IS_OK(result = r.status)) { *connect_pol = r.connect_pol;#ifdef __INSURE__ connect_pol->marker = malloc(1);#endif } return result;}/* Close SAMR handle */NTSTATUS rpccli_samr_close(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *connect_pol){ prs_struct qbuf, rbuf; SAMR_Q_CLOSE_HND q; SAMR_R_CLOSE_HND r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_close\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_close_hnd(&q, connect_pol); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CLOSE_HND, q, r, qbuf, rbuf, samr_io_q_close_hnd, samr_io_r_close_hnd, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (NT_STATUS_IS_OK(result = r.status)) {#ifdef __INSURE__ SAFE_FREE(connect_pol->marker);#endif *connect_pol = r.pol; } return result;}/* Open handle on a domain */NTSTATUS rpccli_samr_open_domain(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *connect_pol, uint32 access_mask, const DOM_SID *domain_sid, POLICY_HND *domain_pol){ prs_struct qbuf, rbuf; SAMR_Q_OPEN_DOMAIN q; SAMR_R_OPEN_DOMAIN r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_open_domain with sid %s\n", sid_string_static(domain_sid) )); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_open_domain(&q, connect_pol, access_mask, domain_sid); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_DOMAIN, q, r, qbuf, rbuf, samr_io_q_open_domain, samr_io_r_open_domain, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (NT_STATUS_IS_OK(result = r.status)) { *domain_pol = r.domain_pol;#ifdef __INSURE__ domain_pol->marker = malloc(1);#endif } return result;}NTSTATUS rpccli_samr_open_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *domain_pol, uint32 access_mask, uint32 user_rid, POLICY_HND *user_pol){ prs_struct qbuf, rbuf; SAMR_Q_OPEN_USER q; SAMR_R_OPEN_USER r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_open_user with rid 0x%x\n", user_rid )); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_open_user(&q, domain_pol, access_mask, user_rid); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_USER, q, r, qbuf, rbuf, samr_io_q_open_user, samr_io_r_open_user, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (NT_STATUS_IS_OK(result = r.status)) { *user_pol = r.user_pol;#ifdef __INSURE__ user_pol->marker = malloc(1);#endif } return result;}/* Open handle on a group */NTSTATUS rpccli_samr_open_group(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *domain_pol, uint32 access_mask, uint32 group_rid, POLICY_HND *group_pol){ prs_struct qbuf, rbuf; SAMR_Q_OPEN_GROUP q; SAMR_R_OPEN_GROUP r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_open_group with rid 0x%x\n", group_rid )); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_open_group(&q, domain_pol, access_mask, group_rid); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_GROUP, q, r, qbuf, rbuf, samr_io_q_open_group, samr_io_r_open_group, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (NT_STATUS_IS_OK(result = r.status)) { *group_pol = r.pol;#ifdef __INSURE__ group_pol->marker = malloc(1);#endif } return result;}/* Create domain group */NTSTATUS rpccli_samr_create_dom_group(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *domain_pol, const char *group_name, uint32 access_mask, POLICY_HND *group_pol){ prs_struct qbuf, rbuf; SAMR_Q_CREATE_DOM_GROUP q; SAMR_R_CREATE_DOM_GROUP r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_create_dom_group\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_create_dom_group(&q, domain_pol, group_name, access_mask); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_DOM_GROUP, q, r, qbuf, rbuf, samr_io_q_create_dom_group, samr_io_r_create_dom_group, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ result = r.status; if (NT_STATUS_IS_OK(result)) *group_pol = r.pol; return result;}/* Add a domain group member */NTSTATUS rpccli_samr_add_groupmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *group_pol, uint32 rid){ prs_struct qbuf, rbuf; SAMR_Q_ADD_GROUPMEM q; SAMR_R_ADD_GROUPMEM r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_add_groupmem\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_add_groupmem(&q, group_pol, rid); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ADD_GROUPMEM, q, r, qbuf, rbuf, samr_io_q_add_groupmem, samr_io_r_add_groupmem, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ result = r.status; return result;}/* Delete a domain group member */NTSTATUS rpccli_samr_del_groupmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *group_pol, uint32 rid){ prs_struct qbuf, rbuf; SAMR_Q_DEL_GROUPMEM q; SAMR_R_DEL_GROUPMEM r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_del_groupmem\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_del_groupmem(&q, group_pol, rid); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DEL_GROUPMEM, q, r, qbuf, rbuf, samr_io_q_del_groupmem, samr_io_r_del_groupmem, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ result = r.status; return result;}/* Query user info */NTSTATUS rpccli_samr_query_userinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *user_pol, uint16 switch_value, SAM_USERINFO_CTR **ctr){ prs_struct qbuf, rbuf; SAMR_Q_QUERY_USERINFO q; SAMR_R_QUERY_USERINFO r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_query_userinfo\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_query_userinfo(&q, user_pol, switch_value); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERINFO, q, r, qbuf, rbuf, samr_io_q_query_userinfo, samr_io_r_query_userinfo, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ result = r.status; *ctr = r.ctr; return result;}/* Set group info */NTSTATUS rpccli_samr_set_groupinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *group_pol, GROUP_INFO_CTR *ctr){ prs_struct qbuf, rbuf; SAMR_Q_SET_GROUPINFO q; SAMR_R_SET_GROUPINFO r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_set_groupinfo\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_set_groupinfo(&q, group_pol, ctr); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_GROUPINFO, q, r, qbuf, rbuf, samr_io_q_set_groupinfo, samr_io_r_set_groupinfo, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ result = r.status; return result;}/* Query group info */NTSTATUS rpccli_samr_query_groupinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *group_pol, uint32 info_level, GROUP_INFO_CTR **ctr){ prs_struct qbuf, rbuf; SAMR_Q_QUERY_GROUPINFO q; SAMR_R_QUERY_GROUPINFO r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_query_groupinfo\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_query_groupinfo(&q, group_pol, info_level); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_GROUPINFO, q, r, qbuf, rbuf, samr_io_q_query_groupinfo, samr_io_r_query_groupinfo, NT_STATUS_UNSUCCESSFUL); *ctr = r.ctr; /* Return output parameters */ result = r.status; return result;}/* Query user groups */NTSTATUS rpccli_samr_query_usergroups(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *user_pol, uint32 *num_groups, DOM_GID **gid){ prs_struct qbuf, rbuf; SAMR_Q_QUERY_USERGROUPS q; SAMR_R_QUERY_USERGROUPS r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_query_usergroups\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_query_usergroups(&q, user_pol); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERGROUPS, q, r, qbuf, rbuf, samr_io_q_query_usergroups, samr_io_r_query_usergroups, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (NT_STATUS_IS_OK(result = r.status)) { *num_groups = r.num_entries; *gid = r.gid; } return result;}/* Set alias info */NTSTATUS rpccli_samr_set_aliasinfo(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *alias_pol, ALIAS_INFO_CTR *ctr){ prs_struct qbuf, rbuf; SAMR_Q_SET_ALIASINFO q; SAMR_R_SET_ALIASINFO r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_set_aliasinfo\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_set_aliasinfo(&q, alias_pol, ctr); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_SET_ALIASINFO, q, r, qbuf, rbuf, samr_io_q_set_aliasinfo, samr_io_r_set_aliasinfo, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ result = r.status; return result;}/* Query user aliases */NTSTATUS rpccli_samr_query_useraliases(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *dom_pol, uint32 num_sids, DOM_SID2 *sid, uint32 *num_aliases, uint32 **als_rids){ prs_struct qbuf, rbuf; SAMR_Q_QUERY_USERALIASES q; SAMR_R_QUERY_USERALIASES r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; int i; uint32 *sid_ptrs; DEBUG(10,("cli_samr_query_useraliases\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); sid_ptrs = TALLOC_ARRAY(mem_ctx, uint32, num_sids); if (sid_ptrs == NULL) return NT_STATUS_NO_MEMORY; for (i=0; i<num_sids; i++) sid_ptrs[i] = 1; /* Marshall data and send request */ init_samr_q_query_useraliases(&q, dom_pol, num_sids, sid_ptrs, sid); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_USERALIASES, q, r, qbuf, rbuf, samr_io_q_query_useraliases, samr_io_r_query_useraliases, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (NT_STATUS_IS_OK(result = r.status)) { *num_aliases = r.num_entries; *als_rids = r.rid; } return result;}/* Query user groups */NTSTATUS rpccli_samr_query_groupmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *group_pol, uint32 *num_mem, uint32 **rid, uint32 **attr){ prs_struct qbuf, rbuf; SAMR_Q_QUERY_GROUPMEM q; SAMR_R_QUERY_GROUPMEM r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_query_groupmem\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_query_groupmem(&q, group_pol); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_GROUPMEM, q, r, qbuf, rbuf, samr_io_q_query_groupmem, samr_io_r_query_groupmem, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (NT_STATUS_IS_OK(result = r.status)) { *num_mem = r.num_entries; *rid = r.rid; *attr = r.attr; } return result;}/** * Enumerate domain users * * @param cli client state structure * @param mem_ctx talloc context * @param pol opened domain policy handle * @param start_idx starting index of enumeration, returns context for next enumeration
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?