diff options
Diffstat (limited to 'source/libsmb')
-rw-r--r-- | source/libsmb/cli_lsarpc.c | 23 | ||||
-rw-r--r-- | source/libsmb/cli_netlogon.c | 6 | ||||
-rw-r--r-- | source/libsmb/cli_samr.c | 6 | ||||
-rw-r--r-- | source/libsmb/cliconnect.c | 30 | ||||
-rw-r--r-- | source/libsmb/clifile.c | 32 | ||||
-rw-r--r-- | source/libsmb/clilist.c | 6 | ||||
-rw-r--r-- | source/libsmb/clirap.c | 6 | ||||
-rw-r--r-- | source/libsmb/clitrans.c | 4 | ||||
-rw-r--r-- | source/libsmb/namequery.c | 69 | ||||
-rw-r--r-- | source/libsmb/nmblib.c | 6 | ||||
-rw-r--r-- | source/libsmb/smbencrypt.c | 2 |
11 files changed, 120 insertions, 70 deletions
diff --git a/source/libsmb/cli_lsarpc.c b/source/libsmb/cli_lsarpc.c index 3234c366568..0a0c5323304 100644 --- a/source/libsmb/cli_lsarpc.c +++ b/source/libsmb/cli_lsarpc.c @@ -217,7 +217,10 @@ NTSTATUS cli_lsa_close(struct cli_state *cli, TALLOC_CTX *mem_ctx, return result; } -/** Lookup a list of sids */ +/** Lookup a list of sids */ +/******************************************************************** + Converts SIDs to names. Outgoing names are in UNIX charset. +*********************************************************************/ NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol, int num_sids, DOM_SID *sids, @@ -308,8 +311,8 @@ NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx, if (dom_idx != 0xffffffff) { - unistr2_to_ascii(dom_name, &ref.ref_dom[dom_idx].uni_dom_name, sizeof(dom_name)- 1); - unistr2_to_ascii(name, &t_names.uni_name[i], sizeof(name) - 1); + unistr2_to_unix(dom_name, &ref.ref_dom[dom_idx].uni_dom_name, sizeof(dom_name)- 1); + unistr2_to_unix(name, &t_names.uni_name[i], sizeof(name) - 1); (*names)[i] = talloc_strdup(mem_ctx, name); (*domains)[i] = talloc_strdup(mem_ctx, dom_name); @@ -335,6 +338,9 @@ NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx, } /** Lookup a list of names */ +/******************************************************************** + Converts names to SIDs. Incoming names are in UNIX charset. +*********************************************************************/ NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol, int num_names, @@ -358,6 +364,7 @@ NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Marshall data and send request */ + /* This call converts from UNIX to DOS charset then to unicode. */ init_q_lookup_names(mem_ctx, &q, pol, num_names, names); if (!lsa_io_q_lookup_names("", &q, &qbuf, 0) || @@ -488,7 +495,7 @@ NTSTATUS cli_lsa_query_info_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx, case 3: if (r.dom.id3.buffer_dom_name != 0) { - unistr2_to_ascii(domain_name, + unistr2_to_unix(domain_name, &r.dom.id3. uni_domain_name, sizeof (fstring) - 1); @@ -503,7 +510,7 @@ NTSTATUS cli_lsa_query_info_policy(struct cli_state *cli, TALLOC_CTX *mem_ctx, case 5: if (r.dom.id5.buffer_dom_name != 0) { - unistr2_to_ascii(domain_name, &r.dom.id5. + unistr2_to_unix(domain_name, &r.dom.id5. uni_domain_name, sizeof (fstring) - 1); } @@ -604,7 +611,7 @@ NTSTATUS cli_lsa_enum_trust_dom(struct cli_state *cli, TALLOC_CTX *mem_ctx, for (i = 0; i < r.num_domains; i++) { fstring tmp; - unistr2_to_ascii(tmp, &r.uni_domain_name[i], + unistr2_to_unix(tmp, &r.uni_domain_name[i], sizeof(tmp) - 1); (*domain_names)[i] = talloc_strdup(mem_ctx, tmp); sid_copy(&(*domain_sids)[i], &r.domain_sid[i].sid); @@ -688,7 +695,7 @@ NTSTATUS cli_lsa_enum_privilege(struct cli_state *cli, TALLOC_CTX *mem_ctx, for (i = 0; i < r.count; i++) { fstring name; - unistr2_to_ascii( name, &r.privs[i].name, sizeof(name)-1); + unistr2_to_unix( name, &r.privs[i].name, sizeof(name)-1); (*privs_name)[i] = talloc_strdup(mem_ctx, name); @@ -745,7 +752,7 @@ NTSTATUS cli_lsa_get_dispname(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* Return output parameters */ - unistr2_to_ascii(description ,&r.desc, sizeof(description)-1); + unistr2_to_unix(description ,&r.desc, sizeof(description)-1); *lang_id_desc = r.lang_id; done: diff --git a/source/libsmb/cli_netlogon.c b/source/libsmb/cli_netlogon.c index cb438de9873..560de2192ee 100644 --- a/source/libsmb/cli_netlogon.c +++ b/source/libsmb/cli_netlogon.c @@ -443,7 +443,7 @@ NTSTATUS cli_netlogon_sam_logon(struct cli_state *cli, TALLOC_CTX *mem_ctx, 0, /* param_ctrl */ 0xdead, 0xbeef, /* LUID? */ username, cli->clnt_name_slash, - cli->sess_key, lm_owf_user_pwd, + (char *)cli->sess_key, lm_owf_user_pwd, nt_owf_user_pwd); break; @@ -455,8 +455,8 @@ NTSTATUS cli_netlogon_sam_logon(struct cli_state *cli, TALLOC_CTX *mem_ctx, generate_random_buffer(chal, 8, False); - SMBencrypt(password, chal, local_lm_response); - SMBNTencrypt(password, chal, local_nt_response); + SMBencrypt((const uchar *)password, chal, local_lm_response); + SMBNTencrypt((const uchar *)password, chal, local_nt_response); init_id_info2(&ctr.auth.id2, lp_workgroup(), 0, /* param_ctrl */ diff --git a/source/libsmb/cli_samr.c b/source/libsmb/cli_samr.c index e5ddc8f7bd1..b1231c6cbd2 100644 --- a/source/libsmb/cli_samr.c +++ b/source/libsmb/cli_samr.c @@ -566,7 +566,7 @@ NTSTATUS cli_samr_enum_dom_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx, (*dom_groups)[i].rid = r.sam[i].rid; if (r.sam[i].hdr_name.buffer) { - unistr2_to_ascii((*dom_groups)[i].acct_name, + unistr2_to_unix((*dom_groups)[i].acct_name, &r.uni_grp_name[name_idx], sizeof(fstring) - 1); name_idx++; @@ -644,7 +644,7 @@ NTSTATUS cli_samr_enum_als_groups(struct cli_state *cli, TALLOC_CTX *mem_ctx, (*dom_groups)[i].rid = r.sam[i].rid; if (r.sam[i].hdr_name.buffer) { - unistr2_to_ascii((*dom_groups)[i].acct_name, + unistr2_to_unix((*dom_groups)[i].acct_name, &r.uni_grp_name[name_idx], sizeof(fstring) - 1); name_idx++; @@ -937,7 +937,7 @@ NTSTATUS cli_samr_lookup_rids(struct cli_state *cli, TALLOC_CTX *mem_ctx, for (i = 0; i < r.num_names1; i++) { fstring tmp; - unistr2_to_ascii(tmp, &r.uni_name[i], sizeof(tmp) - 1); + unistr2_to_unix(tmp, &r.uni_name[i], sizeof(tmp) - 1); (*names)[i] = talloc_strdup(mem_ctx, tmp); (*name_types)[i] = r.type[i]; } diff --git a/source/libsmb/cliconnect.c b/source/libsmb/cliconnect.c index 5e1cbeca386..4e81ad99276 100644 --- a/source/libsmb/cliconnect.c +++ b/source/libsmb/cliconnect.c @@ -154,10 +154,10 @@ static BOOL cli_session_setup_guest(struct cli_state *cli) SSVAL(cli->outbuf,smb_vwv8,0); SIVAL(cli->outbuf,smb_vwv11,capabilities); p = smb_buf(cli->outbuf); - p += clistr_push(cli, p, "", -1, STR_TERMINATE); /* username */ - p += clistr_push(cli, p, "", -1, STR_TERMINATE); /* workgroup */ - p += clistr_push(cli, p, "Unix", -1, STR_TERMINATE); - p += clistr_push(cli, p, "Samba", -1, STR_TERMINATE); + p += clistr_push(cli, p, "", -1, STR_TERMINATE|STR_CONVERT); /* username */ + p += clistr_push(cli, p, "", -1, STR_TERMINATE|STR_CONVERT); /* workgroup */ + p += clistr_push(cli, p, "Unix", -1, STR_TERMINATE|STR_CONVERT); + p += clistr_push(cli, p, "Samba", -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); cli_send_smb(cli); @@ -194,7 +194,7 @@ static BOOL cli_session_setup_plaintext(struct cli_state *cli, char *user, int passlen; char *p; - passlen = clistr_push(cli, pword, pass, sizeof(pword), STR_TERMINATE); + passlen = clistr_push(cli, pword, pass, sizeof(pword), STR_TERMINATE|STR_CONVERT); set_message(cli->outbuf,13,0,True); SCVAL(cli->outbuf,smb_com,SMBsesssetupX); @@ -211,10 +211,10 @@ static BOOL cli_session_setup_plaintext(struct cli_state *cli, char *user, p = smb_buf(cli->outbuf); memcpy(p, pword, passlen); p += passlen; - p += clistr_push(cli, p, user, -1, STR_TERMINATE); /* username */ - p += clistr_push(cli, p, workgroup, -1, STR_TERMINATE); /* workgroup */ - p += clistr_push(cli, p, "Unix", -1, STR_TERMINATE); - p += clistr_push(cli, p, "Samba", -1, STR_TERMINATE); + p += clistr_push(cli, p, user, -1, STR_TERMINATE|STR_CONVERT); /* username */ + p += clistr_push(cli, p, workgroup, -1, STR_TERMINATE|STR_CONVERT); /* workgroup */ + p += clistr_push(cli, p, "Unix", -1, STR_TERMINATE|STR_CONVERT); + p += clistr_push(cli, p, "Samba", -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); cli_send_smb(cli); @@ -258,8 +258,8 @@ static BOOL cli_session_setup_nt1(struct cli_state *cli, char *user, /* non encrypted password supplied. */ passlen = 24; ntpasslen = 24; - clistr_push(cli, pword, pass, sizeof(pword), STR_TERMINATE); - clistr_push(cli, ntpword, ntpass, sizeof(ntpword), STR_TERMINATE); + clistr_push(cli, pword, pass, sizeof(pword), STR_TERMINATE|STR_CONVERT); + clistr_push(cli, ntpword, ntpass, sizeof(ntpword), STR_TERMINATE|STR_CONVERT); SMBencrypt((uchar *)pword,cli->cryptkey,(uchar *)pword); SMBNTencrypt((uchar *)ntpword,cli->cryptkey,(uchar *)ntpword); } else { @@ -285,10 +285,10 @@ static BOOL cli_session_setup_nt1(struct cli_state *cli, char *user, p = smb_buf(cli->outbuf); memcpy(p,pword,passlen); p += passlen; memcpy(p,ntpword,ntpasslen); p += ntpasslen; - p += clistr_push(cli, p, user, -1, STR_TERMINATE|STR_UPPER); - p += clistr_push(cli, p, workgroup, -1, STR_TERMINATE|STR_UPPER); - p += clistr_push(cli, p, "Unix", -1, STR_TERMINATE); - p += clistr_push(cli, p, "Samba", -1, STR_TERMINATE); + p += clistr_push(cli, p, user, -1, STR_TERMINATE|STR_UPPER|STR_CONVERT); + p += clistr_push(cli, p, workgroup, -1, STR_TERMINATE|STR_UPPER|STR_CONVERT); + p += clistr_push(cli, p, "Unix", -1, STR_TERMINATE|STR_CONVERT); + p += clistr_push(cli, p, "Samba", -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); cli_send_smb(cli); diff --git a/source/libsmb/clifile.c b/source/libsmb/clifile.c index ed13bf4d812..cce36613b74 100644 --- a/source/libsmb/clifile.c +++ b/source/libsmb/clifile.c @@ -42,11 +42,11 @@ static BOOL cli_link_internal(struct cli_state *cli, const char *fname_src, cons SSVAL(param,0,hard_link ? SMB_SET_FILE_UNIX_HLINK : SMB_SET_FILE_UNIX_LINK); p = ¶m[6]; - p += clistr_push(cli, p, fname_src, -1, STR_TERMINATE); + p += clistr_push(cli, p, fname_src, -1, STR_TERMINATE|STR_CONVERT); param_len = PTR_DIFF(p, param); p = data; - p += clistr_push(cli, p, fname_dst, -1, STR_TERMINATE); + p += clistr_push(cli, p, fname_dst, -1, STR_TERMINATE|STR_CONVERT); data_len = PTR_DIFF(p, data); if (!cli_send_trans(cli, SMBtrans2, @@ -77,7 +77,7 @@ static BOOL cli_link_internal(struct cli_state *cli, const char *fname_src, cons uint32 unix_perms_to_wire(mode_t perms) { - uint ret = 0; + uint32 ret = 0; ret |= ((perms & S_IXOTH) ? UNIX_X_OTH : 0); ret |= ((perms & S_IWOTH) ? UNIX_W_OTH : 0); @@ -95,7 +95,7 @@ uint32 unix_perms_to_wire(mode_t perms) ret |= ((perms & S_ISGID) ? UNIX_SET_GID : 0); #endif #ifdef S_ISUID - ret |= ((perms & S_ISVTX) ? UNIX_SET_UID : 0); + ret |= ((perms & S_ISUID) ? UNIX_SET_UID : 0); #endif return ret; } @@ -137,7 +137,7 @@ static BOOL cli_unix_chmod_chown_internal(struct cli_state *cli, const char *fna SSVAL(param,0,SMB_SET_FILE_UNIX_BASIC); p = ¶m[6]; - p += clistr_push(cli, p, fname, -1, STR_TERMINATE); + p += clistr_push(cli, p, fname, -1, STR_TERMINATE|STR_CONVERT); param_len = PTR_DIFF(p, param); SIVAL(data,40,uid); @@ -208,9 +208,9 @@ BOOL cli_rename(struct cli_state *cli, const char *fname_src, const char *fname_ p = smb_buf(cli->outbuf); *p++ = 4; - p += clistr_push(cli, p, fname_src, -1, STR_TERMINATE); + p += clistr_push(cli, p, fname_src, -1, STR_TERMINATE|STR_CONVERT); *p++ = 4; - p += clistr_push(cli, p, fname_dst, -1, STR_TERMINATE); + p += clistr_push(cli, p, fname_dst, -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); @@ -245,7 +245,7 @@ BOOL cli_unlink(struct cli_state *cli, const char *fname) p = smb_buf(cli->outbuf); *p++ = 4; - p += clistr_push(cli, p, fname, -1, STR_TERMINATE); + p += clistr_push(cli, p, fname, -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); cli_send_smb(cli); @@ -279,7 +279,7 @@ BOOL cli_mkdir(struct cli_state *cli, const char *dname) p = smb_buf(cli->outbuf); *p++ = 4; - p += clistr_push(cli, p, dname, -1, STR_TERMINATE); + p += clistr_push(cli, p, dname, -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); @@ -314,7 +314,7 @@ BOOL cli_rmdir(struct cli_state *cli, const char *dname) p = smb_buf(cli->outbuf); *p++ = 4; - p += clistr_push(cli, p, dname, -1, STR_TERMINATE); + p += clistr_push(cli, p, dname, -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); @@ -412,7 +412,7 @@ int cli_nt_create_full(struct cli_state *cli, const char *fname, uint32 DesiredA p += len; SSVAL(cli->outbuf,smb_ntcreate_NameLength, len); /* sigh. this copes with broken netapp filer behaviour */ - p += clistr_push(cli, p, "", -1, STR_TERMINATE); + p += clistr_push(cli, p, "", -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); @@ -501,7 +501,7 @@ int cli_open(struct cli_state *cli, const char *fname, int flags, int share_mode } p = smb_buf(cli->outbuf); - p += clistr_push(cli, p, fname, -1, STR_TERMINATE); + p += clistr_push(cli, p, fname, -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); @@ -872,7 +872,7 @@ BOOL cli_getatr(struct cli_state *cli, const char *fname, p = smb_buf(cli->outbuf); *p++ = 4; - p += clistr_push(cli, p, fname, -1, STR_TERMINATE); + p += clistr_push(cli, p, fname, -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); @@ -923,7 +923,7 @@ BOOL cli_setatr(struct cli_state *cli, const char *fname, uint16 attr, time_t t) p = smb_buf(cli->outbuf); *p++ = 4; - p += clistr_push(cli, p, fname, -1, STR_TERMINATE); + p += clistr_push(cli, p, fname, -1, STR_TERMINATE|STR_CONVERT); *p++ = 4; cli_setup_bcc(cli, p); @@ -960,7 +960,7 @@ BOOL cli_chkpath(struct cli_state *cli, const char *path) cli_setup_packet(cli); p = smb_buf(cli->outbuf); *p++ = 4; - p += clistr_push(cli, p, path2, -1, STR_TERMINATE); + p += clistr_push(cli, p, path2, -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); @@ -1021,7 +1021,7 @@ int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path) p = smb_buf(cli->outbuf); *p++ = 4; - p += clistr_push(cli, p, path, -1, STR_TERMINATE); + p += clistr_push(cli, p, path, -1, STR_TERMINATE|STR_CONVERT); cli_setup_bcc(cli, p); diff --git a/source/libsmb/clilist.c b/source/libsmb/clilist.c index 0c80044b68f..77ffe7b41b0 100644 --- a/source/libsmb/clilist.c +++ b/source/libsmb/clilist.c @@ -177,7 +177,7 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute, SIVAL(param,8,0); p = param+12; p += clistr_push(cli, param+12, mask, -1, - STR_TERMINATE); + STR_TERMINATE|STR_CONVERT); } else { setup = TRANSACT2_FINDNEXT; SSVAL(param,0,ff_dir_handle); @@ -187,7 +187,7 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute, SSVAL(param,10,8+4+2); /* continue + resume required + close on end */ p = param+12; p += clistr_push(cli, param+12, mask, -1, - STR_TERMINATE); + STR_TERMINATE|STR_CONVERT); } param_len = PTR_DIFF(p, param); @@ -369,7 +369,7 @@ int cli_list_old(struct cli_state *cli,const char *Mask,uint16 attribute, p = smb_buf(cli->outbuf); *p++ = 4; - p += clistr_push(cli, p, first?mask:"", -1, STR_TERMINATE); + p += clistr_push(cli, p, first?mask:"", -1, STR_TERMINATE|STR_CONVERT); *p++ = 5; if (first) { SSVAL(p,0,0); diff --git a/source/libsmb/clirap.c b/source/libsmb/clirap.c index 2f1423aa1a1..e0e5bc0c1f8 100644 --- a/source/libsmb/clirap.c +++ b/source/libsmb/clirap.c @@ -386,7 +386,7 @@ BOOL cli_qpathinfo(struct cli_state *cli, const char *fname, memset(p, 0, 6); SSVAL(p, 0, SMB_INFO_STANDARD); p += 6; - p += clistr_push(cli, p, fname, sizeof(pstring)-6, STR_TERMINATE ); + p += clistr_push(cli, p, fname, sizeof(pstring)-6, STR_TERMINATE|STR_CONVERT ); param_len = PTR_DIFF(p, param); @@ -462,7 +462,7 @@ BOOL cli_qpathinfo2(struct cli_state *cli, const char *fname, memset(p, 0, 6); SSVAL(p, 0, SMB_QUERY_FILE_ALL_INFO); p += 6; - p += clistr_push(cli, p, fname, sizeof(pstring)-6, STR_TERMINATE ); + p += clistr_push(cli, p, fname, sizeof(pstring)-6, STR_TERMINATE|STR_CONVERT ); param_len = PTR_DIFF(p, param); @@ -649,7 +649,7 @@ NTSTATUS cli_qpathinfo_alt_name(struct cli_state *cli, const char *fname, fstrin memset(p, 0, 6); SSVAL(p, 0, SMB_QUERY_FILE_ALT_NAME_INFO); p += 6; - p += clistr_push(cli, p, fname, sizeof(pstring)-6, STR_TERMINATE); + p += clistr_push(cli, p, fname, sizeof(pstring)-6, STR_TERMINATE|STR_CONVERT); param_len = PTR_DIFF(p, param); diff --git a/source/libsmb/clitrans.c b/source/libsmb/clitrans.c index 96c041fa3be..bd8647421b2 100644 --- a/source/libsmb/clitrans.c +++ b/source/libsmb/clitrans.c @@ -46,12 +46,12 @@ BOOL cli_send_trans(struct cli_state *cli, int trans, memset(cli->outbuf,'\0',smb_size); set_message(cli->outbuf,14+lsetup,0,True); - SCVAL(cli->outbuf,smb_com,trans); + SCVAL(cli->outbuf,smb_com,trans); SSVAL(cli->outbuf,smb_tid, cli->cnum); cli_setup_packet(cli); if (pipe_name) { - pipe_name_len = clistr_push(cli, smb_buf(cli->outbuf), pipe_name, -1, STR_TERMINATE); + pipe_name_len = clistr_push(cli, smb_buf(cli->outbuf), pipe_name, -1, STR_TERMINATE|STR_CONVERT); } outparam = smb_buf(cli->outbuf)+(trans==SMBtrans ? pipe_name_len : 3); diff --git a/source/libsmb/namequery.c b/source/libsmb/namequery.c index 24018bfb26a..09825ac6f1e 100644 --- a/source/libsmb/namequery.c +++ b/source/libsmb/namequery.c @@ -292,7 +292,7 @@ BOOL name_register(int fd, const char *name, int name_type, ****************************************************************************/ struct in_addr *name_query(int fd,const char *name,int name_type, BOOL bcast,BOOL recurse, - struct in_addr to_ip, int *count) + struct in_addr to_ip, int *count, int *flags) { BOOL found=False; int i, retries = 3; @@ -305,6 +305,7 @@ struct in_addr *name_query(int fd,const char *name,int name_type, memset((char *)&p,'\0',sizeof(p)); (*count) = 0; + (*flags) = 0; nmb->header.name_trn_id = generate_trn_id(); nmb->header.opcode = 0; @@ -428,6 +429,19 @@ struct in_addr *name_query(int fd,const char *name,int name_type, found=True; retries=0; + /* We add the flags back ... */ + if (nmb2->header.response) + (*flags) |= NM_FLAGS_RS; + if (nmb2->header.nm_flags.authoritative) + (*flags) |= NM_FLAGS_AA; + if (nmb2->header.nm_flags.trunc) + (*flags) |= NM_FLAGS_TC; + if (nmb2->header.nm_flags.recursion_desired) + (*flags) |= NM_FLAGS_RD; + if (nmb2->header.nm_flags.recursion_available) + (*flags) |= NM_FLAGS_RA; + if (nmb2->header.nm_flags.bcast) + (*flags) |= NM_FLAGS_B; free_packet(p2); /* @@ -655,10 +669,11 @@ BOOL name_resolve_bcast(const char *name, int name_type, */ for( i = num_interfaces-1; i >= 0; i--) { struct in_addr sendto_ip; + int flags; /* Done this way to fix compiler error on IRIX 5.x */ sendto_ip = *iface_bcast(*iface_n_ip(i)); *return_ip_list = name_query(sock, name, name_type, True, - True, sendto_ip, return_count); + True, sendto_ip, return_count, &flags); if(*return_ip_list != NULL) { close(sock); return True; @@ -715,10 +730,11 @@ static BOOL resolve_wins(const char *name, int name_type, interpret_addr(lp_socket_address()), True ); if (sock != -1) { + int flags; *return_iplist = name_query( sock, name, name_type, False, True, wins_ip, - return_count); + return_count, &flags); if(*return_iplist != NULL) { close(sock); return True; @@ -792,15 +808,17 @@ static BOOL resolve_hosts(const char *name, DEBUG(3,("resolve_hosts: Attempting host lookup for name %s<0x20>\n", name)); if (((hp = sys_gethostbyname(name)) != NULL) && (hp->h_addr != NULL)) { - struct in_addr return_ip; - putip((char *)&return_ip,(char *)hp->h_addr); - *return_iplist = (struct in_addr *)malloc(sizeof(struct in_addr)); + int i = 0, j; + while (hp->h_addr_list[i]) i++; + DEBUG(10, ("%d addresses returned\n", i)); + *return_iplist = (struct in_addr *)malloc(i*sizeof(struct in_addr)); if(*return_iplist == NULL) { DEBUG(3,("resolve_hosts: malloc fail !\n")); return False; } - **return_iplist = return_ip; - *return_count = 1; + for (j = 0; j < i; j++) + putip(&(*return_iplist)[j], (char *)hp->h_addr_list[j]); + *return_count = i; return True; } return False; @@ -973,6 +991,15 @@ BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type) return False; } +/************************************************************************** + Resolve a name to a list of addresses +**************************************************************************/ +BOOL resolve_name_2(const char *name, struct in_addr **return_ip, int *count, int name_type) +{ + + return internal_resolve_name(name, name_type, return_ip, count); + +} /******************************************************** resolve a name of format \\server_name or \\ipaddress @@ -1267,7 +1294,7 @@ BOOL get_dc_list(BOOL pdc_only, const char *group, struct in_addr **ip_list, int char *p; char *pserver = lp_passwordserver(); fstring name; - int num_adresses = 0; + int num_addresses = 0; struct in_addr *return_iplist = NULL; if (! *pserver) @@ -1284,12 +1311,12 @@ BOOL get_dc_list(BOOL pdc_only, const char *group, struct in_addr **ip_list, int return True; return internal_resolve_name(group, 0x1B, ip_list, count); } - num_adresses++; + num_addresses++; } - if (num_adresses == 0) + if (num_addresses == 0) return internal_resolve_name(group, name_type, ip_list, count); - return_iplist = (struct in_addr *)malloc(num_adresses * sizeof(struct in_addr)); + return_iplist = (struct in_addr *)malloc(num_addresses * sizeof(struct in_addr)); if(return_iplist == NULL) { DEBUG(3,("get_dc_list: malloc fail !\n")); return False; @@ -1297,10 +1324,22 @@ BOOL get_dc_list(BOOL pdc_only, const char *group, struct in_addr **ip_list, int p = pserver; *count = 0; while (next_token(&p,name,LIST_SEP,sizeof(name))) { - struct in_addr name_ip; - if (resolve_name( name, &name_ip, 0x20) == False) + struct in_addr *more_ip, *tmp; + int count_more; + if (resolve_name_2( name, &more_ip, &count_more, 0x20) == False) continue; - return_iplist[(*count)++] = name_ip; + tmp = (struct in_addr *)realloc(return_iplist,(num_addresses + count_more) * sizeof(struct in_addr)); + if (return_iplist == NULL) { + DEBUG(3, ("realloc failed with %d addresses\n", num_addresses + count_more)); + SAFE_FREE(return_iplist); + SAFE_FREE(more_ip); + return False; + } + return_iplist = tmp; + memmove(&return_iplist[(*count)], more_ip, count_more * sizeof(struct in_addr)); + SAFE_FREE(more_ip); /* Done with this ... */ + *count += count_more; + num_addresses += count_more - 1; } *ip_list = return_iplist; return (*count != 0); diff --git a/source/libsmb/nmblib.c b/source/libsmb/nmblib.c index 54f34cc233a..95d124c0208 100644 --- a/source/libsmb/nmblib.c +++ b/source/libsmb/nmblib.c @@ -1119,7 +1119,11 @@ char *dns_to_netbios_name(char *dns_name) netbios name up to and including the '.' this even applies, by mistake, to workgroup (domain) names, which is _really_ daft. */ - for (i = 15; i >= 0; i--) + /* + * We need to go up, not down, to avoid netbios names like + * fred.xyz being produced from fred.xyz.someco.com. + */ + for (i = 0; i < 15; i++) { if (netbios_name[i] == '.') { diff --git a/source/libsmb/smbencrypt.c b/source/libsmb/smbencrypt.c index c87ff61fdfc..9d862444e0e 100644 --- a/source/libsmb/smbencrypt.c +++ b/source/libsmb/smbencrypt.c @@ -59,7 +59,7 @@ void E_md4hash(const uchar *passwd, uchar *p16) int16 wpwd[129]; /* Password cannot be longer than 128 characters */ - len = strlen(passwd); + len = strlen((const char *)passwd); if(len > 128) len = 128; /* Password must be converted to NT unicode - null terminated. */ |