cli_samr.c
来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 1,888 行 · 第 1/3 页
C
1,888 行
* @param acb_mask account control bit mask (to enumerate some particular * kind of accounts) * @param size max acceptable size of response * @param dom_users returned array of domain user names * @param rids returned array of domain user RIDs * @param num_dom_users numer returned entries * * @return NTSTATUS returned in rpc response **/NTSTATUS rpccli_samr_enum_dom_users(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol, uint32 *start_idx, uint16 acb_mask, uint32 size, char ***dom_users, uint32 **rids, uint32 *num_dom_users){ prs_struct qbuf; prs_struct rbuf; SAMR_Q_ENUM_DOM_USERS q; SAMR_R_ENUM_DOM_USERS r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; int i; DEBUG(10,("cli_samr_enum_dom_users starting at index %u\n", (unsigned int)*start_idx)); ZERO_STRUCT(q); ZERO_STRUCT(r); /* always init this */ *num_dom_users = 0; /* Fill query structure with parameters */ init_samr_q_enum_dom_users(&q, pol, *start_idx, acb_mask, 0, size); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_USERS, q, r, qbuf, rbuf, samr_io_q_enum_dom_users, samr_io_r_enum_dom_users, NT_STATUS_UNSUCCESSFUL); result = r.status; if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) goto done; *start_idx = r.next_idx; *num_dom_users = r.num_entries2; if (r.num_entries2) { /* allocate memory needed to return received data */ *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_entries2); if (!*rids) { DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n")); return NT_STATUS_NO_MEMORY; } *dom_users = TALLOC_ARRAY(mem_ctx, char*, r.num_entries2); if (!*dom_users) { DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n")); return NT_STATUS_NO_MEMORY; } /* fill output buffers with rpc response */ for (i = 0; i < r.num_entries2; i++) { fstring conv_buf; (*rids)[i] = r.sam[i].rid; unistr2_to_ascii(conv_buf, &(r.uni_acct_name[i]), sizeof(conv_buf) - 1); (*dom_users)[i] = talloc_strdup(mem_ctx, conv_buf); } } done: return result;}/* Enumerate domain groups */NTSTATUS rpccli_samr_enum_dom_groups(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol, uint32 *start_idx, uint32 size, struct acct_info **dom_groups, uint32 *num_dom_groups){ prs_struct qbuf, rbuf; SAMR_Q_ENUM_DOM_GROUPS q; SAMR_R_ENUM_DOM_GROUPS r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; uint32 name_idx, i; DEBUG(10,("cli_samr_enum_dom_groups starting at index %u\n", (unsigned int)*start_idx)); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_enum_dom_groups(&q, pol, *start_idx, size); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_GROUPS, q, r, qbuf, rbuf, samr_io_q_enum_dom_groups, samr_io_r_enum_dom_groups, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ result = r.status; if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) goto done; *num_dom_groups = r.num_entries2; if (*num_dom_groups == 0) goto done; if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) { result = NT_STATUS_NO_MEMORY; goto done; } memset(*dom_groups, 0, sizeof(struct acct_info) * (*num_dom_groups)); name_idx = 0; for (i = 0; i < *num_dom_groups; i++) { (*dom_groups)[i].rid = r.sam[i].rid; if (r.sam[i].hdr_name.buffer) { unistr2_to_ascii((*dom_groups)[i].acct_name, &r.uni_grp_name[name_idx], sizeof(fstring) - 1); name_idx++; } *start_idx = r.next_idx; } done: return result;}/* Enumerate domain groups */NTSTATUS rpccli_samr_enum_als_groups(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol, uint32 *start_idx, uint32 size, struct acct_info **dom_aliases, uint32 *num_dom_aliases){ prs_struct qbuf, rbuf; SAMR_Q_ENUM_DOM_ALIASES q; SAMR_R_ENUM_DOM_ALIASES r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; uint32 name_idx, i; DEBUG(10,("cli_samr_enum_als_groups starting at index %u\n", (unsigned int)*start_idx)); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_enum_dom_aliases(&q, pol, *start_idx, size); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ENUM_DOM_ALIASES, q, r, qbuf, rbuf, samr_io_q_enum_dom_aliases, samr_io_r_enum_dom_aliases, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ result = r.status; if (!NT_STATUS_IS_OK(result) && NT_STATUS_V(result) != NT_STATUS_V(STATUS_MORE_ENTRIES)) { goto done; } *num_dom_aliases = r.num_entries2; if (*num_dom_aliases == 0) goto done; if (!((*dom_aliases) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_aliases))) { result = NT_STATUS_NO_MEMORY; goto done; } memset(*dom_aliases, 0, sizeof(struct acct_info) * *num_dom_aliases); name_idx = 0; for (i = 0; i < *num_dom_aliases; i++) { (*dom_aliases)[i].rid = r.sam[i].rid; if (r.sam[i].hdr_name.buffer) { unistr2_to_ascii((*dom_aliases)[i].acct_name, &r.uni_grp_name[name_idx], sizeof(fstring) - 1); name_idx++; } *start_idx = r.next_idx; } done: return result;}/* Query alias members */NTSTATUS rpccli_samr_query_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *alias_pol, uint32 *num_mem, DOM_SID **sids){ prs_struct qbuf, rbuf; SAMR_Q_QUERY_ALIASMEM q; SAMR_R_QUERY_ALIASMEM r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; uint32 i; DEBUG(10,("cli_samr_query_aliasmem\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_query_aliasmem(&q, alias_pol); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASMEM, q, r, qbuf, rbuf, samr_io_q_query_aliasmem, samr_io_r_query_aliasmem, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (!NT_STATUS_IS_OK(result = r.status)) { goto done; } *num_mem = r.num_sids; if (*num_mem == 0) { *sids = NULL; result = NT_STATUS_OK; goto done; } if (!(*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_mem))) { result = NT_STATUS_UNSUCCESSFUL; goto done; } for (i = 0; i < *num_mem; i++) { (*sids)[i] = r.sid[i].sid; } done: return result;}/* Open handle on an alias */NTSTATUS rpccli_samr_open_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *domain_pol, uint32 access_mask, uint32 alias_rid, POLICY_HND *alias_pol){ prs_struct qbuf, rbuf; SAMR_Q_OPEN_ALIAS q; SAMR_R_OPEN_ALIAS r; NTSTATUS result; DEBUG(10,("cli_samr_open_alias with rid 0x%x\n", alias_rid)); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_open_alias(&q, domain_pol, access_mask, alias_rid); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_OPEN_ALIAS, q, r, qbuf, rbuf, samr_io_q_open_alias, samr_io_r_open_alias, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (NT_STATUS_IS_OK(result = r.status)) { *alias_pol = r.pol;#ifdef __INSURE__ alias_pol->marker = malloc(1);#endif } return result;}/* Create an alias */NTSTATUS rpccli_samr_create_dom_alias(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *domain_pol, const char *name, POLICY_HND *alias_pol){ prs_struct qbuf, rbuf; SAMR_Q_CREATE_DOM_ALIAS q; SAMR_R_CREATE_DOM_ALIAS r; NTSTATUS result; DEBUG(10,("cli_samr_create_dom_alias named %s\n", name)); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_create_dom_alias(&q, domain_pol, name); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CREATE_DOM_ALIAS, q, r, qbuf, rbuf, samr_io_q_create_dom_alias, samr_io_r_create_dom_alias, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (NT_STATUS_IS_OK(result = r.status)) { *alias_pol = r.alias_pol; } return result;}/* Add an alias member */NTSTATUS rpccli_samr_add_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *alias_pol, DOM_SID *member){ prs_struct qbuf, rbuf; SAMR_Q_ADD_ALIASMEM q; SAMR_R_ADD_ALIASMEM r; NTSTATUS result; DEBUG(10,("cli_samr_add_aliasmem")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_add_aliasmem(&q, alias_pol, member); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_ADD_ALIASMEM, q, r, qbuf, rbuf, samr_io_q_add_aliasmem, samr_io_r_add_aliasmem, NT_STATUS_UNSUCCESSFUL); result = r.status; return result;}/* Delete an alias member */NTSTATUS rpccli_samr_del_aliasmem(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *alias_pol, DOM_SID *member){ prs_struct qbuf, rbuf; SAMR_Q_DEL_ALIASMEM q; SAMR_R_DEL_ALIASMEM r; NTSTATUS result; DEBUG(10,("cli_samr_del_aliasmem")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_del_aliasmem(&q, alias_pol, member); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_DEL_ALIASMEM, q, r, qbuf, rbuf, samr_io_q_del_aliasmem, samr_io_r_del_aliasmem, NT_STATUS_UNSUCCESSFUL); result = r.status; return result;}/* Query alias info */NTSTATUS rpccli_samr_query_alias_info(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *alias_pol, uint16 switch_value, ALIAS_INFO_CTR *ctr){ prs_struct qbuf, rbuf; SAMR_Q_QUERY_ALIASINFO q; SAMR_R_QUERY_ALIASINFO r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_query_alias_info\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_query_aliasinfo(&q, alias_pol, switch_value); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_ALIASINFO, q, r, qbuf, rbuf, samr_io_q_query_aliasinfo, samr_io_r_query_aliasinfo, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (!NT_STATUS_IS_OK(result = r.status)) { goto done; } *ctr = *r.ctr; done: return result;}/* Query domain info */NTSTATUS rpccli_samr_query_dom_info(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, POLICY_HND *domain_pol, uint16 switch_value, SAM_UNK_CTR *ctr){ prs_struct qbuf, rbuf; SAMR_Q_QUERY_DOMAIN_INFO q; SAMR_R_QUERY_DOMAIN_INFO r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; DEBUG(10,("cli_samr_query_dom_info\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Marshall data and send request */ init_samr_q_query_dom_info(&q, domain_pol, switch_value); r.ctr = ctr; CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_QUERY_DOMAIN_INFO, q, r, qbuf, rbuf, samr_io_q_query_dom_info, samr_io_r_query_dom_info, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (!NT_STATUS_IS_OK(result = r.status)) { goto done; } done: return result;}/* User change password */NTSTATUS rpccli_samr_chgpasswd_user(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, const char *username, const char *newpassword, const char *oldpassword ){ prs_struct qbuf, rbuf; SAMR_Q_CHGPASSWD_USER q; SAMR_R_CHGPASSWD_USER r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; uchar new_nt_password[516]; uchar new_lm_password[516]; uchar old_nt_hash[16]; uchar old_lanman_hash[16]; uchar old_nt_hash_enc[16]; uchar old_lanman_hash_enc[16]; uchar new_nt_hash[16]; uchar new_lanman_hash[16]; char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost); DEBUG(10,("rpccli_samr_chgpasswd_user\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); /* Calculate the MD4 hash (NT compatible) of the password */ E_md4hash(oldpassword, old_nt_hash); E_md4hash(newpassword, new_nt_hash); if (lp_client_lanman_auth() && E_deshash(newpassword, new_lanman_hash) && E_deshash(oldpassword, old_lanman_hash)) { /* E_deshash returns false for 'long' passwords (> 14 DOS chars). This allows us to match Win2k, which does not store a LM hash for these passwords (which would reduce the effective password length to 14) */ encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE); SamOEMhash( new_lm_password, old_nt_hash, 516); E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc); } else { ZERO_STRUCT(new_lm_password); ZERO_STRUCT(old_lanman_hash_enc); } encode_pw_buffer(new_nt_password, newpassword, STR_UNICODE); SamOEMhash( new_nt_password, old_nt_hash, 516); E_old_pw_hash( new_nt_hash, old_nt_hash, old_nt_hash_enc); /* Marshall data and send request */ init_samr_q_chgpasswd_user(&q, srv_name_slash, username, new_nt_password, old_nt_hash_enc, new_lm_password, old_lanman_hash_enc); CLI_DO_RPC(cli, mem_ctx, PI_SAMR, SAMR_CHGPASSWD_USER, q, r, qbuf, rbuf, samr_io_q_chgpasswd_user, samr_io_r_chgpasswd_user, NT_STATUS_UNSUCCESSFUL); /* Return output parameters */ if (!NT_STATUS_IS_OK(result = r.status)) { goto done; } done: return result;}/* change password 3 */NTSTATUS rpccli_samr_chgpasswd3(struct rpc_pipe_client *cli, TALLOC_CTX *mem_ctx, const char *username, const char *newpassword, const char *oldpassword, SAM_UNK_INFO_1 **info, SAMR_CHANGE_REJECT **reject){ prs_struct qbuf, rbuf; SAMR_Q_CHGPASSWD3 q; SAMR_R_CHGPASSWD3 r; NTSTATUS result = NT_STATUS_UNSUCCESSFUL; uchar new_nt_password[516]; uchar new_lm_password[516]; uchar old_nt_hash[16]; uchar old_lanman_hash[16]; uchar old_nt_hash_enc[16]; uchar old_lanman_hash_enc[16]; uchar new_nt_hash[16]; uchar new_lanman_hash[16]; char *srv_name_slash = talloc_asprintf(mem_ctx, "\\\\%s", cli->cli->desthost); DEBUG(10,("rpccli_samr_chgpasswd3\n")); ZERO_STRUCT(q); ZERO_STRUCT(r); *info = NULL; *reject = NULL; /* Calculate the MD4 hash (NT compatible) of the password */ E_md4hash(oldpassword, old_nt_hash); E_md4hash(newpassword, new_nt_hash); if (lp_client_lanman_auth() && E_deshash(newpassword, new_lanman_hash) && E_deshash(oldpassword, old_lanman_hash)) { /* E_deshash returns false for 'long' passwords (> 14 DOS chars). This allows us to match Win2k, which does not store a LM hash for these passwords (which would reduce the effective password length to 14) */ encode_pw_buffer(new_lm_password, newpassword, STR_UNICODE); SamOEMhash( new_lm_password, old_nt_hash, 516); E_old_pw_hash( new_nt_hash, old_lanman_hash, old_lanman_hash_enc); } else { ZERO_STRUCT(new_lm_password);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?