diff options
author | Matthew Chapman <matty@samba.org> | 1999-02-12 00:16:09 +0000 |
---|---|---|
committer | Matthew Chapman <matty@samba.org> | 1999-02-12 00:16:09 +0000 |
commit | fd96929ec1fa27e0affd4c4e9ba307c4ee30b978 (patch) | |
tree | 6bfb5226bc58be39aaf7cfb954dcb472ea256a11 /source3 | |
parent | f38bfc7d9aa07c4e21448aa846956bd89a259a65 (diff) | |
download | samba-fd96929ec1fa27e0affd4c4e9ba307c4ee30b978.tar.gz samba-fd96929ec1fa27e0affd4c4e9ba307c4ee30b978.tar.xz samba-fd96929ec1fa27e0affd4c4e9ba307c4ee30b978.zip |
UNICODE cleanup (see lib/util_unistr.c).
No more ugly static library buffers and all functions take a destination
string length (especially unistrcpy was rather dangerous; we were only
saved by the fact that datagrams are limited in size).
(This used to be commit a1d39af1ce1d451b811dbd7c2ba391214851b87e)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/proto.h | 21 | ||||
-rw-r--r-- | source3/lib/util_unistr.c | 310 | ||||
-rw-r--r-- | source3/libsmb/smbencrypt.c | 2 | ||||
-rw-r--r-- | source3/lsarpcd/srv_lsa.c | 4 | ||||
-rw-r--r-- | source3/nmbd/nmbd_processlogon.c | 41 | ||||
-rw-r--r-- | source3/rpc_client/cli_lsarpc.c | 8 | ||||
-rw-r--r-- | source3/rpc_client/cli_reg.c | 10 | ||||
-rw-r--r-- | source3/rpc_client/cli_samr.c | 10 | ||||
-rw-r--r-- | source3/rpc_parse/parse_misc.c | 11 | ||||
-rw-r--r-- | source3/rpc_parse/parse_reg.c | 10 | ||||
-rw-r--r-- | source3/rpc_parse/parse_rpc.c | 6 | ||||
-rw-r--r-- | source3/rpc_server/srv_lsa.c | 4 | ||||
-rw-r--r-- | source3/rpc_server/srv_netlog.c | 14 | ||||
-rw-r--r-- | source3/rpc_server/srv_pipe.c | 12 | ||||
-rw-r--r-- | source3/rpc_server/srv_reg.c | 2 | ||||
-rw-r--r-- | source3/rpc_server/srv_samr.c | 12 | ||||
-rw-r--r-- | source3/rpc_server/srv_svcctl.c | 4 | ||||
-rw-r--r-- | source3/rpcclient/cmd_svcctl.c | 3 | ||||
-rw-r--r-- | source3/rpcclient/display.c | 119 | ||||
-rw-r--r-- | source3/smbd/chgpasswd.c | 4 | ||||
-rw-r--r-- | source3/smbd/trans2.c | 13 |
21 files changed, 296 insertions, 324 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index c408545907d..1d3b041e4d7 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -564,18 +564,15 @@ void split_at_last_component(char *path, char *front, char sep, char *back); /*The following definitions come from lib/util_unistr.c */ -int PutUniCode(char *dst,char *src); -char *skip_unicode_string(char *buf,int n); -char *unistrn2(char *src, int len); -char *unistr2(char *src); -char *unistr2_to_str(UNISTR2 *str); -uint32 buffer2_to_uint32(BUFFER2 *str); -char *buffer2_to_str(BUFFER2 *str); -char *buffer2_to_multistr(BUFFER2 *str); -int str_to_unistr16(uint16 *dst, const char *src); -int str_to_unistr8(char *dst, const char *src); -char *unistr(char *buf); -int unistrcpy(char *dst, char *src); +char *ascii_to_unibuf(char *dest, const char *src, int maxlen); +void unibuf_to_ascii(char *dest, const char *src, int maxlen); +void ascii_to_unistr(uint16 *dest, const char *src, int maxlen); +void unistr_to_ascii(char *dest, const uint16 *src, int len); +void unistr2_to_ascii(char *dest, const UNISTR2 *str, int destlen); +char *skip_unibuf(char *srcbuf, int len); +char *uni_strncpy(char *destbuf, const char *srcbuf, int len); +uint32 buffer2_to_uint32(const BUFFER2 *str); +void buffer2_to_multistr(char *dest, const BUFFER2 *str, int destlen); /*The following definitions come from libsmb/clientgen.c */ diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 2e908cbd7a6..28c96bdc38b 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -21,268 +21,186 @@ #include "includes.h" -#ifndef MAXUNI -#define MAXUNI 1024 -#endif - /******************************************************************* -write a string in (little-endian) unicoode format -********************************************************************/ + Put an ASCII string into a UNICODE buffer (little endian). + ********************************************************************/ -int PutUniCode(char *dst,char *src) +char *ascii_to_unibuf(char *dest, const char *src, int maxlen) { - int ret = 0; - while (*src) { - SSVAL(dst,ret,(*src) & 0xFF); - ret += 2; - src++; - } - SSVAL(dst,ret,0); - ret += 2; - return(ret); -} - -/******************************************************************* -skip past some unicode strings in a buffer -********************************************************************/ - -char *skip_unicode_string(char *buf,int n) -{ - while (n--) - { - while (*buf) - buf += 2; - buf += 2; - } - return(buf); -} - -/******************************************************************* -Return a ascii version of a little-endian unicode string. -Hack alert: uses fixed buffer(s) and only handles ascii strings -********************************************************************/ - -char *unistrn2(char *src, int len) -{ - static char lbufs[8][MAXUNI]; - static int nexti; - char *lbuf = lbufs[nexti]; - char *p; - - nexti = (nexti+1)%8; - - for (p = lbuf; *src && p-lbuf < MAXUNI-2 && len > 0; len--, src += 2) - { - *p++ = SVAL(src, 0) & 0xFF; + char *destend = dest + maxlen - 1; + register char c; + + while (dest < destend) { + *(dest++) = c = *(src++); + *(dest++) = 0; + if (c == 0) { + break; + } } - *p = 0; - return lbuf; + return dest; } -static char lbufs[8][MAXUNI]; -static int nexti; /******************************************************************* -Return a ascii version of a little-endian unicode string. -Hack alert: uses fixed buffer(s) and only handles ascii strings -********************************************************************/ + Pull an ASCII string out of a UNICODE buffer (little endian). + ********************************************************************/ -char *unistr2(char *src) +void unibuf_to_ascii(char *dest, const char *src, int maxlen) { - char *lbuf = lbufs[nexti]; - char *p; + char *destend = dest + maxlen; + register char c; - nexti = (nexti+1)%8; - - for (p = lbuf; *src && p-lbuf < MAXUNI-2; p++, src += 2) - { - *p = SVAL(src, 0) & 0xFF; + while (dest < destend) { + *(dest++) = c = *(src++); + if ((c == 0) && (*src == 0)) { + break; + } + src++; } - - *p = 0; - return lbuf; } + /******************************************************************* -Return a ascii version of a little-endian unicode string -********************************************************************/ + Put an ASCII string into a UNICODE array (uint16's). + ********************************************************************/ -char *unistr2_to_str(UNISTR2 *str) +void ascii_to_unistr(uint16 *dest, const char *src, int maxlen) { - char *lbuf = lbufs[nexti]; - char *p; - uint16 *src = str->buffer; - int max_size = MIN(sizeof(str->buffer)-2, str->uni_str_len); + uint16 *destend = dest + maxlen; + register char c; - nexti = (nexti+1)%8; + while (dest < destend) { + c = *(src++); + *(dest++) = (uint16)c; - for (p = lbuf; *src && p-lbuf < max_size; p++, src++) - { - *p = (*src & 0xff); + if (c == 0) { + break; + } } - - *p = 0; - return lbuf; } -/******************************************************************* -Return a number stored in a buffer -********************************************************************/ - -uint32 buffer2_to_uint32(BUFFER2 *str) -{ - if (str->buf_len == 4) - { - return IVAL(str->buffer, 0); - } - else - { - return 0; - } -} /******************************************************************* -Return a ascii version of a NOTunicode string -********************************************************************/ + Pull an ASCII string out of a UNICODE array (uint16's). + ********************************************************************/ -char *buffer2_to_str(BUFFER2 *str) +void unistr_to_ascii(char *dest, const uint16 *src, int len) { - char *lbuf = lbufs[nexti]; - char *p; - uint16 *src = str->buffer; - int max_size = MIN(sizeof(str->buffer)-2, str->buf_len/2); + char *destend = dest + len; + register uint16 c; - nexti = (nexti+1)%8; + while (dest < destend) { + c = *(src++); + *(dest++) = (char)c; - for (p = lbuf; *src && p-lbuf < max_size; p++, src++) - { - *p = (*src & 0xff); + if (c == 0) { + break; + } } - - *p = 0; - return lbuf; } + /******************************************************************* -Return a ascii version of a NOTunicode string -********************************************************************/ + Convert a UNISTR2 structure to an ASCII string + ********************************************************************/ -char *buffer2_to_multistr(BUFFER2 *str) +void unistr2_to_ascii(char *dest, const UNISTR2 *str, int destlen) { - char *lbuf = lbufs[nexti]; - char *p; - uint16 *src = str->buffer; - int max_size = MIN(sizeof(str->buffer)-2, str->buf_len/2); + char *destend; + const uint16 *src; + int len; + register uint16 c; - nexti = (nexti+1)%8; + src = str->buffer; + len = MIN(str->uni_str_len, destlen); + destend = dest + len; - for (p = lbuf; p-lbuf < max_size; p++, src++) - { - if (*src == 0) - { - *p = ' '; - } - else - { - *p = (*src & 0xff); + while (dest < destend) { + c = *(src++); + *(dest++) = (char)c; + + if (c == 0) { + break; } } - - *p = 0; - return lbuf; } -/******************************************************************* -create a null-terminated unicode string from a null-terminated ascii string. -return number of unicode chars copied, excluding the null character. -only handles ascii strings -Unicode strings created are in little-endian format. -********************************************************************/ -int str_to_unistr16(uint16 *dst, const char *src) -{ - size_t len = 0; - if (dst == NULL) - return 0; +/******************************************************************* + Skip a UNICODE string in a little endian buffer. + ********************************************************************/ - if (src != NULL) - { - for (; *src && len < MAXUNI-2; len++, dst++, src++) - { - *dst = *src; - } - } +char *skip_unibuf(char *srcbuf, int len) +{ + uint16 *src = (uint16 *)srcbuf; + uint16 *srcend = src + len/2; - *dst = 0; + while ((src < srcend) && (*(src++) != 0)) + ; - return len; + return (char *)src; } + /******************************************************************* -create a null-terminated unicode string from a null-terminated ascii string. -return number of unicode chars copied, excluding the null character. -only handles ascii strings -Unicode strings created are in little-endian format. -********************************************************************/ + UNICODE strcpy between buffers. + ********************************************************************/ -int str_to_unistr8(char *dst, const char *src) +char *uni_strncpy(char *destbuf, const char *srcbuf, int len) { - size_t len = 0; - - if (dst == NULL) - return 0; - - if (src != NULL) - { - for (; *src && len < MAXUNI-2; len++, dst +=2, src++) - { - SSVAL(dst,0,(*src) & 0xFF); + const uint16 *src = (uint16 *)srcbuf; + uint16 *dest = (uint16 *)destbuf; + uint16 *destend = dest + len/2; + register uint16 c; + + while (dest < destend) { + *(dest++) = c = *(src++); + if (c == 0) { + break; } } - SSVAL(dst,0,0); - - return len; + return (char *)dest; } + /******************************************************************* -Return a ascii version of a little-endian unicode string. -Hack alert: uses fixed buffer(s) and only handles ascii strings -********************************************************************/ + Return a number stored in a buffer + ********************************************************************/ -char *unistr(char *buf) +uint32 buffer2_to_uint32(const BUFFER2 *str) { - char *lbuf = lbufs[nexti]; - char *p; - - nexti = (nexti+1)%8; - - for (p = lbuf; *buf && p-lbuf < MAXUNI-2; p++, buf += 2) + if (str->buf_len == 4) + { + return IVAL(str->buffer, 0); + } + else { - *p = SVAL(buf, 0) & 0xFF; + return 0; } - *p = 0; - return lbuf; } /******************************************************************* -strcpy for unicode strings. returns length (in num of wide chars) -********************************************************************/ + Convert a 'multi-string' buffer to space-separated ASCII. + ********************************************************************/ -int unistrcpy(char *dst, char *src) +void buffer2_to_multistr(char *dest, const BUFFER2 *str, int destlen) { - int num_wchars = 0; - - while (*src) - { - *dst++ = *src++; - *dst++ = *src++; - num_wchars++; + char *destend; + const uint16 *src; + int len; + register uint16 c; + + src = str->buffer; + len = MIN(str->buf_len/2, destlen); + destend = dest + len - 1; + + while (dest < destend) { + c = *(src++); + *(dest++) = (c == 0) ? ' ' : (char)c; } - *dst++ = 0; - *dst++ = 0; - return num_wchars; + *dest = 0; } diff --git a/source3/libsmb/smbencrypt.c b/source3/libsmb/smbencrypt.c index ead34aaa3d3..e35cccd7348 100644 --- a/source3/libsmb/smbencrypt.c +++ b/source3/libsmb/smbencrypt.c @@ -209,7 +209,7 @@ BOOL make_oem_passwd_hash(char data[516], const char *passwd, uchar old_pw_hash[ generate_random_buffer((unsigned char *)data, 516, False); if (unicode) { - str_to_unistr8( &data[512 - new_pw_len], passwd); + ascii_to_unibuf(&data[512 - new_pw_len], passwd, new_pw_len); } else { diff --git a/source3/lsarpcd/srv_lsa.c b/source3/lsarpcd/srv_lsa.c index 4db97f6d4c0..fbbeb4233ea 100644 --- a/source3/lsarpcd/srv_lsa.c +++ b/source3/lsarpcd/srv_lsa.c @@ -156,7 +156,7 @@ static int make_dom_ref(DOM_R_REF *ref, char *dom_name, DOM_SID *dom_sid) for (num = 0; num < ref->num_ref_doms_1; num++) { fstring domname; - fstrcpy(domname, unistr2_to_str(&ref->ref_dom[num].uni_dom_name)); + unistr2_to_ascii(domname, &ref->ref_dom[num].uni_dom_name, sizeof(domname)); if (strequal(domname, dom_name)) { return num; @@ -217,7 +217,7 @@ static void make_lsa_rid2s(DOM_R_REF *ref, char *dom_name = NULL; uint8 sid_name_use = SID_NAME_UNKNOWN; - fstrcpy(find_name, unistr2_to_str(&name[i])); + unistr2_to_ascii(find_name, &name[i], sizeof(find_name)); dom_name = strdup(find_name); if (map_domain_name_to_sid(&sid, &dom_name)) diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 42810683412..67678db0694 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -50,7 +50,6 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len, uint32 domainsidsize; char *getdc; char *uniuser; /* Unicode user name. */ - pstring ascuser; char *unicomp; /* Unicode computer name. */ memset(outbuf, 0, sizeof(outbuf)); @@ -118,7 +117,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = align2(unicomp, buf); - q = skip_unicode_string(q, 1); + q = skip_unibuf(q, buf+len-q); ntversion = IVAL(q, 0); q += 4; @@ -140,10 +139,9 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) { q = align2(q, buf); - PutUniCode(q, my_name); /* PDC name */ - q = skip_unicode_string(q, 1); - PutUniCode(q, global_myworkgroup); /* Domain name*/ - q = skip_unicode_string(q, 1); + /* PDC and domain name */ + q = ascii_to_unibuf(q, my_name, outbuf+sizeof(outbuf)-q); + q = ascii_to_unibuf(q, global_myworkgroup, outbuf+sizeof(outbuf)-q); SIVAL(q, 0, ntversion); q += 4; @@ -177,8 +175,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; unicomp = q; - uniuser = skip_unicode_string(unicomp,1); - getdc = skip_unicode_string(uniuser,1); + uniuser = skip_unibuf(unicomp, buf+len-q); + getdc = skip_unibuf(uniuser, buf+len-q); q = skip_string(getdc,1); q += 4; domainsidsize = IVAL(q, 0); @@ -199,15 +197,20 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", * Let's ignore the SID. */ - pstrcpy(ascuser, unistr(uniuser)); - DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser)); - fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ fstrcpy(reply_name+2,my_name); - DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", - unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, global_myworkgroup, - SAMLOGON_R ,lmnttoken)); + if (DEBUGLVL(3)) { + fstring ascuser; + fstring asccomp; + + unibuf_to_ascii(ascuser, uniuser, sizeof(ascuser)); + unibuf_to_ascii(asccomp, unicomp, sizeof(asccomp)); + + DEBUGADD(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", + asccomp,inet_ntoa(p->ip), ascuser, reply_name, + global_myworkgroup, SAMLOGON_R, lmnttoken)); + } /* Construct reply. */ @@ -215,12 +218,10 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", SSVAL(q, 0, SAMLOGON_R); q += 2; - PutUniCode(q, reply_name); - q = skip_unicode_string(q, 1); - unistrcpy(q, uniuser); - q = skip_unicode_string(q, 1); /* User name (workstation trust account) */ - PutUniCode(q, lp_workgroup()); - q = skip_unicode_string(q, 1); /* Domain name. */ + /* Logon server, trust account, domain */ + q = ascii_to_unibuf(q, reply_name, outbuf+sizeof(outbuf)-q); + q = uni_strncpy(q, uniuser, outbuf+sizeof(outbuf)-q); + q = ascii_to_unibuf(q, lp_workgroup(), outbuf+sizeof(outbuf)-q); SIVAL(q, 0, ntversion); q += 4; diff --git a/source3/rpc_client/cli_lsarpc.c b/source3/rpc_client/cli_lsarpc.c index 4c55572b626..21eba6ddb7b 100644 --- a/source3/rpc_client/cli_lsarpc.c +++ b/source3/rpc_client/cli_lsarpc.c @@ -331,8 +331,8 @@ BOOL lsa_lookup_sids(struct cli_state *cli, uint16 fnum, if (dom_idx != 0xffffffff) { - fstrcpy(dom_name, unistr2_to_str(&ref.ref_dom[dom_idx].uni_dom_name)); - fstrcpy(name , unistr2_to_str(&t_names.uni_name[i])); + unistr2_to_ascii(dom_name, &ref.ref_dom[dom_idx].uni_dom_name, sizeof(dom_name)); + unistr2_to_ascii(name, &t_names.uni_name[i], sizeof(name)); memset(full_name, 0, sizeof(full_name)); @@ -427,7 +427,7 @@ BOOL lsa_query_info_pol(struct cli_state *cli, uint16 fnum, { if (r_q.dom.id3.buffer_dom_name != 0) { - fstrcpy(domain_name, unistr2_to_str(&r_q.dom.id3.uni_domain_name)); + unistr2_to_ascii(domain_name, &r_q.dom.id3.uni_domain_name, sizeof(domain_name)); } if (r_q.dom.id3.buffer_dom_sid != 0) { @@ -441,7 +441,7 @@ BOOL lsa_query_info_pol(struct cli_state *cli, uint16 fnum, { if (r_q.dom.id5.buffer_dom_name != 0) { - fstrcpy(domain_name, unistr2_to_str(&r_q.dom.id5.uni_domain_name)); + unistr2_to_ascii(domain_name, &r_q.dom.id5.uni_domain_name, sizeof(domain_name)); } if (r_q.dom.id5.buffer_dom_sid != 0) { diff --git a/source3/rpc_client/cli_reg.c b/source3/rpc_client/cli_reg.c index b3d2f6e864c..6fe48599d57 100644 --- a/source3/rpc_client/cli_reg.c +++ b/source3/rpc_client/cli_reg.c @@ -306,7 +306,7 @@ BOOL do_reg_query_key(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd, valid_query = True; *class_len = r_o.hdr_class.uni_max_len; - fstrcpy(class, unistr2_to_str(&r_o.uni_class)); + unistr2_to_ascii(class, &r_o.uni_class, sizeof(class)); *num_subkeys = r_o.num_subkeys ; *max_subkeylen = r_o.max_subkeylen ; *max_subkeysize = r_o.max_subkeysize; @@ -425,7 +425,8 @@ BOOL do_reg_query_info(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd, if (p) { valid_query = True; - fstrcpy(type, buffer2_to_str(&r_o.uni_type)); + unistr_to_ascii(type, r_o.uni_type.buffer, + MIN(r_o.uni_type.buf_len, sizeof(type))); (*unk_0) = r_o.unknown_0; (*unk_1) = r_o.unknown_1; } @@ -786,7 +787,8 @@ BOOL do_reg_enum_key(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd, valid_query = True; (*unk_1) = r_o.unknown_1; (*unk_2) = r_o.unknown_2; - fstrcpy(key_name, unistr2(r_o.key_name.str.buffer)); + unistr_to_ascii(key_name, r_o.key_name.str.buffer, + sizeof(key_name)); (*mod_time) = nt_time_to_unix(&r_o.time); } } @@ -902,7 +904,7 @@ BOOL do_reg_enum_val(struct cli_state *cli, uint16 fnum, POLICY_HND *hnd, { valid_query = True; (*val_type) = r_o.type; - fstrcpy(val_name, unistr2_to_str(&r_o.uni_name)); + unistr2_to_ascii(val_name, &r_o.uni_name, sizeof(val_name)); } } diff --git a/source3/rpc_client/cli_samr.c b/source3/rpc_client/cli_samr.c index f97a38b718d..2ddc0877a99 100644 --- a/source3/rpc_client/cli_samr.c +++ b/source3/rpc_client/cli_samr.c @@ -585,12 +585,12 @@ BOOL samr_enum_dom_groups(struct cli_state *cli, uint16 fnum, (*sam)[i].acct_desc[0] = 0; if (r_e.sam[i].hdr_grp_name.buffer) { - fstrcpy((*sam)[i].acct_name, unistr2_to_str(&r_e.str[name_idx].uni_grp_name)); + unistr2_to_ascii((*sam)[i].acct_name, &r_e.str[name_idx].uni_grp_name, sizeof((*sam)[i].acct_name)); name_idx++; } if (r_e.sam[i].hdr_grp_desc.buffer) { - fstrcpy((*sam)[i].acct_desc, unistr2_to_str(&r_e.str[desc_idx].uni_grp_desc)); + unistr2_to_ascii((*sam)[i].acct_desc, &r_e.str[name_idx].uni_grp_desc, sizeof((*sam)[i].acct_desc)); desc_idx++; } DEBUG(5,("samr_enum_dom_groups: idx: %4d rid: %8x acct: %s desc: %s\n", @@ -678,7 +678,7 @@ BOOL samr_enum_dom_aliases(struct cli_state *cli, uint16 fnum, (*sam)[i].acct_desc[0] = 0; if (r_e.sam[i].hdr_name.buffer) { - fstrcpy((*sam)[i].acct_name, unistr2_to_str(&r_e.uni_grp_name[name_idx])); + unistr2_to_ascii((*sam)[i].acct_name, &r_e.uni_grp_name[name_idx], sizeof((*sam)[i].acct_name)); name_idx++; } DEBUG(5,("samr_enum_dom_aliases: idx: %4d rid: %8x acct: %s\n", @@ -767,7 +767,7 @@ BOOL samr_enum_dom_users(struct cli_state *cli, uint16 fnum, (*sam)[i].acct_desc[0] = 0; if (r_e.sam[i].hdr_name.buffer) { - fstrcpy((*sam)[i].acct_name, unistr2_to_str(&r_e.uni_acct_name[name_idx])); + unistr2_to_ascii((*sam)[i].acct_name, &r_e.uni_acct_name[name_idx], sizeof((*sam)[i].acct_name)); name_idx++; } DEBUG(5,("samr_enum_dom_users: idx: %4d rid: %8x acct: %s\n", @@ -1774,7 +1774,7 @@ BOOL samr_query_lookup_rids(struct cli_state *cli, uint16 fnum, for (i = 0; i < r_o.num_names1; i++) { - fstrcpy(names[i], unistr2_to_str(&r_o.uni_name[i])); + unistr2_to_ascii(names[i], &r_o.uni_name[i], sizeof(names[i])); } for (i = 0; i < r_o.num_types1; i++) { diff --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c index 7c3f4469087..04a9ba4544d 100644 --- a/source3/rpc_parse/parse_misc.c +++ b/source3/rpc_parse/parse_misc.c @@ -328,8 +328,7 @@ creates a UNISTR structure. ********************************************************************/ void make_unistr(UNISTR *str, char *buf) { - /* store the string (null-terminated copy) */ - str_to_unistr16(str->buffer, buf); + ascii_to_unistr(str->buffer, buf, sizeof(str->buffer)); } /******************************************************************* @@ -371,8 +370,8 @@ void make_buffer3_str(BUFFER3 *str, char *buf, int len) str->buf_max_len = len * 2; str->buf_len = len * 2; - /* store the string (null-terminated 8 bit chars into 16 bit chars) */ - str_to_unistr8(str->buffer, buf); + /* store the string (little endian buffer) */ + ascii_to_unibuf(str->buffer, buf, str->buf_len); } /******************************************************************* @@ -572,8 +571,8 @@ void make_unistr2(UNISTR2 *str, const char *buf, int len) str->undoc = 0; str->uni_str_len = len; - /* store the string (null-terminated 8 bit chars into 16 bit chars) */ - str_to_unistr16((str->buffer), buf); + /* store the string (wide chars) */ + ascii_to_unistr(str->buffer, buf, len); } /******************************************************************* diff --git a/source3/rpc_parse/parse_reg.c b/source3/rpc_parse/parse_reg.c index 84d96501053..3aa9bbbc2a3 100644 --- a/source3/rpc_parse/parse_reg.c +++ b/source3/rpc_parse/parse_reg.c @@ -769,19 +769,21 @@ void make_reg_r_info(REG_R_INFO *r_r, uint32 status) { char buf[512]; - int len = str_to_unistr8(buf, os_type); + int len; + + len = ascii_to_unibuf(buf, os_type, sizeof(buf)) - buf; r_r->ptr1 = 1; r_r->level = level; r_r->ptr_type = 1; - make_buffer2(&(r_r->uni_type), buf, len*2); + make_buffer2(&(r_r->uni_type), buf, len); r_r->ptr2 = 1; - r_r->unknown_0 = len*2; + r_r->unknown_0 = len; r_r->ptr3 = 1; - r_r->unknown_1 = len*2; + r_r->unknown_1 = len; r_r->status = status; } diff --git a/source3/rpc_parse/parse_rpc.c b/source3/rpc_parse/parse_rpc.c index 63f738466b1..c4a7e358951 100644 --- a/source3/rpc_parse/parse_rpc.c +++ b/source3/rpc_parse/parse_rpc.c @@ -707,9 +707,9 @@ void make_rpc_auth_ntlmssp_resp(RPC_AUTH_NTLMSSP_RESP *rsp, if (IS_BITS_SET_ALL(neg_flags, NTLMSSP_NEGOTIATE_UNICODE)) { - str_to_unistr8(rsp->domain, domain); - str_to_unistr8(rsp->user , user ); - str_to_unistr8(rsp->wks , wks ); + ascii_to_unibuf(rsp->domain, domain, sizeof(rsp->domain)); + ascii_to_unibuf(rsp->user , user , sizeof(rsp->user )); + ascii_to_unibuf(rsp->wks , wks , sizeof(rsp->wks )); } else { diff --git a/source3/rpc_server/srv_lsa.c b/source3/rpc_server/srv_lsa.c index 4db97f6d4c0..fbbeb4233ea 100644 --- a/source3/rpc_server/srv_lsa.c +++ b/source3/rpc_server/srv_lsa.c @@ -156,7 +156,7 @@ static int make_dom_ref(DOM_R_REF *ref, char *dom_name, DOM_SID *dom_sid) for (num = 0; num < ref->num_ref_doms_1; num++) { fstring domname; - fstrcpy(domname, unistr2_to_str(&ref->ref_dom[num].uni_dom_name)); + unistr2_to_ascii(domname, &ref->ref_dom[num].uni_dom_name, sizeof(domname)); if (strequal(domname, dom_name)) { return num; @@ -217,7 +217,7 @@ static void make_lsa_rid2s(DOM_R_REF *ref, char *dom_name = NULL; uint8 sid_name_use = SID_NAME_UNKNOWN; - fstrcpy(find_name, unistr2_to_str(&name[i])); + unistr2_to_ascii(find_name, &name[i], sizeof(find_name)); dom_name = strdup(find_name); if (map_domain_name_to_sid(&sid, &dom_name)) diff --git a/source3/rpc_server/srv_netlog.c b/source3/rpc_server/srv_netlog.c index 33eb889ff2e..f34aa502ed2 100644 --- a/source3/rpc_server/srv_netlog.c +++ b/source3/rpc_server/srv_netlog.c @@ -288,7 +288,7 @@ static void api_net_req_chal( uint16 vuid, /* grab the challenge... */ net_io_q_req_chal("", &q_r, data, 0); - fstrcpy(mach_acct, unistr2_to_str(&q_r.uni_logon_clnt)); + unistr2_to_ascii(mach_acct, &q_r.uni_logon_clnt, sizeof(mach_acct)); fstrcpy(mach_name, mach_acct); strlower(mach_name); @@ -399,7 +399,8 @@ static void api_net_srv_pwset( uint16 vuid, DEBUG(5,("api_net_srv_pwset: %d\n", __LINE__)); - fstrcpy(mach_acct, unistr2_to_str(&q_a.clnt_id.login.uni_acct_name)); + unistr2_to_ascii(mach_acct, &q_a.clnt_id.login.uni_acct_name, + sizeof(mach_acct)); DEBUG(3,("Server Password Set Wksta:[%s]\n", mach_acct)); @@ -672,12 +673,9 @@ static void api_net_sam_logon( uint16 vuid, if (status == 0) { - fstrcpy(nt_username, unistr2_to_str(uni_samlogon_user)); -#if 0 - slprintf(nt_username, sizeof(nt_username), "%s\\%s", - unistr2_to_str(uni_domain), - unistr2_to_str(uni_samlogon_user)); -#endif + unistr2_to_ascii(nt_username, uni_samlogon_user, + sizeof(nt_username)); + DEBUG(3,("User:[%s]\n", nt_username)); become_root(True); diff --git a/source3/rpc_server/srv_pipe.c b/source3/rpc_server/srv_pipe.c index 5908fe06b52..07e16c7e5de 100644 --- a/source3/rpc_server/srv_pipe.c +++ b/source3/rpc_server/srv_pipe.c @@ -225,9 +225,15 @@ static BOOL api_pipe_ntlmssp_verify(pipes_struct *p) if (IS_BITS_SET_ALL(p->ntlmssp_chal.neg_flags, NTLMSSP_NEGOTIATE_UNICODE)) { - fstrcpy(p->user_name, unistrn2(p->ntlmssp_resp.user , p->ntlmssp_resp.hdr_usr .str_str_len/2)); - fstrcpy(p->domain , unistrn2(p->ntlmssp_resp.domain, p->ntlmssp_resp.hdr_domain.str_str_len/2)); - fstrcpy(p->wks , unistrn2(p->ntlmssp_resp.wks , p->ntlmssp_resp.hdr_wks .str_str_len/2)); + unibuf_to_ascii(p->user_name, p->ntlmssp_resp.user, + MIN(p->ntlmssp_resp.hdr_usr .str_str_len/2, + sizeof(p->user_name))); + unibuf_to_ascii(p->domain , p->ntlmssp_resp.domain, + MIN(p->ntlmssp_resp.hdr_domain.str_str_len/2, + sizeof(p->domain ))); + unibuf_to_ascii(p->wks , p->ntlmssp_resp.wks, + MIN(p->ntlmssp_resp.hdr_wks .str_str_len/2, + sizeof(p->wks ))); } else { diff --git a/source3/rpc_server/srv_reg.c b/source3/rpc_server/srv_reg.c index f98133626d5..52fff8716c1 100644 --- a/source3/rpc_server/srv_reg.c +++ b/source3/rpc_server/srv_reg.c @@ -136,7 +136,7 @@ static void reg_reply_open_entry(REG_Q_OPEN_ENTRY *q_u, status = 0xC000000 | NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */ } - fstrcpy(name, unistr2_to_str(&q_u->uni_name)); + unistr2_to_ascii(name, &q_u->uni_name, sizeof(name)); if (status == 0x0) { diff --git a/source3/rpc_server/srv_samr.c b/source3/rpc_server/srv_samr.c index ec3fa289a7e..7f2b62212ed 100644 --- a/source3/rpc_server/srv_samr.c +++ b/source3/rpc_server/srv_samr.c @@ -1440,7 +1440,7 @@ static void samr_reply_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u, { DOM_SID sid; fstring name; - fstrcpy(name, unistr2_to_str(&q_u->uni_name[i])); + unistr2_to_ascii(name, &q_u->uni_name[i], sizeof(name)); status = lookup_name(name, &sid, &(type[i])); if (status == 0x0) @@ -1489,8 +1489,8 @@ static void samr_reply_chgpasswd_user(SAMR_Q_CHGPASSWD_USER *q_u, fstring user_name; fstring wks; - fstrcpy(user_name, unistr2_to_str(&q_u->uni_user_name)); - fstrcpy(wks , unistr2_to_str(&q_u->uni_dest_host)); + unistr2_to_ascii(user_name, &q_u->uni_user_name, sizeof(user_name)); + unistr2_to_ascii(wks, &q_u->uni_dest_host, sizeof(wks)); DEBUG(5,("samr_chgpasswd_user: user: %s wks: %s\n", user_name, wks)); @@ -2024,7 +2024,7 @@ static void samr_reply_create_dom_alias(SAMR_Q_CREATE_DOM_ALIAS *q_u, if (status == 0x0) { - fstrcpy(grp.name, unistr2_to_str(&q_u->uni_acct_desc)); + unistr2_to_ascii(grp.name, &q_u->uni_acct_desc, sizeof(grp.name)); fstrcpy(grp.comment, ""); grp.rid = 0xffffffff; @@ -2135,7 +2135,7 @@ static void samr_reply_create_dom_group(SAMR_Q_CREATE_DOM_GROUP *q_u, if (status == 0x0) { - fstrcpy(grp.name, unistr2_to_str(&q_u->uni_acct_desc)); + unistr2_to_ascii(grp.name, &q_u->uni_acct_desc, sizeof(grp.name)); fstrcpy(grp.comment, ""); grp.rid = 0xffffffff; grp.attr = 0x07; @@ -2302,7 +2302,7 @@ static void api_samr_unknown_32( uint16 vuid, prs_struct *data, prs_struct *rdat reply if the account already exists... */ - fstrcpy(mach_acct, unistr2_to_str(&q_u.uni_mach_acct)); + unistr2_to_ascii(mach_acct, &q_u.uni_mach_acct, sizeof(mach_acct)); become_root(True); sam_pass = getsam21pwntnam(mach_acct); diff --git a/source3/rpc_server/srv_svcctl.c b/source3/rpc_server/srv_svcctl.c index 6a39b246d01..cf6ab5a0e10 100644 --- a/source3/rpc_server/srv_svcctl.c +++ b/source3/rpc_server/srv_svcctl.c @@ -93,7 +93,7 @@ static void svc_reply_open_service(SVC_Q_OPEN_SERVICE *q_u, status = 0xC000000 | NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */ } - fstrcpy(name, unistr2_to_str(&q_u->uni_svc_name)); + unistr2_to_ascii(name, &q_u->uni_svc_name, sizeof(name)); if (status == 0x0) { @@ -143,7 +143,7 @@ static void svc_reply_open_sc_man(SVC_Q_OPEN_SC_MAN *q_u, status = 0xC000000 | NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */ } - fstrcpy(name, unistr2_to_str(&q_u->uni_srv_name)); + unistr2_to_ascii(name, &q_u->uni_srv_name, sizeof(name)); if (status == 0x0) { diff --git a/source3/rpcclient/cmd_svcctl.c b/source3/rpcclient/cmd_svcctl.c index e30c20af641..280eea68de3 100644 --- a/source3/rpcclient/cmd_svcctl.c +++ b/source3/rpcclient/cmd_svcctl.c @@ -104,7 +104,8 @@ void cmd_svc_enum(struct client_info *info) QUERY_SERVICE_CONFIG cfg; uint32 svc_buf_size = 0x800; - fstrcpy(svc_name, unistr2(svcs[i].uni_srvc_name.buffer)); + unistr_to_ascii(svc_name, svcs[i].uni_srvc_name.buffer, + sizeof(svc_name)); res2 = res2 ? svc_open_service(smb_cli, fnum, &sc_man_pol, diff --git a/source3/rpcclient/display.c b/source3/rpcclient/display.c index 173a42bf734..56efdf74be8 100644 --- a/source3/rpcclient/display.c +++ b/source3/rpcclient/display.c @@ -192,8 +192,8 @@ void display_srv_info_101(FILE *out_hnd, enum action_type action, fstring name; fstring comment; - fstrcpy(name , unistr2_to_str(&sv101->uni_name )); - fstrcpy(comment , unistr2_to_str(&sv101->uni_comment )); + unistr2_to_ascii(name, &sv101->uni_name, sizeof(name)); + unistr2_to_ascii(comment, &sv101->uni_comment, sizeof(comment)); display_server(out_hnd, action, name, sv101->srv_type, comment); @@ -234,9 +234,10 @@ void display_srv_info_102(FILE *out_hnd, enum action_type action,SRV_INFO_102 *s fstring comment; fstring usr_path; - fstrcpy(name , unistr2_to_str(&sv102->uni_name )); - fstrcpy(comment , unistr2_to_str(&sv102->uni_comment )); - fstrcpy(usr_path, unistr2_to_str(&sv102->uni_usr_path)); + unistr2_to_ascii(name, &sv102->uni_name, sizeof(name)); + unistr2_to_ascii(comment, &sv102->uni_comment, sizeof(comment)); + unistr2_to_ascii(usr_path, &sv102->uni_usr_path, + sizeof(usr_path)); display_server(out_hnd, action, name, sv102->srv_type, comment); @@ -347,8 +348,8 @@ void display_conn_info_1(FILE *out_hnd, enum action_type action, fstring usr_name; fstring net_name; - fstrcpy(usr_name, unistr2_to_str(&str1->uni_usr_name)); - fstrcpy(net_name, unistr2_to_str(&str1->uni_net_name)); + unistr2_to_ascii(usr_name, &str1->uni_usr_name, sizeof(usr_name)); + unistr2_to_ascii(net_name, &str1->uni_net_name, sizeof(net_name)); fprintf(out_hnd, "\tid :\t%d\n", info1->id); fprintf(out_hnd, "\ttype :\t%s\n", get_share_type_str(info1->type)); @@ -503,8 +504,8 @@ void display_share_info_1(FILE *out_hnd, enum action_type action, fstring remark ; fstring net_name; - fstrcpy(net_name, unistr2_to_str(&str1->uni_netname)); - fstrcpy(remark , unistr2_to_str(&str1->uni_remark )); + unistr2_to_ascii(net_name, &str1->uni_netname, sizeof(net_name)); + unistr2_to_ascii(remark, &str1->uni_remark, sizeof(remark)); display_share(out_hnd, action, net_name, info1->type, remark); @@ -545,10 +546,10 @@ void display_share_info_2(FILE *out_hnd, enum action_type action, fstring path ; fstring passwd ; - fstrcpy(net_name, unistr2_to_str(&str2->uni_netname)); - fstrcpy(remark , unistr2_to_str(&str2->uni_remark )); - fstrcpy(path , unistr2_to_str(&str2->uni_path )); - fstrcpy(passwd , unistr2_to_str(&str2->uni_passwd )); + unistr2_to_ascii(net_name, &str2->uni_netname, sizeof(net_name)); + unistr2_to_ascii(remark, &str2->uni_remark, sizeof(remark)); + unistr2_to_ascii(path, &str2->uni_path, sizeof(path)); + unistr2_to_ascii(passwd, &str2->uni_passwd, sizeof(passwd)); display_share2(out_hnd, action, net_name, info2->type, remark, info2->perms, info2->max_uses, info2->num_uses, @@ -698,8 +699,10 @@ void display_file_info_3(FILE *out_hnd, enum action_type action, fstring path_name; fstring user_name; - fstrcpy(path_name, unistr2_to_str(&str3->uni_path_name)); - fstrcpy(user_name, unistr2_to_str(&str3->uni_user_name)); + unistr2_to_ascii(path_name, &str3->uni_path_name, + sizeof(path_name)); + unistr2_to_ascii(user_name, &str3->uni_user_name, + sizeof(user_name)); fprintf(out_hnd, "\tid :\t%d\n", info3->id); fprintf(out_hnd, "\tperms :\t%s\n", get_file_mode_str(info3->perms)); @@ -1148,16 +1151,37 @@ void display_sam_user_info_21(FILE *out_hnd, enum action_type action, SAM_USER_I } case ACTION_ENUMERATE: { - fprintf(out_hnd, "\t\tUser Name :\t%s\n", unistr2_to_str(&usr->uni_user_name )); /* username unicode string */ - fprintf(out_hnd, "\t\tFull Name :\t%s\n", unistr2_to_str(&usr->uni_full_name )); /* user's full name unicode string */ - fprintf(out_hnd, "\t\tHome Drive :\t%s\n", unistr2_to_str(&usr->uni_home_dir )); /* home directory unicode string */ - fprintf(out_hnd, "\t\tDir Drive :\t%s\n", unistr2_to_str(&usr->uni_dir_drive )); /* home directory drive unicode string */ - fprintf(out_hnd, "\t\tProfile Path:\t%s\n", unistr2_to_str(&usr->uni_profile_path)); /* profile path unicode string */ - fprintf(out_hnd, "\t\tLogon Script:\t%s\n", unistr2_to_str(&usr->uni_logon_script)); /* logon script unicode string */ - fprintf(out_hnd, "\t\tDescription :\t%s\n", unistr2_to_str(&usr->uni_acct_desc )); /* user description unicode string */ - fprintf(out_hnd, "\t\tWorkstations:\t%s\n", unistr2_to_str(&usr->uni_workstations)); /* workstaions unicode string */ - fprintf(out_hnd, "\t\tUnknown Str :\t%s\n", unistr2_to_str(&usr->uni_unknown_str )); /* unknown string unicode string */ - fprintf(out_hnd, "\t\tRemote Dial :\t%s\n", unistr2_to_str(&usr->uni_munged_dial )); /* munged remote access unicode string */ + fstring temp; + + unistr2_to_ascii(temp, &usr->uni_user_name, sizeof(temp)); + fprintf(out_hnd, "\t\tUser Name :\t%s\n", temp); + + unistr2_to_ascii(temp, &user->uni_full_name, sizeof(temp)); + fprintf(out_hnd, "\t\tFull Name :\t%s\n", temp); + + unistr2_to_ascii(temp, &user->uni_home_dir, sizeof(temp)); + fprintf(out_hnd, "\t\tHome Drive :\t%s\n", temp); + + unistr2_to_ascii(temp, &user->uni_dir_drive, sizeof(temp)); + fprintf(out_hnd, "\t\tDir Drive :\t%s\n", temp); + + unistr2_to_ascii(temp, &user->uni_profile_path, sizeof(temp)); + fprintf(out_hnd, "\t\tProfile Path:\t%s\n", temp); + + unistr2_to_ascii(temp, &user->uni_logon_script, sizeof(temp)); + fprintf(out_hnd, "\t\tLogon Script:\t%s\n", temp); + + unistr2_to_ascii(temp, &user->uni_acct_desc, sizeof(temp)); + fprintf(out_hnd, "\t\tDescription :\t%s\n", temp); + + unistr2_to_ascii(temp, &user->uni_workstations, sizeof(temp)); + fprintf(out_hnd, "\t\tWorkstations:\t%s\n", temp); + + unistr2_to_ascii(temp, &user->uni_unknown_str, sizeof(temp)); + fprintf(out_hnd, "\t\tUnknown Str :\t%s\n", temp); + + unistr2_to_ascii(temp, &user->uni_munged_dial, sizeof(temp)); + fprintf(out_hnd, "\t\tRemote Dial :\t%s\n", temp); fprintf(out_hnd, "\t\tLogon Time :\t%s\n", http_timestring(nt_time_to_unix(&(usr->logon_time )))); fprintf(out_hnd, "\t\tLogoff Time :\t%s\n", http_timestring(nt_time_to_unix(&(usr->logoff_time )))); @@ -1446,13 +1470,17 @@ char *get_reg_val_type_str(uint32 type) static void print_reg_value(FILE *out_hnd, char *val_name, uint32 val_type, BUFFER2 *value) { fstring type; + fstring valstr; + fstrcpy(type, get_reg_val_type_str(val_type)); switch (val_type) { case 0x01: /* unistr */ { - fprintf(out_hnd,"\t%s:\t%s:\t%s\n", val_name, type, buffer2_to_str(value)); + unistr_to_ascii(valstr, value->buffer, + MIN(value->buf_len, sizeof(valstr))); + fprintf(out_hnd,"\t%s:\t%s:\t%s\n", val_name, type, valstr); break; } @@ -1480,7 +1508,8 @@ static void print_reg_value(FILE *out_hnd, char *val_name, uint32 val_type, BUFF case 0x07: /* multiunistr */ { - fprintf(out_hnd,"\t%s:\t%s:\t%s\n", val_name, type, buffer2_to_multistr(value)); + buffer2_to_multistr(valstr, value, sizeof(valstr)); + fprintf(out_hnd,"\t%s:\t%s:\t%s\n", val_name, type, valstr); break; } } @@ -1566,17 +1595,30 @@ void display_query_svc_cfg(FILE *out_hnd, enum action_type action, { case ACTION_HEADER: { - fprintf(out_hnd, "\tService:\t%s\n", unistr2_to_str(&cfg->uni_display_name)); /* service name unicode string */ + fstring service; + + unistr2_to_ascii(service, &cfg->uni_display_name, sizeof(service)); + fprintf(out_hnd, "\tService:\t%s\n", service); fprintf(out_hnd, "\t-------\n"); break; } case ACTION_ENUMERATE: { - fprintf(out_hnd, "\tPath:\t%s\n" , unistr2_to_str(&cfg->uni_bin_path_name)); - fprintf(out_hnd, "\tLoad Order:\t%s\n" , unistr2_to_str(&cfg->uni_load_order_grp)); - fprintf(out_hnd, "\tDependencies:\t%s\n" , unistr2_to_str(&cfg->uni_dependencies)); - fprintf(out_hnd, "\tService Start:\t%s\n", unistr2_to_str(&cfg->uni_service_start_name)); - fprintf(out_hnd, "\tService Type:\t%d\n" , cfg->service_type); + fstring temp; + + unistr2_to_ascii(temp, &cfg->uni_bin_path_name, sizeof(temp)); + fprintf(out_hnd, "\tPath:\t%s\n", temp); + + unistr2_to_ascii(temp, &cfg->uni_load_order_grp, sizeof(temp)); + fprintf(out_hnd, "\tLoad Order:\t%s\n", temp); + + unistr2_to_ascii(temp, &cfg->uni_dependencies, sizeof(temp)); + fprintf(out_hnd, "\tDependencies:\t%s\n", temp); + + unistr2_to_ascii(temp, &cfg->uni_service_start_name, sizeof(temp)); + fprintf(out_hnd, "\tService Start:\t%s\n", temp); + + fprintf(out_hnd, "\tService Type:\t%d\n", cfg->service_type); fprintf(out_hnd, "\tStart Type:\t%s\n" , get_svc_start_type_str(cfg->start_type)); fprintf(out_hnd, "\tError Control:\t%d\n" , cfg->error_control); fprintf(out_hnd, "\tTag Id:\t%d\n" , cfg->tag_id); @@ -1604,8 +1646,15 @@ void display_svc_info(FILE *out_hnd, enum action_type action, ENUM_SRVC_STATUS * } case ACTION_ENUMERATE: { - fprintf(out_hnd, "\t%s:", unistr2(svc->uni_srvc_name .buffer)); /* service name unicode string */ - fprintf(out_hnd, "\t%s\n", unistr2(svc->uni_disp_name .buffer)); /* display name unicode string */ + fstring name; + + unistr_to_ascii(name, svc->uni_srvc_name.buffer, + sizeof(name)); /* service name */ + fprintf(out_hnd, "\t%s:", name); + + unistr_to_ascii(name, svc->uni_disp_name.buffer, + sizeof(name)); /* display name */ + fprintf(out_hnd, "\t%s\n", name); break; } case ACTION_FOOTER: diff --git a/source3/smbd/chgpasswd.c b/source3/smbd/chgpasswd.c index a2e75ecc431..167fce6e8cb 100644 --- a/source3/smbd/chgpasswd.c +++ b/source3/smbd/chgpasswd.c @@ -691,10 +691,8 @@ BOOL check_oem_password(char *user, * nt passwords are in unicode */ int uni_pw_len = new_pw_len; - char *pw; new_pw_len /= 2; - pw = unistrn2(&lmdata[512-uni_pw_len], new_pw_len); - memcpy(new_passwd, pw, new_pw_len+1); + unibuf_to_ascii(new_passwd, &lmdata[512-uni_pw_len], new_pw_len); } else { diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 7bfb046cc29..1bfcaa5f121 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -1121,7 +1121,7 @@ static int call_trans2qfsinfo(connection_struct *conn, #endif /* Old code. */ SIVAL(pdata,4,128); /* Max filename component length */ SIVAL(pdata,8,2*strlen(fstype)); - PutUniCode(pdata+12,fstype); + ascii_to_unibuf(pdata+12, fstype, 1024-12); SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2)|FLAGS2_UNICODE_STRINGS); break; case SMB_QUERY_FS_LABEL_INFO: @@ -1148,7 +1148,7 @@ static int call_trans2qfsinfo(connection_struct *conn, } else { data_len = 18 + 2*strlen(vname); SIVAL(pdata,12,strlen(vname)*2); - PutUniCode(pdata+18,vname); + ascii_to_unibuf(pdata+18, vname, 1024-18); } DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_FS_VOLUME_INFO namelen = %d, vol = %s\n", @@ -1395,6 +1395,8 @@ static int call_trans2qfilepathinfo(connection_struct *conn, case SMB_QUERY_FILE_ALT_NAME_INFO: { pstring short_name; + char *data_end; + pstrcpy(short_name,p); /* Mangle if not already 8.3 */ if(!is_8_3(short_name, True)) @@ -1403,10 +1405,9 @@ static int call_trans2qfilepathinfo(connection_struct *conn, *short_name = '\0'; } strupper(short_name); - l = strlen(short_name); - PutUniCode(pdata + 4, short_name); - data_size = 4 + (2*l); - SIVAL(pdata,0,2*l); + data_end = ascii_to_unibuf(pdata + 4, short_name, 1024-4); + data_size = data_end - pdata; + SIVAL(pdata,0,2*(data_size-4)); } break; |