summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2001-07-04 07:15:53 +0000
committerAndrew Tridgell <tridge@samba.org>2001-07-04 07:15:53 +0000
commit87fbb7092b8f8b2f0db0f361c3d625e19de57cd9 (patch)
tree3c302f710cbaa03e3c0d46549e8982771b12b8a5 /source3/libsmb
parent9e9e73303ec10a64bd744b9b33f4e6cd7d394f03 (diff)
downloadsamba-87fbb7092b8f8b2f0db0f361c3d625e19de57cd9.tar.gz
samba-87fbb7092b8f8b2f0db0f361c3d625e19de57cd9.tar.bz2
samba-87fbb7092b8f8b2f0db0f361c3d625e19de57cd9.zip
The big character set handling changeover!
This commit gets rid of all our old codepage handling and replaces it with iconv. All internal strings in Samba are now in "unix" charset, which may be multi-byte. See internals.doc and my posting to samba-technical for a more complete explanation. (This used to be commit debb471267960e56005a741817ebd227ecfc512a)
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/cli_lsarpc.c7
-rw-r--r--source3/libsmb/cliconnect.c53
-rw-r--r--source3/libsmb/clierror.c2
-rw-r--r--source3/libsmb/clifile.c26
-rw-r--r--source3/libsmb/clilist.c27
-rw-r--r--source3/libsmb/climessage.c6
-rw-r--r--source3/libsmb/clirap.c26
-rw-r--r--source3/libsmb/clistr.c133
-rw-r--r--source3/libsmb/clitrans.c2
-rw-r--r--source3/libsmb/libsmbclient.c4
-rw-r--r--source3/libsmb/namequery.c7
-rw-r--r--source3/libsmb/nmblib.c4
-rw-r--r--source3/libsmb/pwd_cache.c14
-rw-r--r--source3/libsmb/smbencrypt.c41
-rw-r--r--source3/libsmb/smberr.c8
15 files changed, 94 insertions, 266 deletions
diff --git a/source3/libsmb/cli_lsarpc.c b/source3/libsmb/cli_lsarpc.c
index 88f0dff225..61afeb7f38 100644
--- a/source3/libsmb/cli_lsarpc.c
+++ b/source3/libsmb/cli_lsarpc.c
@@ -268,11 +268,8 @@ uint32 cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
/* Translate optimised name through domain index array */
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);
+ pull_ascii_fstring(dom_name, &ref.ref_dom[dom_idx].uni_dom_name);
+ pull_ascii_fstring(name, &t_names.uni_name[i]);
slprintf(full_name, sizeof(full_name) - 1,
"%s%s%s", dom_name, dom_name[0] ?
diff --git a/source3/libsmb/cliconnect.c b/source3/libsmb/cliconnect.c
index 67eef52583..7ec0627682 100644
--- a/source3/libsmb/cliconnect.c
+++ b/source3/libsmb/cliconnect.c
@@ -26,7 +26,7 @@
static struct {
int prot;
- char *name;
+ const char *name;
}
prots[] =
{
@@ -84,8 +84,7 @@ BOOL cli_session_setup(struct cli_state *cli,
*/
passlen = 24;
ntpasslen = 24;
- fstrcpy(pword, pass);
- unix_to_dos(pword,True);
+ clistr_push(cli, pword, pass, -1, STR_TERMINATE);
fstrcpy(ntpword, ntpass);;
SMBencrypt((uchar *)pword,(uchar *)cli->cryptkey,(uchar *)pword);
SMBNTencrypt((uchar *)ntpword,(uchar *)cli->cryptkey,(uchar *)ntpword);
@@ -104,7 +103,7 @@ BOOL cli_session_setup(struct cli_state *cli,
/*
* Plaintext mode needed, assume plaintext supplied.
*/
- passlen = clistr_push(cli, pword, pass, -1, STR_CONVERT|STR_TERMINATE);
+ passlen = clistr_push(cli, pword, pass, -1, STR_TERMINATE);
fstrcpy(ntpword, "");
ntpasslen = 0;
}
@@ -136,7 +135,7 @@ BOOL cli_session_setup(struct cli_state *cli,
p = smb_buf(cli->outbuf);
memcpy(p,pword,passlen);
p += passlen;
- p += clistr_push(cli, p, user, -1, STR_CONVERT|STR_UPPER|STR_TERMINATE);
+ p += clistr_push(cli, p, user, -1, STR_UPPER|STR_TERMINATE);
cli_setup_bcc(cli, p);
}
else
@@ -167,10 +166,10 @@ BOOL cli_session_setup(struct cli_state *cli,
p += SVAL(cli->outbuf,smb_vwv7);
memcpy(p,ntpword,ntpasslen);
p += SVAL(cli->outbuf,smb_vwv8);
- p += clistr_push(cli, p, user, -1, STR_CONVERT|STR_TERMINATE|STR_UPPER);
- p += clistr_push(cli, p, workgroup, -1, STR_CONVERT|STR_TERMINATE|STR_UPPER);
- p += clistr_push(cli, p, "Unix", -1, STR_CONVERT|STR_TERMINATE);
- p += clistr_push(cli, p, "Samba", -1, STR_CONVERT|STR_TERMINATE);
+ 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);
cli_setup_bcc(cli, p);
}
@@ -193,9 +192,9 @@ BOOL cli_session_setup(struct cli_state *cli,
* info.
*/
char *q = smb_buf(cli->inbuf);
- q += clistr_pull(cli, cli->server_os, q, sizeof(fstring), -1, STR_TERMINATE|STR_CONVERT);
- q += clistr_pull(cli, cli->server_type, q, sizeof(fstring), -1, STR_TERMINATE|STR_CONVERT);
- q += clistr_pull(cli, cli->server_domain, q, sizeof(fstring), -1, STR_TERMINATE|STR_CONVERT);
+ q += clistr_pull(cli, cli->server_os, q, sizeof(fstring), -1, STR_TERMINATE);
+ q += clistr_pull(cli, cli->server_type, q, sizeof(fstring), -1, STR_TERMINATE);
+ q += clistr_pull(cli, cli->server_domain, q, sizeof(fstring), -1, STR_TERMINATE);
}
fstrcpy(cli->user_name, user);
@@ -227,7 +226,7 @@ BOOL cli_ulogoff(struct cli_state *cli)
send a tconX
****************************************************************************/
BOOL cli_send_tconX(struct cli_state *cli,
- char *share, char *dev, char *pass, int passlen)
+ const char *share, const char *dev, const char *pass, int passlen)
{
fstring fullshare, pword, dos_pword;
char *p;
@@ -247,15 +246,15 @@ BOOL cli_send_tconX(struct cli_state *cli,
* Non-encrypted passwords - convert to DOS codepage before encryption.
*/
passlen = 24;
- fstrcpy(dos_pword,pass);
- unix_to_dos(dos_pword,True);
+ clistr_push(cli, dos_pword, pass, -1, STR_TERMINATE);
+
SMBencrypt((uchar *)dos_pword,(uchar *)cli->cryptkey,(uchar *)pword);
} else {
if((cli->sec_mode & 3) == 0) {
/*
* Non-encrypted passwords - convert to DOS codepage before using.
*/
- passlen = clistr_push(cli, pword, pass, -1, STR_CONVERT|STR_TERMINATE);
+ passlen = clistr_push(cli, pword, pass, -1, STR_TERMINATE);
} else {
memcpy(pword, pass, passlen);
}
@@ -263,8 +262,6 @@ BOOL cli_send_tconX(struct cli_state *cli,
slprintf(fullshare, sizeof(fullshare)-1,
"\\\\%s\\%s", cli->desthost, share);
- unix_to_dos(fullshare, True);
- strupper(fullshare);
set_message(cli->outbuf,4, 0, True);
CVAL(cli->outbuf,smb_com) = SMBtconX;
@@ -276,7 +273,7 @@ BOOL cli_send_tconX(struct cli_state *cli,
p = smb_buf(cli->outbuf);
memcpy(p,pword,passlen);
p += passlen;
- p += clistr_push(cli, p, fullshare, -1, STR_CONVERT | STR_TERMINATE);
+ p += clistr_push(cli, p, fullshare, -1, STR_TERMINATE |STR_UPPER);
fstrcpy(p, dev); p += strlen(dev)+1;
cli_setup_bcc(cli, p);
@@ -294,7 +291,7 @@ BOOL cli_send_tconX(struct cli_state *cli,
fstrcpy(cli->dev, "A:");
if (cli->protocol >= PROTOCOL_NT1) {
- clistr_pull(cli, cli->dev, smb_buf(cli->inbuf), sizeof(fstring), -1, STR_TERMINATE | STR_CONVERT);
+ clistr_pull(cli, cli->dev, smb_buf(cli->inbuf), sizeof(fstring), -1, STR_TERMINATE);
}
if (strcasecmp(share,"IPC$")==0) {
@@ -350,9 +347,7 @@ void cli_negprot_send(struct cli_state *cli)
prots[numprots].name && prots[numprots].prot<=cli->protocol;
numprots++) {
*p++ = 2;
- pstrcpy(p,prots[numprots].name);
- unix_to_dos(p,True);
- p += strlen(p) + 1;
+ p += clistr_push(cli, p, prots[numprots].name, -1, STR_TERMINATE);
}
CVAL(cli->outbuf,smb_com) = SMBnegprot;
@@ -389,9 +384,7 @@ BOOL cli_negprot(struct cli_state *cli)
prots[numprots].name && prots[numprots].prot<=cli->protocol;
numprots++) {
*p++ = 2;
- pstrcpy(p,prots[numprots].name);
- unix_to_dos(p,True);
- p += strlen(p) + 1;
+ p += clistr_push(cli, p, prots[numprots].name, -1, STR_TERMINATE);
}
CVAL(cli->outbuf,smb_com) = SMBnegprot;
@@ -433,7 +426,7 @@ BOOL cli_negprot(struct cli_state *cli)
if (smb_buflen(cli->inbuf) > 8) {
clistr_pull(cli, cli->server_domain,
smb_buf(cli->inbuf)+8, sizeof(cli->server_domain),
- smb_buflen(cli->inbuf)-8, STR_CONVERT|STR_UNICODE|STR_NOALIGN);
+ smb_buflen(cli->inbuf)-8, STR_UNICODE|STR_NOALIGN);
}
} else if (cli->protocol >= PROTOCOL_LANMAN1) {
cli->sec_mode = SVAL(cli->inbuf,smb_vwv1);
@@ -762,9 +755,9 @@ BOOL cli_establish_connection(struct cli_state *cli,
if (*cli->server_domain || *cli->server_os || *cli->server_type)
{
DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n",
- cli->server_domain,
- cli->server_os,
- cli->server_type));
+ cli->server_domain,
+ cli->server_os,
+ cli->server_type));
}
if (do_tcon)
diff --git a/source3/libsmb/clierror.c b/source3/libsmb/clierror.c
index 77e2be805b..f533eabb0b 100644
--- a/source3/libsmb/clierror.c
+++ b/source3/libsmb/clierror.c
@@ -120,7 +120,7 @@ char *cli_errstr(struct cli_state *cli)
{
if (rap_errmap[i].err == cli->rap_error)
{
- fstrcpy( error_message, rap_errmap[i].message);
+ fstrcpy(error_message, rap_errmap[i].message);
break;
}
}
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 2c4eef9bbe..215c500c30 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -44,10 +44,10 @@ BOOL cli_rename(struct cli_state *cli, char *fname_src, char *fname_dst)
p = smb_buf(cli->outbuf);
*p++ = 4;
p += clistr_push(cli, p, fname_src, -1,
- STR_TERMINATE | STR_CONVERT);
+ STR_TERMINATE);
*p++ = 4;
p += clistr_push(cli, p, fname_dst, -1,
- STR_TERMINATE | STR_CONVERT);
+ STR_TERMINATE);
cli_setup_bcc(cli, p);
@@ -83,7 +83,7 @@ BOOL cli_unlink(struct cli_state *cli, char *fname)
p = smb_buf(cli->outbuf);
*p++ = 4;
- p += clistr_push(cli, p, fname, -1, STR_TERMINATE | STR_CONVERT);
+ p += clistr_push(cli, p, fname, -1, STR_TERMINATE);
cli_setup_bcc(cli, p);
cli_send_smb(cli);
@@ -116,7 +116,7 @@ BOOL cli_mkdir(struct cli_state *cli, char *dname)
p = smb_buf(cli->outbuf);
*p++ = 4;
- p += clistr_push(cli, p, dname, -1, STR_CONVERT|STR_TERMINATE);
+ p += clistr_push(cli, p, dname, -1, 0);
cli_setup_bcc(cli, p);
@@ -150,7 +150,7 @@ BOOL cli_rmdir(struct cli_state *cli, char *dname)
p = smb_buf(cli->outbuf);
*p++ = 4;
- p += clistr_push(cli, p, dname, -1, STR_TERMINATE|STR_CONVERT);
+ p += clistr_push(cli, p, dname, -1, STR_TERMINATE);
cli_setup_bcc(cli, p);
@@ -243,8 +243,8 @@ int cli_nt_create_full(struct cli_state *cli, char *fname, uint32 DesiredAccess,
p = smb_buf(cli->outbuf);
/* this alignment and termination is critical for netapp filers. Don't change */
- p += clistr_align_out(cli, p, STR_CONVERT);
- len = clistr_push(cli, p, fname, -1, STR_CONVERT);
+ p += clistr_align_out(cli, p, 0);
+ len = clistr_push(cli, p, fname, -1, 0);
p += len;
SSVAL(cli->outbuf,smb_ntcreate_NameLength, len);
/* sigh. this copes with broken netapp filer behaviour */
@@ -336,7 +336,7 @@ int cli_open(struct cli_state *cli, char *fname, int flags, int share_mode)
}
p = smb_buf(cli->outbuf);
- p += clistr_push(cli, p, fname, -1, STR_TERMINATE | STR_CONVERT);
+ p += clistr_push(cli, p, fname, -1, STR_TERMINATE);
cli_setup_bcc(cli, p);
@@ -648,7 +648,7 @@ BOOL cli_getatr(struct cli_state *cli, char *fname,
p = smb_buf(cli->outbuf);
*p++ = 4;
- p += clistr_push(cli, p, fname, -1, STR_TERMINATE | STR_CONVERT);
+ p += clistr_push(cli, p, fname, -1, STR_TERMINATE);
cli_setup_bcc(cli, p);
@@ -699,7 +699,7 @@ BOOL cli_setatr(struct cli_state *cli, char *fname, uint16 attr, time_t t)
p = smb_buf(cli->outbuf);
*p++ = 4;
- p += clistr_push(cli, p, fname, -1, STR_TERMINATE | STR_CONVERT);
+ p += clistr_push(cli, p, fname, -1, STR_TERMINATE);
*p++ = 4;
cli_setup_bcc(cli, p);
@@ -736,7 +736,7 @@ BOOL cli_chkpath(struct cli_state *cli, char *path)
cli_setup_packet(cli);
p = smb_buf(cli->outbuf);
*p++ = 4;
- p += clistr_push(cli, p, path2, -1, STR_TERMINATE | STR_CONVERT);
+ p += clistr_push(cli, p, path2, -1, STR_TERMINATE);
cli_setup_bcc(cli, p);
@@ -796,7 +796,7 @@ int cli_ctemp(struct cli_state *cli, char *path, char **tmp_path)
p = smb_buf(cli->outbuf);
*p++ = 4;
- p += clistr_push(cli, p, path, -1, STR_TERMINATE | STR_CONVERT);
+ p += clistr_push(cli, p, path, -1, STR_TERMINATE);
cli_setup_bcc(cli, p);
@@ -812,7 +812,7 @@ int cli_ctemp(struct cli_state *cli, char *path, char **tmp_path)
if (tmp_path) {
pstring path2;
clistr_pull(cli, path2, smb_buf(cli->inbuf)+1,
- sizeof(path2), -1, STR_TERMINATE | STR_CONVERT);
+ sizeof(path2), -1, STR_TERMINATE);
*tmp_path = strdup(path2);
}
diff --git a/source3/libsmb/clilist.c b/source3/libsmb/clilist.c
index 9080a9c221..b08cc08f01 100644
--- a/source3/libsmb/clilist.c
+++ b/source3/libsmb/clilist.c
@@ -51,7 +51,7 @@ static int interpret_long_filename(struct cli_state *cli,
clistr_pull(cli, finfo->name, p+27,
sizeof(finfo->name),
-1,
- STR_TERMINATE | STR_CONVERT);
+ STR_TERMINATE);
}
return(28 + CVAL(p,26));
@@ -66,7 +66,7 @@ static int interpret_long_filename(struct cli_state *cli,
clistr_pull(cli, finfo->name, p+31,
sizeof(finfo->name),
-1,
- STR_TERMINATE | STR_CONVERT);
+ STR_TERMINATE);
}
return(32 + CVAL(p,30));
@@ -82,7 +82,7 @@ static int interpret_long_filename(struct cli_state *cli,
clistr_pull(cli, finfo->name, p+33,
sizeof(finfo->name),
-1,
- STR_TERMINATE | STR_CONVERT);
+ STR_TERMINATE);
}
return(SVAL(p,4)+4);
@@ -97,7 +97,7 @@ static int interpret_long_filename(struct cli_state *cli,
clistr_pull(cli, finfo->name, p+37,
sizeof(finfo->name),
-1,
- STR_TERMINATE | STR_CONVERT);
+ STR_TERMINATE);
}
return(SVAL(p,4)+4);
@@ -135,7 +135,7 @@ static int interpret_long_filename(struct cli_state *cli,
p += 2;
{
/* stupid NT bugs. grr */
- int flags = STR_CONVERT;
+ int flags = 0;
if (p[1] == 0 && namelen > 1) flags |= STR_UNICODE;
clistr_pull(cli, finfo->short_name, p,
sizeof(finfo->short_name),
@@ -144,8 +144,7 @@ static int interpret_long_filename(struct cli_state *cli,
p += 24; /* short name? */
clistr_pull(cli, finfo->name, p,
sizeof(finfo->name),
- namelen,
- STR_CONVERT);
+ namelen, 0);
return(ret);
}
return(SVAL(p,0));
@@ -203,7 +202,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_CONVERT);
+ STR_TERMINATE);
} else {
setup = TRANSACT2_FINDNEXT;
SSVAL(param,0,ff_dir_handle);
@@ -213,7 +212,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_CONVERT);
+ STR_TERMINATE);
}
param_len = PTR_DIFF(p, param);
@@ -271,15 +270,13 @@ int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute,
clistr_pull(cli, mask, p+ff_lastname,
sizeof(mask),
data_len-ff_lastname,
- STR_TERMINATE |
- STR_CONVERT);
+ STR_TERMINATE);
break;
case 1:
clistr_pull(cli, mask, p+ff_lastname+1,
sizeof(mask),
-1,
- STR_TERMINATE |
- STR_CONVERT);
+ STR_TERMINATE);
break;
}
} else {
@@ -345,7 +342,7 @@ static int interpret_short_filename(struct cli_state *cli, char *p,file_info *fi
finfo->ctime = make_unix_date(p+22);
finfo->mtime = finfo->atime = finfo->ctime;
finfo->size = IVAL(p,26);
- clistr_pull(cli, finfo->name, p+30, sizeof(finfo->name), 12, STR_CONVERT|STR_ASCII);
+ clistr_pull(cli, finfo->name, p+30, sizeof(finfo->name), 12, STR_ASCII);
if (strcmp(finfo->name, "..") && strcmp(finfo->name, "."))
fstrcpy(finfo->short_name,finfo->name);
@@ -392,7 +389,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|STR_CONVERT);
+ p += clistr_push(cli, p, first?mask:"", -1, STR_TERMINATE);
*p++ = 5;
if (first) {
SSVAL(p,0,0);
diff --git a/source3/libsmb/climessage.c b/source3/libsmb/climessage.c
index d46986bfd6..e0a308104b 100644
--- a/source3/libsmb/climessage.c
+++ b/source3/libsmb/climessage.c
@@ -41,11 +41,9 @@ BOOL cli_message_start(struct cli_state *cli, char *host, char *username,
p = smb_buf(cli->outbuf);
*p++ = 4;
- p += clistr_push(cli, p, username, -1,
- STR_TERMINATE|STR_CONVERT);
+ p += clistr_push(cli, p, username, -1, STR_TERMINATE);
*p++ = 4;
- p += clistr_push(cli, p, host, -1,
- STR_TERMINATE|STR_CONVERT);
+ p += clistr_push(cli, p, host, -1, STR_TERMINATE);
cli_setup_bcc(cli, p);
diff --git a/source3/libsmb/clirap.c b/source3/libsmb/clirap.c
index 253d192aba..c16fe2d08d 100644
--- a/source3/libsmb/clirap.c
+++ b/source3/libsmb/clirap.c
@@ -181,8 +181,8 @@ int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, co
char *cmnt = comment_offset?(rdata+comment_offset-converter):"";
pstring s1, s2;
- pstrcpy(s1, dos_to_unix(sname, False));
- pstrcpy(s2, dos_to_unix(cmnt, False));
+ pull_ascii_pstring(s1, sname);
+ pull_ascii_pstring(s2, cmnt);
fn(s1, type, s2, state);
}
@@ -237,8 +237,7 @@ BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
SIVAL(p,0,stype);
p += 4;
- p += clistr_push(cli, p, workgroup, -1,
- STR_TERMINATE | STR_CONVERT | STR_ASCII);
+ p += push_pstring(p, workgroup);
if (cli_api(cli,
param, PTR_DIFF(p,param), 8, /* params, length, max */
@@ -265,8 +264,8 @@ BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
stype = IVAL(p,18) & ~SV_TYPE_LOCAL_LIST_ONLY;
- pstrcpy(s1, dos_to_unix(sname, False));
- pstrcpy(s2, dos_to_unix(cmnt, False));
+ pull_ascii_pstring(s1, sname);
+ pull_ascii_pstring(s2, cmnt);
fn(s1, stype, s2, state);
}
}
@@ -325,13 +324,10 @@ BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char
* use this as the key to make_oem_passwd_hash().
*/
memset(upper_case_old_pw, '\0', sizeof(upper_case_old_pw));
- fstrcpy(upper_case_old_pw, old_password);
- unix_to_dos(upper_case_old_pw,True);
- strupper(upper_case_old_pw);
+ clistr_push(cli, upper_case_old_pw, old_password, -1,STR_TERMINATE|STR_UPPER);
E_P16((uchar *)upper_case_old_pw, old_pw_hash);
- pstrcpy(dos_new_password, new_password);
- unix_to_dos(dos_new_password, True);
+ clistr_push(cli, dos_new_password, new_password, -1, STR_TERMINATE);
if (!make_oem_passwd_hash( data, dos_new_password, old_pw_hash, False))
return False;
@@ -340,9 +336,7 @@ BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char
* Now place the old password hash in the data.
*/
memset(upper_case_new_pw, '\0', sizeof(upper_case_new_pw));
- fstrcpy(upper_case_new_pw, new_password);
- unix_to_dos(upper_case_new_pw,True);
- strupper(upper_case_new_pw);
+ clistr_push(cli, upper_case_new_pw, new_password, -1, STR_TERMINATE|STR_UPPER);
E_P16((uchar *)upper_case_new_pw, new_pw_hash);
@@ -399,7 +393,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 | STR_CONVERT);
+ p += clistr_push(cli, p, fname, sizeof(pstring)-6, STR_TERMINATE);
param_len = PTR_DIFF(p, param);
@@ -475,7 +469,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 | STR_CONVERT);
+ p += clistr_push(cli, p, fname, sizeof(pstring)-6, STR_TERMINATE);
param_len = PTR_DIFF(p, param);
diff --git a/source3/libsmb/clistr.c b/source3/libsmb/clistr.c
index 6dd3b751b4..baec3e5da8 100644
--- a/source3/libsmb/clistr.c
+++ b/source3/libsmb/clistr.c
@@ -19,147 +19,26 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#define NO_SYSLOG
-
#include "includes.h"
-#define UNICODE_FLAG(cli, flags) (!(flags & STR_ASCII) && \
- ((flags & STR_UNICODE || \
- (SVAL(cli->outbuf, smb_flg2) & FLAGS2_UNICODE_STRINGS))))
-
-/****************************************************************************
-copy a string from a char* src to a unicode or ascii
-dos code page destination choosing unicode or ascii based on the
-cli->capabilities flag
-return the number of bytes occupied by the string in the destination
-flags can have:
- STR_TERMINATE means include the null termination
- STR_CONVERT means convert from unix to dos codepage
- STR_UPPER means uppercase in the destination
- STR_ASCII use ascii even with unicode servers
- STR_NOALIGN means don't do alignment
-dest_len is the maximum length allowed in the destination. If dest_len
-is -1 then no maxiumum is used
-****************************************************************************/
int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len, int flags)
{
- int len=0;
-
- /* treat a pstring as "unlimited" length */
- if (dest_len == -1) {
- dest_len = sizeof(pstring);
- }
-
- if (clistr_align_out(cli, dest, flags)) {
- *(char *)dest = 0;
- dest = (void *)((char *)dest + 1);
- dest_len--;
- len++;
- }
-
- if (!UNICODE_FLAG(cli, flags)) {
- /* the server doesn't want unicode */
- safe_strcpy(dest, src, dest_len);
- len = strlen(dest);
- if (flags & STR_TERMINATE) len++;
- if (flags & STR_CONVERT) unix_to_dos(dest,True);
- if (flags & STR_UPPER) strupper(dest);
- return len;
- }
-
- /* the server likes unicode. give it the works */
- if (flags & STR_CONVERT) {
- dos_PutUniCode(dest, src, dest_len, flags & STR_TERMINATE);
- } else {
- ascii_to_unistr(dest, src, dest_len);
- }
- if (flags & STR_UPPER) {
- strupper_w(dest);
- }
- len += strlen(src)*2;
- if (flags & STR_TERMINATE) len += 2;
- return len;
+ return push_string(cli->outbuf, dest, src, dest_len, flags);
}
-/****************************************************************************
-copy a string from a unicode or ascii source (depending on
-cli->capabilities) to a char* destination
-flags can have:
- STR_CONVERT means convert from dos to unix codepage
- STR_TERMINATE means the string in src is null terminated
- STR_UNICODE means to force as unicode
- STR_NOALIGN means don't do alignment
-if STR_TERMINATE is set then src_len is ignored
-src_len is the length of the source area in bytes
-return the number of bytes occupied by the string in src
-****************************************************************************/
-int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len, int src_len, int flags)
+int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len, int src_len,
+ int flags)
{
- int len;
-
- if (dest_len == -1) {
- dest_len = sizeof(pstring);
- }
-
- if (clistr_align_in(cli, src, flags)) {
- src = (const void *)((const char *)src + 1);
- if (src_len > 0) src_len--;
- }
-
- if (!UNICODE_FLAG(cli, flags)) {
- /* the server doesn't want unicode */
- if (flags & STR_TERMINATE) {
- safe_strcpy(dest, src, dest_len);
- len = strlen(src)+1;
- } else {
- if (src_len > dest_len) src_len = dest_len;
- len = src_len;
- memcpy(dest, src, len);
- dest[len] = 0;
- }
- if (flags & STR_CONVERT)
- safe_strcpy(dest,dos_to_unix(dest,False),dest_len);
- return len;
- }
-
- if (flags & STR_TERMINATE) {
- unistr_to_ascii(dest, src, dest_len);
- len = strlen(dest)*2 + 2;
- } else {
- int i, c;
- if (dest_len*2 < src_len) src_len = 2*dest_len;
- for (i=0; i < src_len; i += 2) {
- c = SVAL(src, i);
- *dest++ = c;
- }
- *dest++ = 0;
- len = src_len;
- }
- if (flags & STR_CONVERT)
- safe_strcpy(dest,dos_to_unix(dest,False),dest_len);
- return len;
+ return pull_string(cli->inbuf, dest, src, dest_len, src_len, flags);
}
-/****************************************************************************
-return an alignment of either 0 or 1
-if unicode is not negotiated then return 0
-otherwise return 1 if offset is off
-****************************************************************************/
-static int clistr_align(struct cli_state *cli, char *buf, const void *p, int flags)
-{
- if ((flags & STR_NOALIGN) || !UNICODE_FLAG(cli, flags)) return 0;
- return PTR_DIFF(p, buf) & 1;
-}
-
int clistr_align_out(struct cli_state *cli, const void *p, int flags)
{
- return clistr_align(cli, cli->outbuf, p, flags);
+ return align_string(cli->outbuf, p, flags);
}
int clistr_align_in(struct cli_state *cli, const void *p, int flags)
{
- return clistr_align(cli, cli->inbuf, p, flags);
+ return align_string(cli->inbuf, p, flags);
}
-
-
diff --git a/source3/libsmb/clitrans.c b/source3/libsmb/clitrans.c
index d21d179126..68583c4199 100644
--- a/source3/libsmb/clitrans.c
+++ b/source3/libsmb/clitrans.c
@@ -28,7 +28,7 @@
send a SMB trans or trans2 request
****************************************************************************/
BOOL cli_send_trans(struct cli_state *cli, int trans,
- char *pipe_name,
+ const char *pipe_name,
int fid, int flags,
uint16 *setup, int lsetup, int msetup,
char *param, int lparam, int mparam,
diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c
index bc70dc520b..10444a8ab9 100644
--- a/source3/libsmb/libsmbclient.c
+++ b/source3/libsmb/libsmbclient.c
@@ -446,8 +446,6 @@ int smbc_init(smbc_get_auth_data_fn fn, int debug)
slprintf(my_netbios_name, 16, "smbc%s%d", user, pid);
- charset_initialise();
-
/* Here we would open the smb.conf file if needed ... */
home = getenv("HOME");
@@ -471,8 +469,6 @@ int smbc_init(smbc_get_auth_data_fn fn, int debug)
}
- codepage_initialise(lp_client_code_page()); /* Get a codepage */
-
reopen_logs(); /* Get logging working ... */
name_register_wins(my_netbios_name, 0);
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index 465198dfad..18bf6f4804 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -182,9 +182,7 @@ BOOL name_status_find(int type, struct in_addr to_ip, char *name)
}
if (i == count) return False;
- StrnCpy(name, status[i].name, 15);
-
- dos_to_unix(name, True);
+ pull_ascii(name, status[i].name, 15, 0, STR_TERMINATE);
free(status);
return True;
@@ -1025,7 +1023,8 @@ NT GETDC call, UNICODE, NT domain SID and uncle tom cobbley and all...
mailslot_name = bufp;
bufp += (strlen(bufp) + 1);
bufp = ALIGN2(bufp, buffer);
- bufp += dos_PutUniCode(bufp, srcname, sizeof(buffer) - (bufp - buffer) - 1, True);
+ bufp += push_ucs2(NULL, bufp, srcname, sizeof(buffer) - (bufp - buffer), STR_TERMINATE);
+
SIVAL(bufp,0,1);
SSVAL(bufp,4,0xFFFF);
SSVAL(bufp,6,0xFFFF);
diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c
index 0a6bbe87e2..d3b0e68aef 100644
--- a/source3/libsmb/nmblib.c
+++ b/source3/libsmb/nmblib.c
@@ -831,9 +831,7 @@ void make_nmb_name( struct nmb_name *n, const char *name, int type)
{
extern pstring global_scope;
memset( (char *)n, '\0', sizeof(struct nmb_name) );
- StrnCpy( n->name, name, 15 );
- unix_to_dos(n->name, True);
- strupper( n->name );
+ push_ascii(n->name, name, 15, STR_TERMINATE|STR_UPPER);
n->name_type = (unsigned int)type & 0xFF;
StrnCpy( n->scope, global_scope, 63 );
strupper( n->scope );
diff --git a/source3/libsmb/pwd_cache.c b/source3/libsmb/pwd_cache.c
index 420b49ed2e..37a07a0001 100644
--- a/source3/libsmb/pwd_cache.c
+++ b/source3/libsmb/pwd_cache.c
@@ -145,8 +145,7 @@ void pwd_set_nullpwd(struct pwd_info *pwd)
void pwd_set_cleartext(struct pwd_info *pwd, char *clr)
{
pwd_init(pwd);
- fstrcpy(pwd->password, clr);
- unix_to_dos(pwd->password,True);
+ push_ascii_fstring(pwd->password, clr);
pwd->cleartext = True;
pwd->null_pwd = False;
pwd->crypted = False;
@@ -157,13 +156,9 @@ void pwd_set_cleartext(struct pwd_info *pwd, char *clr)
****************************************************************************/
void pwd_get_cleartext(struct pwd_info *pwd, char *clr)
{
- if (pwd->cleartext)
- {
+ if (pwd->cleartext) {
fstrcpy(clr, pwd->password);
- dos_to_unix(clr, True);
- }
- else
- {
+ } else {
clr[0] = 0;
}
}
@@ -222,8 +217,7 @@ void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr)
pwd_init(pwd);
- pstrcpy(dos_passwd, clr);
- unix_to_dos(dos_passwd, True);
+ push_ascii_pstring(dos_passwd, clr);
nt_lm_owf_gen(dos_passwd, pwd->smb_nt_pwd, pwd->smb_lm_pwd);
pwd->null_pwd = False;
diff --git a/source3/libsmb/smbencrypt.c b/source3/libsmb/smbencrypt.c
index b9827333d8..4cc8261e66 100644
--- a/source3/libsmb/smbencrypt.c
+++ b/source3/libsmb/smbencrypt.c
@@ -207,16 +207,8 @@ BOOL make_oem_passwd_hash(char data[516], const char *passwd, uchar old_pw_hash[
* decrypt. JRA.
*/
generate_random_buffer((unsigned char *)data, 516, False);
- if (unicode)
- {
- /* Note that passwd should be in DOS oem character set. */
- dos_struni2( &data[512 - new_pw_len], passwd, 512);
- }
- else
- {
- /* Note that passwd should be in DOS oem character set. */
- fstrcpy( &data[512 - new_pw_len], passwd);
- }
+ push_string(NULL, &data[512 - new_pw_len], passwd, new_pw_len,
+ STR_NOALIGN | (unicode?STR_UNICODE:STR_ASCII));
SIVAL(data, 512, new_pw_len);
#ifdef DEBUG_PASSWORD
@@ -236,26 +228,19 @@ BOOL encode_pw_buffer(char buffer[516], const char *new_pass,
{
generate_random_buffer(buffer, 516, True);
- if (nt_pass_set)
- {
- /*
- * nt passwords are in unicode. last char overwrites NULL
- * in ascii_to_unibuf, so use SIVAL *afterwards*.
- */
+ if (nt_pass_set) {
new_pw_len *= 2;
- ascii_to_unistr((uint16 *)&buffer[512 - new_pw_len], new_pass,
- new_pw_len);
- }
- else
- {
- memcpy(&buffer[512 - new_pw_len], new_pass, new_pw_len);
+ push_ucs2(NULL, &buffer[512 - new_pw_len], new_pass,
+ new_pw_len, 0);
+ } else {
+ push_ascii(&buffer[512 - new_pw_len], new_pass,
+ new_pw_len, 0);
}
/*
* The length of the new password is in the last 4 bytes of
* the data buffer.
*/
-
SIVAL(buffer, 512, new_pw_len);
return True;
@@ -268,8 +253,6 @@ BOOL decode_pw_buffer(char in_buffer[516], char *new_pwrd,
int new_pwrd_size, uint32 *new_pw_len,
uchar nt_p16[16], uchar p16[16])
{
- char *pw;
-
int uni_pw_len=0;
int byte_len=0;
char unicode_passwd[514];
@@ -304,9 +287,8 @@ BOOL decode_pw_buffer(char in_buffer[516], char *new_pwrd,
return False;
}
+ pull_string(NULL, passwd, &in_buffer[512 - byte_len], -1, byte_len, STR_UNICODE);
uni_pw_len = byte_len/2;
- pw = dos_unistrn2((uint16 *)(&in_buffer[512 - byte_len]), byte_len);
- memcpy(passwd, pw, uni_pw_len);
#ifdef DEBUG_PASSWORD
DEBUG(100,("nt_lm_owf_gen: passwd: "));
@@ -324,7 +306,7 @@ BOOL decode_pw_buffer(char in_buffer[516], char *new_pwrd,
#endif
/* Mangle the passwords into Lanman format */
- memcpy(lm_ascii_passwd, passwd, uni_pw_len);
+ memcpy(lm_ascii_passwd, passwd, byte_len/2);
lm_ascii_passwd[14] = '\0';
strupper(lm_ascii_passwd);
@@ -338,11 +320,10 @@ BOOL decode_pw_buffer(char in_buffer[516], char *new_pwrd,
#endif
/* copy the password and it's length to the return buffer */
- *new_pw_len=uni_pw_len;
+ *new_pw_len = byte_len/2;
memcpy(new_pwrd, passwd, uni_pw_len);
new_pwrd[uni_pw_len]='\0';
-
/* clear out local copy of user's password (just being paranoid). */
ZERO_STRUCT(unicode_passwd);
ZERO_STRUCT(lm_ascii_passwd);
diff --git a/source3/libsmb/smberr.c b/source3/libsmb/smberr.c
index c2d8884d73..924fa76d71 100644
--- a/source3/libsmb/smberr.c
+++ b/source3/libsmb/smberr.c
@@ -164,10 +164,12 @@ char *smb_errstr(char *inbuf)
if (num == err[j].code)
{
if (DEBUGLEVEL > 0)
- slprintf(ret, sizeof(ret) - 1, "%s - %s (%s)",err_classes[i].class,
- err[j].name,err[j].message);
+ slprintf(ret, sizeof(ret) - 1, "%s - %s (%s)",
+ err_classes[i].class,
+ err[j].name,err[j].message);
else
- slprintf(ret, sizeof(ret) - 1, "%s - %s",err_classes[i].class,err[j].name);
+ slprintf(ret, sizeof(ret) - 1, "%s - %s",
+ err_classes[i].class,err[j].name);
return ret;
}
}