diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/proto.h | 16 | ||||
-rw-r--r-- | source3/include/rpc_samr_old.h | 91 | ||||
-rw-r--r-- | source3/rpc_parse/parse_samr.c | 402 | ||||
-rw-r--r-- | source3/rpc_server/srv_samr.c | 534 |
4 files changed, 777 insertions, 266 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index ccfa056ee5..cf3929f68d 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -2291,9 +2291,8 @@ void init_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_e, POLICY_HND *pol, uint16 switch_level); BOOL samr_io_q_query_aliasinfo(char *desc, SAMR_Q_QUERY_ALIASINFO *q_e, prs_struct *ps, int depth); -void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *r_u, - uint16 switch_value, char *acct_desc, - uint32 status); +void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *r_u, uint32 switch_level, + char* alias, char* alias_desc); BOOL samr_io_r_query_aliasinfo(char *desc, SAMR_R_QUERY_ALIASINFO *r_u, prs_struct *ps, int depth); BOOL samr_io_q_lookup_ids(char *desc, SAMR_Q_LOOKUP_IDS *q_u, prs_struct *ps, int depth); void init_samr_r_lookup_ids(SAMR_R_LOOKUP_IDS *r_u, @@ -2398,6 +2397,17 @@ void init_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER *q_u, BOOL samr_io_q_chgpasswd_user(char *desc, SAMR_Q_CHGPASSWD_USER *q_u, prs_struct *ps, int depth); void init_samr_r_chgpasswd_user(SAMR_R_CHGPASSWD_USER *r_u, uint32 status); BOOL samr_io_r_chgpasswd_user(char *desc, SAMR_R_CHGPASSWD_USER *r_u, prs_struct *ps, int depth); +BOOL samr_io_q_lookup_domain(char* desc, SAMR_Q_LOOKUP_DOMAIN* q_u, prs_struct *ps, int depth); +BOOL init_samr_r_lookup_domain(SAMR_R_LOOKUP_DOMAIN * r_u, + DOM_SID *dom_sid, uint32 status); +BOOL samr_io_r_lookup_domain(char *desc, SAMR_R_LOOKUP_DOMAIN * r_u, + prs_struct *ps, int depth); +BOOL samr_io_q_enum_domains(char *desc, SAMR_Q_ENUM_DOMAINS * q_e, + prs_struct *ps, int depth); +BOOL init_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS * r_u, + uint32 next_idx, fstring* domains, uint32 num_sam_entries); +BOOL samr_io_r_enum_domains(char *desc, SAMR_R_ENUM_DOMAINS * r_u, + prs_struct *ps, int depth); #endif /*The following definitions come from rpc_parse/parse_sec.c */ diff --git a/source3/include/rpc_samr_old.h b/source3/include/rpc_samr_old.h index 26dd2bf447..29c1672425 100644 --- a/source3/include/rpc_samr_old.h +++ b/source3/include/rpc_samr_old.h @@ -78,6 +78,8 @@ SamrTestPrivateFunctionsUser ********************************************************************/ #define SAMR_CLOSE_HND 0x01 +#define SAMR_LOOKUP_DOMAIN 0x05 +#define SAMR_ENUM_DOMAINS 0x06 #define SAMR_OPEN_DOMAIN 0x07 #define SAMR_QUERY_DOMAIN_INFO 0x08 #define SAMR_LOOKUP_IDS 0x10 @@ -404,7 +406,7 @@ typedef struct r_samr_query_domain_info } SAMR_R_QUERY_DOMAIN_INFO; - + /**************************************************************************** SAMR_Q_OPEN_DOMAIN - unknown_0 values seen associated with SIDs: @@ -431,7 +433,7 @@ typedef struct r_samr_open_domain_info } SAMR_R_OPEN_DOMAIN; -#define MAX_SAM_ENTRIES 250 +#define MAX_SAM_ENTRIES 600 typedef struct samr_entry_info { @@ -565,6 +567,59 @@ typedef struct r_samr_enum_dom_aliases_info } SAMR_R_ENUM_DOM_ALIASES; +/*************************************************************************** + SAMR_Q_LOOKUP_DOMAIN - obtain SID for a local domain + ***************************************************************************/ +typedef struct q_samr_lookup_domain_info +{ + POLICY_HND connect_pol; + + UNIHDR hdr_domain; + UNISTR2 uni_domain; + +} SAMR_Q_LOOKUP_DOMAIN; + +/* SAMR_R_LOOKUP_DOMAIN */ +typedef struct r_samr_lookup_domain_info +{ + uint32 ptr_sid; + DOM_SID2 dom_sid; + + uint32 status; + +} SAMR_R_LOOKUP_DOMAIN; + +/********************************************************************** + SAMR_Q_ENUM_DOMAINS - SAM rids and names + **********************************************************************/ +typedef struct q_samr_enum_domains_info +{ + POLICY_HND pol; /* policy handle */ + + uint32 start_idx; /* enumeration handle */ + uint32 max_size; /* 0x0000 ffff */ + +} SAMR_Q_ENUM_DOMAINS; + +/* SAMR_R_ENUM_DOMAINS - SAM rids and Domain names */ +typedef struct r_samr_enum_domains_info +{ + uint32 next_idx; /* next starting index required for enum */ + uint32 ptr_entries1; + + uint32 num_entries2; + uint32 ptr_entries2; + + uint32 num_entries3; + + SAM_ENTRY *sam; + UNISTR2 *uni_dom_name; + + uint32 num_entries4; + + uint32 status; + +} SAMR_R_ENUM_DOMAINS; /* SAMR_Q_QUERY_DISPINFO - SAM rids, names and descriptions */ @@ -573,9 +628,8 @@ typedef struct q_samr_query_disp_info POLICY_HND pol; /* policy handle */ uint16 switch_level; /* 0x0001 and 0x0002 seen */ - uint16 unknown_0; /* 0x0000 and 0x2000 seen */ uint32 start_idx; /* presumably the start enumeration index */ - uint32 unknown_1; /* 0x0000 07d0, 0x0000 0400 and 0x0000 0200 seen */ + uint32 max_entries; /* 0x0000 07d0, 0x0000 0400 and 0x0000 0200 seen */ uint32 max_size; /* 0x0000 7fff, 0x0000 7ffe and 0x0000 3fff seen*/ @@ -679,10 +733,19 @@ typedef struct q_samr_enum_alias_info { POLICY_HND pol; /* policy handle */ - uint16 switch_level; /* 0x0003 seen */ + uint16 switch_level; /* 0x0003 seen (0x0001 seen from NT5) */ } SAMR_Q_QUERY_ALIASINFO; +typedef struct samr_alias_info1 +{ + uint32 switch_value_1; + UNIHDR hdr_alias_name; + UNISTR2 uni_alias_name; + UNIHDR hdr_alias_desc; + UNISTR2 uni_alias_desc; +} ALIAS_INFO1; + typedef struct samr_alias_info3 { UNIHDR hdr_acct_desc; @@ -693,17 +756,18 @@ typedef struct samr_alias_info3 /* SAMR_R_QUERY_ALIASINFO - SAM rids, names and descriptions */ typedef struct r_samr_query_aliasinfo_info { - uint32 ptr; - uint16 switch_value; /* 0x0003 */ - /* uint8[2] padding */ + uint32 ptr; + uint16 switch_value; /* 0x0003 */ + /* uint8[2] padding */ - union - { - ALIAS_INFO3 info3; + union + { + ALIAS_INFO1 info1; + ALIAS_INFO3 info3; - } alias; + } alias; - uint32 status; + uint32 status; } SAMR_R_QUERY_ALIASINFO; @@ -1016,6 +1080,7 @@ typedef struct r_samr_unknown_38 uint16 unk_0; uint16 unk_1; uint16 unk_2; + uint16 unk_3; uint32 status; /* return status */ } SAMR_R_UNKNOWN_38; diff --git a/source3/rpc_parse/parse_samr.c b/source3/rpc_parse/parse_samr.c index 1c344c9d30..4a85524263 100644 --- a/source3/rpc_parse/parse_samr.c +++ b/source3/rpc_parse/parse_samr.c @@ -1,5 +1,4 @@ #define OLD_NTDOMAIN 1 - /* * Unix SMB/Netbios implementation. * Version 1.9. @@ -1301,9 +1300,8 @@ void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_e, POLICY_HND *pol, q_e->switch_level = switch_level; - q_e->unknown_0 = 0; q_e->start_idx = start_idx; - q_e->unknown_1 = 0x000007d0; + q_e->max_entries = 0; q_e->max_size = size; } @@ -1329,11 +1327,15 @@ BOOL samr_io_q_query_dispinfo(char *desc, SAMR_Q_QUERY_DISPINFO *q_e, prs_struc if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level)) return False; +#if 0 if(!prs_uint16("unknown_0 ", ps, depth, &q_e->unknown_0)) return False; +#else + prs_align(ps); +#endif if(!prs_uint32("start_idx ", ps, depth, &q_e->start_idx)) return False; - if(!prs_uint32("unknown_1 ", ps, depth, &q_e->unknown_1)) + if(!prs_uint32("max_entries ", ps, depth, &q_e->max_entries)) return False; if(!prs_uint32("max_size ", ps, depth, &q_e->max_size)) return False; @@ -1446,8 +1448,11 @@ void init_sam_info_1(SAM_INFO_1 *sam, uint32 acb_mask, DEBUG(5,("limiting number of entries to %d\n", num_sam_entries)); } + DEBUG(5,("num_sam_entries: %u, start_idx: %u\n",num_sam_entries, + num_sam_entries)); - for (i = start_idx, entries_added = 0; i < num_sam_entries; i++) { + for (i = 0, entries_added = 0; + i < num_sam_entries; i++) { if (IS_BITS_SET_ALL(pass[i].acb_info, acb_mask)) { init_sam_entry1(&sam->sam[entries_added], start_idx + entries_added + 1, @@ -1462,7 +1467,7 @@ void init_sam_info_1(SAM_INFO_1 *sam, uint32 acb_mask, copy_unistr2(&sam->str[entries_added].uni_acct_desc, &pass[i].uni_acct_desc); entries_added++; - } + } } sam->num_entries = entries_added; @@ -1523,7 +1528,7 @@ void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO *r_u, { DEBUG(5,("init_samr_r_query_dispinfo\n")); - if (status == 0x0) { + if (status == 0x0 || status == 0x105) { r_u->unknown_0 = 0x0000001; r_u->unknown_1 = 0x0000001; } else { @@ -1792,85 +1797,110 @@ BOOL samr_io_q_query_aliasinfo(char *desc, SAMR_Q_QUERY_ALIASINFO *q_e, prs_str Inits a SAMR_R_QUERY_ALIASINFO structure. ********************************************************************/ -void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *r_u, - uint16 switch_value, char *acct_desc, - uint32 status) -{ - DEBUG(5,("init_samr_r_query_aliasinfo\n")); - - r_u->ptr = 0; - - if (status == 0) { - r_u->switch_value = switch_value; - - switch (switch_value) { - case 3: - { - int acct_len = acct_desc ? strlen(acct_desc) : 0; - - r_u->ptr = 1; - - init_uni_hdr(&r_u->alias.info3.hdr_acct_desc, acct_len); - init_unistr2(&r_u->alias.info3.uni_acct_desc, acct_desc, acct_len); - - break; - } - default: - DEBUG(4,("init_samr_r_query_aliasinfo: unsupported switch level\n")); - break; - } +void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *r_u, uint32 switch_level, + char* alias, char* alias_desc) + +{ + int alias_desc_len, alias_len; + + if(r_u == NULL) + return; + + alias_len = alias?strlen(alias):0; + alias_desc_len = alias_desc?strlen(alias_desc):0; + + DEBUG(5,("init_samr_r_query_aliasinfo\n")); + + r_u->switch_value = switch_level; + + if(r_u->status == 0) + { + switch(switch_level) + { + case 1: + { + r_u->ptr = 1; + init_uni_hdr(&r_u->alias.info1.hdr_alias_name, alias_len); + init_unistr2(&r_u->alias.info1.uni_alias_name, alias, alias_len); + r_u->alias.info1.switch_value_1 = switch_level; + init_uni_hdr(&r_u->alias.info1.hdr_alias_desc, alias_desc_len); + init_unistr2(&r_u->alias.info1.uni_alias_desc, alias_desc, alias_desc_len); + break; + } + case 3: + { + r_u->ptr = 1; + init_uni_hdr(&r_u->alias.info3.hdr_acct_desc, alias_desc_len); + init_unistr2(&r_u->alias.info3.uni_acct_desc, alias_desc, alias_desc_len); + break; + } + default: + { + r_u->status = 0xC0000000 | NT_STATUS_INVALID_INFO_CLASS; + } } - - r_u->status = status; + } } + + /******************************************************************* Reads or writes a structure. ********************************************************************/ BOOL samr_io_r_query_aliasinfo(char *desc, SAMR_R_QUERY_ALIASINFO *r_u, prs_struct *ps, int depth) { - if (r_u == NULL) - return False; + if (r_u == NULL) + return False; - prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo"); - depth++; + prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo"); + depth++; - if(!prs_align(ps)) - return False; + if(!prs_align(ps)) + return False; - if(!prs_uint32("ptr ", ps, depth, &r_u->ptr)) - return False; + if(!prs_uint32("ptr ", ps, depth, &r_u->ptr)) + return False; - if (r_u->ptr != 0) { - if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value)) - return False; - if(!prs_align(ps)) - return False; - - if (r_u->switch_value != 0) { - switch (r_u->switch_value) { - case 3: - if(!smb_io_unihdr ("", &r_u->alias.info3.hdr_acct_desc, ps, depth)) - return False; - if(!smb_io_unistr2("", &r_u->alias.info3.uni_acct_desc, - r_u->alias.info3.hdr_acct_desc.buffer, ps, depth)) - return False; - break; - default: - DEBUG(4,("samr_io_r_query_aliasinfo: unsupported switch level\n")); - break; - } - } - } - - if(!prs_align(ps)) - return False; - - if(!prs_uint32("status", ps, depth, &r_u->status)) - return False; - - return True; + if (r_u->ptr != 0) { + if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value)) + return False; + if(!prs_align(ps)) + return False; + + if (r_u->switch_value != 0) { + switch (r_u->switch_value) { + case 1: + smb_io_unihdr("",&r_u->alias.info1.hdr_alias_name, ps, depth); + prs_uint32("switch_value_1", ps, depth, &r_u->alias.info1.switch_value_1); + smb_io_unihdr("",&r_u->alias.info1.hdr_alias_desc, ps, depth); + + smb_io_unistr2("", &r_u->alias.info1.uni_alias_name, + r_u->alias.info1.hdr_alias_name.buffer, ps, depth); + smb_io_unistr2("", &r_u->alias.info1.uni_alias_desc, + r_u->alias.info1.hdr_alias_desc.buffer, ps, depth); + break; + case 3: + if(!smb_io_unihdr ("", &r_u->alias.info3.hdr_acct_desc, ps, depth)) + return False; + if(!smb_io_unistr2("", &r_u->alias.info3.uni_acct_desc, + r_u->alias.info3.hdr_acct_desc.buffer, ps, depth)) + return False; + break; + default: + DEBUG(4,("samr_io_r_query_aliasinfo: unsupported switch level\n")); + break; + } + } + } + + if(!prs_align(ps)) + return False; + + if(!prs_uint32("status", ps, depth, &r_u->status)) + return False; + + return True; } /******************************************************************* @@ -3402,8 +3432,7 @@ void init_samr_r_unknown_38(SAMR_R_UNKNOWN_38 *r_u) r_u->unk_0 = 0; r_u->unk_1 = 0; r_u->unk_2 = 0; - - r_u->status = 0x0; + r_u->unk_3 = 0; } /******************************************************************* @@ -3433,7 +3462,9 @@ BOOL samr_io_r_unknown_38(char *desc, SAMR_R_UNKNOWN_38 *r_u, prs_struct *ps, i return False; if(!prs_align(ps)) return False; - if(!prs_uint32("status", ps, depth, &r_u->status)) + if(!prs_uint16("unk_3", ps, depth, &r_u->unk_3)) + return False; + if(!prs_align(ps)) return False; return True; @@ -3609,6 +3640,223 @@ BOOL samr_io_r_chgpasswd_user(char *desc, SAMR_R_CHGPASSWD_USER *r_u, prs_struct return True; } +/********************************************************************** + Reads or writes a structure + **********************************************************************/ +BOOL samr_io_q_lookup_domain(char* desc, SAMR_Q_LOOKUP_DOMAIN* q_u, prs_struct *ps, int depth) +{ + if (q_u == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_q_lookup_domain"); + depth++; + + prs_align(ps); + + smb_io_pol_hnd("connect_pol", &(q_u->connect_pol), ps, depth); + + smb_io_unihdr("hdr_domain", &(q_u->hdr_domain), ps, depth); + smb_io_unistr2("uni_domain", &(q_u->uni_domain), + q_u->hdr_domain.buffer, ps, depth); + prs_align(ps); + + return True; +} + +/******************************************************************* +makes a SAMR_R_LOOKUP_DOMAIN structure. +********************************************************************/ +BOOL init_samr_r_lookup_domain(SAMR_R_LOOKUP_DOMAIN * r_u, + DOM_SID *dom_sid, uint32 status) +{ + if (r_u == NULL) + return False; + + DEBUG(5, ("make_samr_r_lookup_domain\n")); + + r_u->status = status; + r_u->ptr_sid = 0; + if (status == 0x0) + { + r_u->ptr_sid = 1; + init_dom_sid2(&r_u->dom_sid, dom_sid); + } + + return True; +} + +/******************************************************************* +reads or writes a structure. +********************************************************************/ +BOOL samr_io_r_lookup_domain(char *desc, SAMR_R_LOOKUP_DOMAIN * r_u, + prs_struct *ps, int depth) +{ + if (r_u == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_r_lookup_domain"); + depth++; + + prs_align(ps); + + prs_uint32("ptr", ps, depth, &(r_u->ptr_sid)); + + if (r_u->ptr_sid != 0) + { + smb_io_dom_sid2("sid", &(r_u->dom_sid), ps, depth); + prs_align(ps); + } + + prs_uint32("status", ps, depth, &(r_u->status)); + + return True; +} + +/******************************************************************* +reads or writes a structure. +********************************************************************/ +BOOL samr_io_q_enum_domains(char *desc, SAMR_Q_ENUM_DOMAINS * q_e, + prs_struct *ps, int depth) +{ + if (q_e == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_q_enum_domains"); + depth++; + + prs_align(ps); + + smb_io_pol_hnd("pol", &(q_e->pol), ps, depth); + + prs_uint32("start_idx", ps, depth, &(q_e->start_idx)); + prs_uint32("max_size ", ps, depth, &(q_e->max_size)); + + prs_align(ps); + + return True; +} + +/******************************************************************* +makes a SAMR_R_ENUM_DOMAINS structure. +********************************************************************/ +BOOL init_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS * r_u, + uint32 next_idx, fstring* domains, uint32 num_sam_entries) +{ + int i=0; + + if (r_u == NULL) + return False; + + DEBUG(5, ("init_samr_r_enum_domains\n")); + + r_u->next_idx = next_idx; + + r_u->uni_dom_name = (UNISTR2*) malloc(sizeof(UNISTR2) * num_sam_entries); + r_u->sam = (SAM_ENTRY*) malloc(sizeof(SAM_ENTRY) * num_sam_entries); + if(r_u->uni_dom_name == NULL || r_u->sam == NULL) + { + free(r_u->uni_dom_name); + free(r_u->sam); + r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED; + } + + if(r_u->status == 0) + for(i=0;i<num_sam_entries;i++) /* only two domains to send */ + { + init_unistr2(&r_u->uni_dom_name[i],domains[i], strlen(domains[i])); + init_sam_entry(&(r_u->sam[i]), strlen(domains[i]), 0); + } + else + { + num_sam_entries = 0; + } + + if (num_sam_entries != 0) + { + r_u->ptr_entries1 = 1; + r_u->ptr_entries2 = 1; + r_u->num_entries2 = num_sam_entries; + r_u->num_entries3 = num_sam_entries; + + r_u->num_entries4 = num_sam_entries; + } + else + { + r_u->ptr_entries1 = 0; + r_u->num_entries2 = num_sam_entries; + r_u->ptr_entries2 = 1; + } + + return True; +} + +/******************************************************************* +reads or writes a structure. +********************************************************************/ +BOOL samr_io_r_enum_domains(char *desc, SAMR_R_ENUM_DOMAINS * r_u, + prs_struct *ps, int depth) +{ + uint32 i; + + if (r_u == NULL) + return False; + + prs_debug(ps, depth, desc, "samr_io_r_enum_domains"); + depth++; + + prs_align(ps); + + prs_uint32("next_idx ", ps, depth, &(r_u->next_idx)); + prs_uint32("ptr_entries1", ps, depth, &(r_u->ptr_entries1)); + + if (r_u->ptr_entries1 != 0) + { + prs_uint32("num_entries2", ps, depth, &(r_u->num_entries2)); + prs_uint32("ptr_entries2", ps, depth, &(r_u->ptr_entries2)); + prs_uint32("num_entries3", ps, depth, &(r_u->num_entries3)); -#undef OLD_NTDOMAIN + if (UNMARSHALLING(ps)) + { + r_u->sam = (SAM_ENTRY*) malloc(sizeof(SAM_ENTRY)* + r_u->num_entries2); + r_u->uni_dom_name = (UNISTR2*) malloc(sizeof(UNISTR2)* + r_u->num_entries2); + } + if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) + && r_u->num_entries2 != 0) + { + DEBUG(0, ("NULL pointers in SAMR_R_ENUM_DOMAINS\n")); + r_u->num_entries4 = 0; + r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED; + return False; + } + + for (i = 0; i < r_u->num_entries2; i++) + { + fstring tmp; + slprintf(tmp, sizeof(tmp) - 1, "domains[%d]", i); + sam_io_sam_entry(tmp, &(r_u->sam[i]), ps, depth); + } + + for (i = 0; i < r_u->num_entries2; i++) + { + fstring tmp; + slprintf(tmp, sizeof(tmp) - 1, "domains[%d]", i); + smb_io_unistr2(tmp, &(r_u->uni_dom_name[i]), + r_u->sam[i].hdr_name.buffer, ps, + depth); + prs_align(ps); + } + + prs_align(ps); + + } + + prs_uint32("num_entries4", ps, depth, &(r_u->num_entries4)); + prs_uint32("status", ps, depth, &(r_u->status)); + + return True; +} + +#undef OLD_NTDOMAIN diff --git a/source3/rpc_server/srv_samr.c b/source3/rpc_server/srv_samr.c index d09ae2ad01..9ad1d34561 100644 --- a/source3/rpc_server/srv_samr.c +++ b/source3/rpc_server/srv_samr.c @@ -1,5 +1,4 @@ #define OLD_NTDOMAIN 1 - /* * Unix SMB/Netbios implementation. * Version 1.9. @@ -332,7 +331,7 @@ static BOOL get_passwd_entries(SAM_USER_INFO_21 *pw_buf, /******************************************************************* samr_reply_unknown_1 ********************************************************************/ -static void samr_reply_close_hnd(SAMR_Q_CLOSE_HND *q_u, +static BOOL samr_reply_close_hnd(SAMR_Q_CLOSE_HND *q_u, prs_struct *rdata) { SAMR_R_CLOSE_HND r_u; @@ -353,10 +352,12 @@ static void samr_reply_close_hnd(SAMR_Q_CLOSE_HND *q_u, DEBUG(5,("samr_reply_close_hnd: %d\n", __LINE__)); /* store the response in the SMB stream */ - samr_io_r_close_hnd("", &r_u, rdata, 0); + if(!samr_io_r_close_hnd("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_reply_close_hnd: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -367,10 +368,12 @@ static BOOL api_samr_close_hnd(prs_struct *data, prs_struct *rdata) SAMR_Q_CLOSE_HND q_u; /* grab the samr unknown 1 */ - samr_io_q_close_hnd("", &q_u, data, 0); + if(!samr_io_q_close_hnd("", &q_u, data, 0)) + return False; /* construct reply. always indicate success */ - samr_reply_close_hnd(&q_u, rdata); + if(!samr_reply_close_hnd(&q_u, rdata)) + return False; return True; } @@ -379,7 +382,7 @@ static BOOL api_samr_close_hnd(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_open_domain ********************************************************************/ -static void samr_reply_open_domain(SAMR_Q_OPEN_DOMAIN *q_u, +static BOOL samr_reply_open_domain(SAMR_Q_OPEN_DOMAIN *q_u, prs_struct *rdata) { SAMR_R_OPEN_DOMAIN r_u; @@ -414,10 +417,12 @@ static void samr_reply_open_domain(SAMR_Q_OPEN_DOMAIN *q_u, DEBUG(5,("samr_open_domain: %d\n", __LINE__)); /* store the response in the SMB stream */ - samr_io_r_open_domain("", &r_u, rdata, 0); + if(!samr_io_r_open_domain("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_open_domain: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -428,10 +433,12 @@ static BOOL api_samr_open_domain(prs_struct *data, prs_struct *rdata) SAMR_Q_OPEN_DOMAIN q_u; /* grab the samr open */ - samr_io_q_open_domain("", &q_u, data, 0); + if(!samr_io_q_open_domain("", &q_u, data, 0)) + return False; /* construct reply. always indicate success */ - samr_reply_open_domain(&q_u, rdata); + if(!samr_reply_open_domain(&q_u, rdata)) + return False; return True; } @@ -440,7 +447,7 @@ static BOOL api_samr_open_domain(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_unknown_2c ********************************************************************/ -static void samr_reply_unknown_2c(SAMR_Q_UNKNOWN_2C *q_u, +static BOOL samr_reply_unknown_2c(SAMR_Q_UNKNOWN_2C *q_u, prs_struct *rdata) { SAMR_R_UNKNOWN_2C r_u; @@ -463,10 +470,12 @@ static void samr_reply_unknown_2c(SAMR_Q_UNKNOWN_2C *q_u, DEBUG(5,("samr_unknown_2c: %d\n", __LINE__)); /* store the response in the SMB stream */ - samr_io_r_unknown_2c("", &r_u, rdata, 0); + if(!samr_io_r_unknown_2c("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_unknown_2c: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -477,10 +486,12 @@ static BOOL api_samr_unknown_2c(prs_struct *data, prs_struct *rdata) SAMR_Q_UNKNOWN_2C q_u; /* grab the samr open */ - samr_io_q_unknown_2c("", &q_u, data, 0); + if(!samr_io_q_unknown_2c("", &q_u, data, 0)) + return False; /* construct reply. always indicate success */ - samr_reply_unknown_2c(&q_u, rdata); + if(!samr_reply_unknown_2c(&q_u, rdata)) + return False; return True; } @@ -489,7 +500,7 @@ static BOOL api_samr_unknown_2c(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_unknown_3 ********************************************************************/ -static void samr_reply_unknown_3(SAMR_Q_UNKNOWN_3 *q_u, +static BOOL samr_reply_unknown_3(SAMR_Q_UNKNOWN_3 *q_u, prs_struct *rdata) { SAMR_R_UNKNOWN_3 r_u; @@ -541,10 +552,12 @@ static void samr_reply_unknown_3(SAMR_Q_UNKNOWN_3 *q_u, DEBUG(5,("samr_unknown_3: %d\n", __LINE__)); /* store the response in the SMB stream */ - samr_io_r_unknown_3("", &r_u, rdata, 0); + if(!samr_io_r_unknown_3("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_unknown_3: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -555,10 +568,12 @@ static BOOL api_samr_unknown_3(prs_struct *data, prs_struct *rdata) SAMR_Q_UNKNOWN_3 q_u; /* grab the samr open */ - samr_io_q_unknown_3("", &q_u, data, 0); + if(!samr_io_q_unknown_3("", &q_u, data, 0)) + return False; /* construct reply. always indicate success */ - samr_reply_unknown_3(&q_u, rdata); + if(!samr_reply_unknown_3(&q_u, rdata)) + return False; return True; } @@ -567,7 +582,7 @@ static BOOL api_samr_unknown_3(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_enum_dom_users ********************************************************************/ -static void samr_reply_enum_dom_users(SAMR_Q_ENUM_DOM_USERS *q_u, +static BOOL samr_reply_enum_dom_users(SAMR_Q_ENUM_DOM_USERS *q_u, prs_struct *rdata) { SAMR_R_ENUM_DOM_USERS r_e; @@ -595,10 +610,12 @@ static void samr_reply_enum_dom_users(SAMR_Q_ENUM_DOM_USERS *q_u, pass, r_e.status); /* store the response in the SMB stream */ - samr_io_r_enum_dom_users("", &r_e, rdata, 0); + if(!samr_io_r_enum_dom_users("", &r_e, rdata, 0)) + return False; DEBUG(5,("samr_enum_dom_users: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -609,19 +626,20 @@ static BOOL api_samr_enum_dom_users(prs_struct *data, prs_struct *rdata) SAMR_Q_ENUM_DOM_USERS q_e; /* grab the samr open */ - samr_io_q_enum_dom_users("", &q_e, data, 0); + if(!samr_io_q_enum_dom_users("", &q_e, data, 0)) + return False; /* construct reply. */ - samr_reply_enum_dom_users(&q_e, rdata); + if(!samr_reply_enum_dom_users(&q_e, rdata)) + return False; return True; } - /******************************************************************* samr_reply_enum_dom_groups ********************************************************************/ -static void samr_reply_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_u, +static BOOL samr_reply_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_u, prs_struct *rdata) { SAMR_R_ENUM_DOM_GROUPS r_e; @@ -652,10 +670,12 @@ static void samr_reply_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_u, } /* store the response in the SMB stream */ - samr_io_r_enum_dom_groups("", &r_e, rdata, 0); + if(!samr_io_r_enum_dom_groups("", &r_e, rdata, 0)) + return False; DEBUG(5,("samr_enum_dom_groups: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -666,10 +686,12 @@ static BOOL api_samr_enum_dom_groups(prs_struct *data, prs_struct *rdata) SAMR_Q_ENUM_DOM_GROUPS q_e; /* grab the samr open */ - samr_io_q_enum_dom_groups("", &q_e, data, 0); + if(!samr_io_q_enum_dom_groups("", &q_e, data, 0)) + return False; /* construct reply. */ - samr_reply_enum_dom_groups(&q_e, rdata); + if(!samr_reply_enum_dom_groups(&q_e, rdata)) + return False; return True; } @@ -677,7 +699,7 @@ static BOOL api_samr_enum_dom_groups(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_enum_dom_aliases ********************************************************************/ -static void samr_reply_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_u, +static BOOL samr_reply_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_u, prs_struct *rdata) { SAMR_R_ENUM_DOM_ALIASES r_e; @@ -736,10 +758,12 @@ static void samr_reply_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_u, init_samr_r_enum_dom_aliases(&r_e, num_entries, pass, r_e.status); /* store the response in the SMB stream */ - samr_io_r_enum_dom_aliases("", &r_e, rdata, 0); + if(!samr_io_r_enum_dom_aliases("", &r_e, rdata, 0)) + return False; DEBUG(5,("samr_enum_dom_aliases: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -750,10 +774,12 @@ static BOOL api_samr_enum_dom_aliases(prs_struct *data, prs_struct *rdata) SAMR_Q_ENUM_DOM_ALIASES q_e; /* grab the samr open */ - samr_io_q_enum_dom_aliases("", &q_e, data, 0); + if(!samr_io_q_enum_dom_aliases("", &q_e, data, 0)) + return False; /* construct reply. */ - samr_reply_enum_dom_aliases(&q_e, rdata); + if(!samr_reply_enum_dom_aliases(&q_e, rdata)) + return False; return True; } @@ -762,7 +788,7 @@ static BOOL api_samr_enum_dom_aliases(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_query_dispinfo ********************************************************************/ -static void samr_reply_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_u, +static BOOL samr_reply_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_u, prs_struct *rdata) { SAMR_R_QUERY_DISPINFO r_e; @@ -790,10 +816,36 @@ static void samr_reply_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_u, if (r_e.status == 0x0) { + /* decide how many entries to get depending on the max_entries + and max_size passed by client */ + uint32 retsize; + + if(q_u->max_entries > MAX_SAM_ENTRIES) + q_u->max_entries = MAX_SAM_ENTRIES; + + retsize = (q_u->max_entries * (sizeof(SAM_ENTRY1)+sizeof(SAM_STR1))) + + 3*sizeof(uint32); + + if(retsize > q_u->max_size) + { + /* determine max_entries based on max_size */ + q_u->max_entries = (q_u->max_size - 3*sizeof(uint32)) / + (sizeof(SAM_ENTRY1)+sizeof(SAM_STR1)); + q_u->max_entries = (q_u->max_entries>0?q_u->max_entries:1); + } + + DEBUG(10,("samr_reply_query_dispinfo: Setting q_u->max_entries to %u\n",q_u->max_entries)); + become_root(True); - got_pwds = get_passwd_entries(pass, q_u->start_idx, &total_entries, &num_entries, MAX_SAM_ENTRIES, 0); + got_pwds = get_passwd_entries(pass, q_u->start_idx, &total_entries, &num_entries, q_u->max_entries, 0); unbecome_root(True); + /* more left - set resume handle */ + if(total_entries > num_entries) + { + r_e.status = 0x105; + } + switch (q_u->switch_level) { case 0x1: @@ -822,16 +874,24 @@ static void samr_reply_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_u, } } - if (r_e.status == 0) + /* more left - set resume handle */ + if(total_entries > num_entries) + { + r_e.status = 0x105; + } + + if (r_e.status == 0 || r_e.status == 0x105) { - init_samr_r_query_dispinfo(&r_e, switch_level, &ctr, r_e.status); + init_samr_r_query_dispinfo(&r_e, switch_level, &ctr, r_e.status); } /* store the response in the SMB stream */ - samr_io_r_query_dispinfo("", &r_e, rdata, 0); + if(!samr_io_r_query_dispinfo("", &r_e, rdata, 0)) + return False; DEBUG(5,("samr_query_dispinfo: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -842,10 +902,12 @@ static BOOL api_samr_query_dispinfo(prs_struct *data, prs_struct *rdata) SAMR_Q_QUERY_DISPINFO q_e; /* grab the samr open */ - samr_io_q_query_dispinfo("", &q_e, data, 0); + if(!samr_io_q_query_dispinfo("", &q_e, data, 0)) + return False; /* construct reply. */ - samr_reply_query_dispinfo(&q_e, rdata); + if(!samr_reply_query_dispinfo(&q_e, rdata)) + return False; return True; } @@ -854,39 +916,43 @@ static BOOL api_samr_query_dispinfo(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_query_aliasinfo ********************************************************************/ -static void samr_reply_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_u, +static BOOL samr_reply_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_u, prs_struct *rdata) { - SAMR_R_QUERY_ALIASINFO r_e; - - r_e.status = 0x0; - r_e.ptr = 0; - - /* find the policy handle. open a policy on it. */ - if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1)) - { - r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE; - } + SAMR_R_QUERY_ALIASINFO r_e; + fstring alias_desc = "Local Unix group"; + fstring alias=""; + uint8 type; + uint32 alias_rid; - DEBUG(5,("samr_reply_query_aliasinfo: %d\n", __LINE__)); + ZERO_STRUCT(r_e); - if (r_e.status == 0x0) - { - if (q_u->switch_level != 3) - { - r_e.status = NT_STATUS_INVALID_INFO_CLASS; - } - } + DEBUG(5,("samr_reply_query_aliasinfo: %d\n", __LINE__)); - init_samr_r_query_aliasinfo(&r_e, q_u->switch_level, - "local UNIX group", - r_e.status); + /* find the policy handle. open a policy on it. */ + if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1)) + { + r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE; + } - /* store the response in the SMB stream */ - samr_io_r_query_aliasinfo("", &r_e, rdata, 0); + alias_rid = get_lsa_policy_samr_rid(&q_u->pol); + if(alias_rid == 0xffffffff) + r_e.status = 0xC0000000 | NT_STATUS_NO_SUCH_ALIAS; - DEBUG(5,("samr_query_aliasinfo: %d\n", __LINE__)); + if(!lookup_local_rid(alias_rid, alias, &type)) + { + r_e.status = 0xC0000000 | NT_STATUS_NO_SUCH_ALIAS; + } + + init_samr_r_query_aliasinfo(&r_e, q_u->switch_level, alias, alias_desc); + + /* store the response in the SMB stream */ + if(!samr_io_r_query_aliasinfo("", &r_e, rdata, 0)) + return False; + + DEBUG(5,("samr_query_aliasinfo: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -897,10 +963,12 @@ static BOOL api_samr_query_aliasinfo(prs_struct *data, prs_struct *rdata) SAMR_Q_QUERY_ALIASINFO q_e; /* grab the samr open */ - samr_io_q_query_aliasinfo("", &q_e, data, 0); + if(!samr_io_q_query_aliasinfo("", &q_e, data, 0)) + return False; /* construct reply. */ - samr_reply_query_aliasinfo(&q_e, rdata); + if(!samr_reply_query_aliasinfo(&q_e, rdata)) + return False; return True; } @@ -909,7 +977,7 @@ static BOOL api_samr_query_aliasinfo(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_lookup_ids ********************************************************************/ -static void samr_reply_lookup_ids(SAMR_Q_LOOKUP_IDS *q_u, +static BOOL samr_reply_lookup_ids(SAMR_Q_LOOKUP_IDS *q_u, prs_struct *rdata) { uint32 rid[MAX_SAM_ENTRIES]; @@ -962,10 +1030,12 @@ static void samr_reply_lookup_ids(SAMR_Q_LOOKUP_IDS *q_u, init_samr_r_lookup_ids(&r_u, num_rids, rid, status); /* store the response in the SMB stream */ - samr_io_r_lookup_ids("", &r_u, rdata, 0); + if(!samr_io_r_lookup_ids("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_lookup_ids: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -976,10 +1046,12 @@ static BOOL api_samr_lookup_ids(prs_struct *data, prs_struct *rdata) SAMR_Q_LOOKUP_IDS q_u; /* grab the samr 0x10 */ - samr_io_q_lookup_ids("", &q_u, data, 0); + if(!samr_io_q_lookup_ids("", &q_u, data, 0)) + return False; /* construct reply. always indicate success */ - samr_reply_lookup_ids(&q_u, rdata); + if(!samr_reply_lookup_ids(&q_u, rdata)) + return False; return True; } @@ -989,71 +1061,73 @@ static BOOL api_samr_lookup_ids(prs_struct *data, prs_struct *rdata) ********************************************************************/ static BOOL samr_reply_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u, - prs_struct *rdata) + prs_struct *rdata) { - uint32 rid[MAX_SAM_ENTRIES]; - uint8 type[MAX_SAM_ENTRIES]; - uint32 status = 0; - int i; - int num_rids = q_u->num_names1; - DOM_SID pol_sid; - - SAMR_R_LOOKUP_NAMES r_u; - - DEBUG(5,("samr_lookup_names: %d\n", __LINE__)); - - ZERO_ARRAY(rid); - ZERO_ARRAY(type); - - if (!get_lsa_policy_samr_sid(&q_u->pol, &pol_sid)) { - status = 0xC0000000 | NT_STATUS_OBJECT_TYPE_MISMATCH; - init_samr_r_lookup_names(&r_u, 0, rid, type, status); - if(!samr_io_r_lookup_names("", &r_u, rdata, 0)) { - DEBUG(0,("samr_reply_lookup_names: failed to marshall SAMR_R_LOOKUP_NAMES.\n")); - return False; - } - return True; + uint32 rid[MAX_SAM_ENTRIES]; + uint8 type[MAX_SAM_ENTRIES]; + uint32 status = 0; + int i; + int num_rids = q_u->num_names1; + DOM_SID pol_sid; + + SAMR_R_LOOKUP_NAMES r_u; + + DEBUG(5,("samr_lookup_names: %d\n", __LINE__)); + + ZERO_ARRAY(rid); + ZERO_ARRAY(type); + + if (!get_lsa_policy_samr_sid(&q_u->pol, &pol_sid)) { + status = 0xC0000000 | NT_STATUS_OBJECT_TYPE_MISMATCH; + init_samr_r_lookup_names(&r_u, 0, rid, type, status); + if(!samr_io_r_lookup_names("", &r_u, rdata, 0)) { + DEBUG(0,("samr_reply_lookup_names: failed to marshall SAMR_R_LOOKUP_NAMES.\n")); + return False; } + return True; + } - if (num_rids > MAX_SAM_ENTRIES) { - num_rids = MAX_SAM_ENTRIES; - DEBUG(5,("samr_lookup_names: truncating entries to %d\n", num_rids)); - } - - SMB_ASSERT_ARRAY(q_u->uni_name, num_rids); + if (num_rids > MAX_SAM_ENTRIES) { + num_rids = MAX_SAM_ENTRIES; + DEBUG(5,("samr_lookup_names: truncating entries to %d\n", num_rids)); + } - for (i = 0; i < num_rids; i++) { - fstring name; + SMB_ASSERT_ARRAY(q_u->uni_name, num_rids); - status = 0xC0000000 | NT_STATUS_NONE_MAPPED; + for (i = 0; i < num_rids; i++) { + fstring name; - rid [i] = 0xffffffff; - type[i] = SID_NAME_UNKNOWN; + status = 0xC0000000 | NT_STATUS_NONE_MAPPED; - fstrcpy(name, dos_unistrn2(q_u->uni_name[i].buffer, - q_u->uni_name[i].uni_str_len)); + rid [i] = 0xffffffff; + type[i] = SID_NAME_UNKNOWN; - if(sid_equal(&pol_sid, &global_sam_sid)) { - DOM_SID sid; + fstrcpy(name, dos_unistrn2(q_u->uni_name[i].buffer, + q_u->uni_name[i].uni_str_len)); - if(lookup_local_name(global_myname, name, &sid, &type[i])) { - sid_split_rid( &sid, &rid[i]); - status = 0; - } - } + if(sid_equal(&pol_sid, &global_sam_sid)) + { + DOM_SID sid; + if(lookup_local_name(global_myname, name, + &sid, &type[i])) + { + sid_split_rid( &sid, &rid[i]); + status = 0; } + } + } - init_samr_r_lookup_names(&r_u, num_rids, rid, type, status); + init_samr_r_lookup_names(&r_u, num_rids, rid, type, status); - /* store the response in the SMB stream */ - if(!samr_io_r_lookup_names("", &r_u, rdata, 0)) { - DEBUG(0,("samr_reply_lookup_names: failed to marshall SAMR_R_LOOKUP_NAMES.\n")); - return False; - } + /* store the response in the SMB stream */ + if(!samr_io_r_lookup_names("", &r_u, rdata, 0)) { + DEBUG(0,("samr_reply_lookup_names: failed to marshall SAMR_R_LOOKUP_NAMES.\n")); + return False; + } - DEBUG(5,("samr_lookup_names: %d\n", __LINE__)); + DEBUG(5,("samr_lookup_names: %d\n", __LINE__)); - return True; + return True; } /******************************************************************* @@ -1142,8 +1216,7 @@ static BOOL api_samr_chgpasswd_user(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_unknown_38 ********************************************************************/ -static void samr_reply_unknown_38(SAMR_Q_UNKNOWN_38 *q_u, - prs_struct *rdata) +static BOOL samr_reply_unknown_38(SAMR_Q_UNKNOWN_38 *q_u, prs_struct *rdata) { SAMR_R_UNKNOWN_38 r_u; @@ -1152,9 +1225,11 @@ static void samr_reply_unknown_38(SAMR_Q_UNKNOWN_38 *q_u, init_samr_r_unknown_38(&r_u); /* store the response in the SMB stream */ - samr_io_r_unknown_38("", &r_u, rdata, 0); + if(!samr_io_r_unknown_38("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_unknown_38: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -1165,10 +1240,12 @@ static BOOL api_samr_unknown_38(prs_struct *data, prs_struct *rdata) SAMR_Q_UNKNOWN_38 q_u; /* unknown 38 command */ - samr_io_q_unknown_38("", &q_u, data, 0); + if(!samr_io_q_unknown_38("", &q_u, data, 0)) + return False; /* construct reply. always indicate success */ - samr_reply_unknown_38(&q_u, rdata); + if(!samr_reply_unknown_38(&q_u, rdata)) + return False; return True; } @@ -1177,7 +1254,7 @@ static BOOL api_samr_unknown_38(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_unknown_12 ********************************************************************/ -static void samr_reply_unknown_12(SAMR_Q_UNKNOWN_12 *q_u, +static BOOL samr_reply_unknown_12(SAMR_Q_UNKNOWN_12 *q_u, prs_struct *rdata) { fstring group_names[MAX_SAM_ENTRIES]; @@ -1214,10 +1291,12 @@ static void samr_reply_unknown_12(SAMR_Q_UNKNOWN_12 *q_u, init_samr_r_unknown_12(&r_u, num_gids, group_names, group_attrs, status); /* store the response in the SMB stream */ - samr_io_r_unknown_12("", &r_u, rdata, 0); + if(!samr_io_r_unknown_12("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_unknown_12: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -1228,10 +1307,12 @@ static BOOL api_samr_unknown_12(prs_struct *data, prs_struct *rdata) SAMR_Q_UNKNOWN_12 q_u; /* grab the samr lookup names */ - samr_io_q_unknown_12("", &q_u, data, 0); + if(!samr_io_q_unknown_12("", &q_u, data, 0)) + return False; /* construct reply. always indicate success */ - samr_reply_unknown_12(&q_u, rdata); + if(!samr_reply_unknown_12(&q_u, rdata)) + return False; return True; } @@ -1240,9 +1321,7 @@ static BOOL api_samr_unknown_12(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_open_user ********************************************************************/ -static void samr_reply_open_user(SAMR_Q_OPEN_USER *q_u, - prs_struct *rdata, - int status) +static BOOL samr_reply_open_user(SAMR_Q_OPEN_USER *q_u, prs_struct *rdata, int status) { SAMR_R_OPEN_USER r_u; struct sam_passwd *sam_pass; @@ -1290,10 +1369,12 @@ static void samr_reply_open_user(SAMR_Q_OPEN_USER *q_u, DEBUG(5,("samr_open_user: %d\n", __LINE__)); /* store the response in the SMB stream */ - samr_io_r_open_user("", &r_u, rdata, 0); + if(!samr_io_r_open_user("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_open_user: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -1304,10 +1385,12 @@ static BOOL api_samr_open_user(prs_struct *data, prs_struct *rdata) SAMR_Q_OPEN_USER q_u; /* grab the samr unknown 22 */ - samr_io_q_open_user("", &q_u, data, 0); + if(!samr_io_q_open_user("", &q_u, data, 0)) + return False; /* construct reply. always indicate success */ - samr_reply_open_user(&q_u, rdata, 0x0); + if(!samr_reply_open_user(&q_u, rdata, 0x0)) + return False; return True; } @@ -1420,7 +1503,7 @@ static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 user_rid) /******************************************************************* samr_reply_query_userinfo ********************************************************************/ -static void samr_reply_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u, +static BOOL samr_reply_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u, prs_struct *rdata) { SAMR_R_QUERY_USERINFO r_u; @@ -1495,10 +1578,12 @@ static void samr_reply_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u, init_samr_r_query_userinfo(&r_u, q_u->switch_value, info, status); /* store the response in the SMB stream */ - samr_io_r_query_userinfo("", &r_u, rdata, 0); + if(!samr_io_r_query_userinfo("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -1509,10 +1594,12 @@ static BOOL api_samr_query_userinfo(prs_struct *data, prs_struct *rdata) SAMR_Q_QUERY_USERINFO q_u; /* grab the samr unknown 24 */ - samr_io_q_query_userinfo("", &q_u, data, 0); + if(!samr_io_q_query_userinfo("", &q_u, data, 0)) + return False; /* construct reply. always indicate success */ - samr_reply_query_userinfo(&q_u, rdata); + if(!samr_reply_query_userinfo(&q_u, rdata)) + return False; return True; } @@ -1521,7 +1608,7 @@ static BOOL api_samr_query_userinfo(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_query_usergroups ********************************************************************/ -static void samr_reply_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u, +static BOOL samr_reply_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u, prs_struct *rdata) { SAMR_R_QUERY_USERGROUPS r_u; @@ -1570,15 +1657,18 @@ static void samr_reply_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u, init_samr_r_query_usergroups(&r_u, num_groups, gids, status); /* store the response in the SMB stream */ - samr_io_r_query_usergroups("", &r_u, rdata, 0); + if(!samr_io_r_query_usergroups("", &r_u, rdata, 0)) { + if (gids) + free((char *)gids); + return False; + } if (gids) - { free((char *)gids); - } DEBUG(5,("samr_query_usergroups: %d\n", __LINE__)); - + + return True; } /******************************************************************* @@ -1588,10 +1678,12 @@ static BOOL api_samr_query_usergroups(prs_struct *data, prs_struct *rdata) { SAMR_Q_QUERY_USERGROUPS q_u; /* grab the samr unknown 32 */ - samr_io_q_query_usergroups("", &q_u, data, 0); + if(!samr_io_q_query_usergroups("", &q_u, data, 0)) + return False; /* construct reply. */ - samr_reply_query_usergroups(&q_u, rdata); + if(!samr_reply_query_usergroups(&q_u, rdata)) + return False; return True; } @@ -1600,8 +1692,7 @@ static BOOL api_samr_query_usergroups(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_query_dom_info ********************************************************************/ -static void samr_reply_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO *q_u, - prs_struct *rdata) +static BOOL samr_reply_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO *q_u, prs_struct *rdata) { SAMR_R_QUERY_DOMAIN_INFO r_u; SAM_UNK_CTR ctr; @@ -1644,10 +1735,12 @@ static void samr_reply_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO *q_u, init_samr_r_query_dom_info(&r_u, switch_value, &ctr, status); /* store the response in the SMB stream */ - samr_io_r_query_dom_info("", &r_u, rdata, 0); + if(!samr_io_r_query_dom_info("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_query_dom_info: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -1658,20 +1751,20 @@ static BOOL api_samr_query_dom_info(prs_struct *data, prs_struct *rdata) SAMR_Q_QUERY_DOMAIN_INFO q_e; /* grab the samr unknown 8 command */ - samr_io_q_query_dom_info("", &q_e, data, 0); + if(!samr_io_q_query_dom_info("", &q_e, data, 0)) + return False; /* construct reply. */ - samr_reply_query_dom_info(&q_e, rdata); + if(!samr_reply_query_dom_info(&q_e, rdata)) + return False; return True; } - - /******************************************************************* samr_reply_unknown_32 ********************************************************************/ -static void samr_reply_unknown_32(SAMR_Q_UNKNOWN_32 *q_u, +static BOOL samr_reply_unknown_32(SAMR_Q_UNKNOWN_32 *q_u, prs_struct *rdata, int status) { @@ -1694,10 +1787,12 @@ static void samr_reply_unknown_32(SAMR_Q_UNKNOWN_32 *q_u, DEBUG(5,("samr_unknown_32: %d\n", __LINE__)); /* store the response in the SMB stream */ - samr_io_r_unknown_32("", &r_u, rdata, 0); + if(!samr_io_r_unknown_32("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_unknown_32: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -1740,7 +1835,8 @@ static BOOL api_samr_unknown_32(prs_struct *data, prs_struct *rdata) } /* construct reply. */ - samr_reply_unknown_32(&q_u, rdata, status); + if(!samr_reply_unknown_32(&q_u, rdata, status)) + return False; return True; } @@ -1749,8 +1845,7 @@ static BOOL api_samr_unknown_32(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_connect_anon ********************************************************************/ -static void samr_reply_connect_anon(SAMR_Q_CONNECT_ANON *q_u, - prs_struct *rdata) +static BOOL samr_reply_connect_anon(SAMR_Q_CONNECT_ANON *q_u, prs_struct *rdata) { SAMR_R_CONNECT_ANON r_u; BOOL pol_open = False; @@ -1779,10 +1874,12 @@ static void samr_reply_connect_anon(SAMR_Q_CONNECT_ANON *q_u, DEBUG(5,("samr_connect_anon: %d\n", __LINE__)); /* store the response in the SMB stream */ - samr_io_r_connect_anon("", &r_u, rdata, 0); + if(!samr_io_r_connect_anon("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_connect_anon: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -1793,10 +1890,12 @@ static BOOL api_samr_connect_anon(prs_struct *data, prs_struct *rdata) SAMR_Q_CONNECT_ANON q_u; /* grab the samr open policy */ - samr_io_q_connect_anon("", &q_u, data, 0); + if(!samr_io_q_connect_anon("", &q_u, data, 0)) + return False; /* construct reply. always indicate success */ - samr_reply_connect_anon(&q_u, rdata); + if(!samr_reply_connect_anon(&q_u, rdata)) + return False; return True; } @@ -1804,8 +1903,7 @@ static BOOL api_samr_connect_anon(prs_struct *data, prs_struct *rdata) /******************************************************************* samr_reply_connect ********************************************************************/ -static void samr_reply_connect(SAMR_Q_CONNECT *q_u, - prs_struct *rdata) +static BOOL samr_reply_connect(SAMR_Q_CONNECT *q_u, prs_struct *rdata) { SAMR_R_CONNECT r_u; BOOL pol_open = False; @@ -1834,10 +1932,12 @@ static void samr_reply_connect(SAMR_Q_CONNECT *q_u, DEBUG(5,("samr_connect: %d\n", __LINE__)); /* store the response in the SMB stream */ - samr_io_r_connect("", &r_u, rdata, 0); + if(!samr_io_r_connect("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_connect: %d\n", __LINE__)); + return True; } /******************************************************************* @@ -1848,19 +1948,103 @@ static BOOL api_samr_connect(prs_struct *data, prs_struct *rdata) SAMR_Q_CONNECT q_u; /* grab the samr open policy */ - samr_io_q_connect("", &q_u, data, 0); + if(!samr_io_q_connect("", &q_u, data, 0)) + return False; /* construct reply. always indicate success */ - samr_reply_connect(&q_u, rdata); + if(!samr_reply_connect(&q_u, rdata)) + return False; + + return True; +} + +/********************************************************************** + api_reply_lookup_domain + **********************************************************************/ +static BOOL samr_reply_lookup_domain(SAMR_Q_LOOKUP_DOMAIN* q_u, prs_struct* rdata) +{ + SAMR_R_LOOKUP_DOMAIN r_u; + + r_u.status = 0x0; + if (r_u.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->connect_pol)) == -1)) + { + r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE; + DEBUG(5,("samr_reply_lookup_domain: invalid handle\n")); + } + + /* assume the domain name sent is our global_myname and + send global_sam_sid */ + init_samr_r_lookup_domain(&r_u, &global_sam_sid, r_u.status); + + if(!samr_io_r_lookup_domain("", &r_u, rdata, 0)) + return False; + + DEBUG(5,("samr_reply_lookup_domain: %d\n", __LINE__)); + + return True; +} + +/********************************************************************** + api_samr_lookup_domain + **********************************************************************/ +static BOOL api_samr_lookup_domain(prs_struct* data, prs_struct* rdata) +{ + SAMR_Q_LOOKUP_DOMAIN q_u; + + if(!samr_io_q_lookup_domain("", &q_u, data, 0)) + return False; + + if(!samr_reply_lookup_domain(&q_u, rdata)) + return False; + + return True; +} + +/********************************************************************** + samr_reply_enum_domains + **********************************************************************/ +static BOOL samr_reply_enum_domains(SAMR_Q_ENUM_DOMAINS* q_u, prs_struct* rdata) +{ + SAMR_R_ENUM_DOMAINS r_u; + fstring dom[2]; + + fstrcpy(dom[0],global_myname); + fstrcpy(dom[1],"Builtin"); + r_u.status = 0; + + init_samr_r_enum_domains(&r_u, q_u->start_idx, dom, 2); + if(!samr_io_r_enum_domains("", &r_u, rdata, 0)) { + free(r_u.sam); + free(r_u.uni_dom_name); + return False; + } + + free(r_u.sam); + free(r_u.uni_dom_name); return True; } +/********************************************************************** + api_samr_enum_domains + **********************************************************************/ +static BOOL api_samr_enum_domains(prs_struct* data, prs_struct* rdata) +{ + SAMR_Q_ENUM_DOMAINS q_u; + + if(!samr_io_q_enum_domains("", &q_u, data, 0)) + return False; + + if(!samr_reply_enum_domains(&q_u, rdata)) + return False; + + return True; +} + /******************************************************************* samr_reply_open_alias ********************************************************************/ -static void samr_reply_open_alias(SAMR_Q_OPEN_ALIAS *q_u, - prs_struct *rdata) +static BOOL samr_reply_open_alias(SAMR_Q_OPEN_ALIAS *q_u, prs_struct *rdata) { SAMR_R_OPEN_ALIAS r_u; BOOL pol_open = False; @@ -1889,10 +2073,12 @@ static void samr_reply_open_alias(SAMR_Q_OPEN_ALIAS *q_u, DEBUG(5,("samr_open_alias: %d\n", __LINE__)); /* store the response in the SMB stream */ - samr_io_r_open_alias("", &r_u, rdata, 0); + if(!samr_io_r_open_alias("", &r_u, rdata, 0)) + return False; DEBUG(5,("samr_open_alias: %d\n", __LINE__)); - + + return True; } /******************************************************************* @@ -1904,10 +2090,12 @@ static BOOL api_samr_open_alias(prs_struct *data, prs_struct *rdata) SAMR_Q_OPEN_ALIAS q_u; /* grab the samr open policy */ - samr_io_q_open_alias("", &q_u, data, 0); + if(!samr_io_q_open_alias("", &q_u, data, 0)) + return False; /* construct reply. always indicate success */ - samr_reply_open_alias(&q_u, rdata); + if(!samr_reply_open_alias(&q_u, rdata)) + return False; return True; } @@ -1939,6 +2127,8 @@ static struct api_struct api_samr_cmds [] = { "SAMR_OPEN_DOMAIN" , SAMR_OPEN_DOMAIN , api_samr_open_domain }, { "SAMR_UNKNOWN_3" , SAMR_UNKNOWN_3 , api_samr_unknown_3 }, { "SAMR_UNKNOWN_2C" , SAMR_UNKNOWN_2C , api_samr_unknown_2c }, + { "SAMR_LOOKUP_DOMAIN" , SAMR_LOOKUP_DOMAIN , api_samr_lookup_domain }, + { "SAMR_ENUM_DOMAINS" , SAMR_ENUM_DOMAINS , api_samr_enum_domains }, { NULL , 0 , NULL } }; @@ -1949,6 +2139,4 @@ BOOL api_samr_rpc(pipes_struct *p, prs_struct *data) { return api_rpcTNP(p, "api_samr_rpc", api_samr_cmds, data); } - #undef OLD_NTDOMAIN - |