SMB client
Copyright (C) Andrew Tridgell 1994-1998
Copyright (C) Simo Sorce 2001-2002
- Copyright (C) Jelmer Vernooij 2003
+ Copyright (C) Jelmer Vernooij 2003-2004
Copyright (C) James J Myers 2003 <myersjj@samba.org>
This program is free software; you can redistribute it and/or modify
*/
#include "includes.h"
-#include "../client/client_proto.h"
+#include "version.h"
+#include "dynconfig.h"
+#include "clilist.h"
+#include "lib/cmdline/popt_common.h"
+#include "librpc/gen_ndr/ndr_srvsvc.h"
+#include "librpc/gen_ndr/ndr_lsa.h"
+#include "libcli/raw/libcliraw.h"
+#include "system/time.h"
+#include "system/dir.h"
+#include "system/filesys.h"
+#include "dlinklist.h"
+
#ifndef REGISTER
#define REGISTER 0
#endif
-struct cli_state *cli;
+struct smbcli_state *cli;
extern BOOL in_client;
static int port = 0;
pstring cur_dir = "\\";
static pstring cd_path = "";
static pstring service;
static pstring desthost;
-static pstring username;
-static pstring password;
-static BOOL use_kerberos;
-static BOOL got_pass;
static char *cmdstr = NULL;
static int io_bufsize = 64512;
static int name_type = 0x20;
static int process_tok(fstring tok);
-static int cmd_help(void);
+static int cmd_help(const char **cmd_ptr);
/* 30 second timeout on most commands */
#define CLIENT_TIMEOUT (30*1000)
static BOOL translation = False;
-static BOOL have_ip;
-
/* clitar bits insert */
extern int blocksize;
extern BOOL tar_inc;
static BOOL recurse = False;
BOOL lowercase = False;
-static struct in_addr dest_ip;
+static const char *dest_ip;
#define SEPARATORS " \t\n\r"
static pstring fileselection = "";
-extern file_info def_finfo;
-
/* timing globals */
-SMB_BIG_UINT get_total_size = 0;
-unsigned int get_total_time_ms = 0;
-static SMB_BIG_UINT put_total_size = 0;
-static unsigned int put_total_time_ms = 0;
+uint64_t get_total_size = 0;
+uint_t get_total_time_ms = 0;
+static uint64_t put_total_size = 0;
+static uint_t put_total_time_ms = 0;
/* totals globals */
static double dir_total;
#define USENMB
/* some forward declarations */
-static struct cli_state *do_connect(const char *server, const char *share);
+static struct smbcli_state *do_connect(const char *server, const char *share, struct cli_credentials *cred);
/*******************************************************************
write to a local file with CR/LF->LF translation if appropriate. return the
number taken from the buffer. This may not equal the number written.
****************************************************************************/
-static int writefile(int f, char *b, int n)
+static int writefile(int f, const void *_b, int n)
{
+ const uint8_t *b = _b;
int i;
if (!translation) {
read from a file with LF->CR/LF translation if appropriate. return the
number read. read approx n bytes.
****************************************************************************/
-static int readfile(char *b, int n, XFILE *f)
+static int readfile(void *_b, int n, XFILE *f)
{
+ uint8_t *b = _b;
int i;
int c;
return x_fread(b,1,n,f);
i = 0;
- while (i < (n - 1) && (i < CLI_BUFFER_SIZE)) {
+ while (i < (n - 1)) {
if ((c = x_getc(f)) == EOF) {
break;
}
int total_len = 0;
int grp_id;
- if (!cli_message_start(cli, desthost, username, &grp_id)) {
- d_printf("message start: %s\n", cli_errstr(cli));
+ if (!smbcli_message_start(cli->tree, desthost, cli_credentials_get_username(cmdline_credentials), &grp_id)) {
+ d_printf("message start: %s\n", smbcli_errstr(cli->tree));
return;
}
int l=0;
int c;
- ZERO_ARRAY(msg);
+ ZERO_STRUCT(msg);
for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) {
if (c == '\n')
msg[l] = c;
}
- if (!cli_message_text(cli, msg, l, grp_id)) {
- d_printf("SMBsendtxt failed (%s)\n",cli_errstr(cli));
+ if (!smbcli_message_text(cli->tree, msg, l, grp_id)) {
+ d_printf("SMBsendtxt failed (%s)\n",smbcli_errstr(cli->tree));
return;
}
else
d_printf("sent %d bytes\n",total_len);
- if (!cli_message_end(cli, grp_id)) {
- d_printf("SMBsendend failed (%s)\n",cli_errstr(cli));
+ if (!smbcli_message_end(cli->tree, grp_id)) {
+ d_printf("SMBsendend failed (%s)\n",smbcli_errstr(cli->tree));
return;
}
}
{
int total, bsize, avail;
- if (!cli_dskattr(cli, &bsize, &total, &avail)) {
- d_printf("Error in dskattr: %s\n",cli_errstr(cli));
+ if (NT_STATUS_IS_ERR(smbcli_dskattr(cli->tree, &bsize, &total, &avail))) {
+ d_printf("Error in dskattr: %s\n",smbcli_errstr(cli->tree));
return 1;
}
/****************************************************************************
show cd/pwd
****************************************************************************/
-static int cmd_pwd(void)
+static int cmd_pwd(const char **cmd_ptr)
{
d_printf("Current directory is %s",service);
d_printf("%s\n",cur_dir);
return 0;
}
+/*
+ convert a string to dos format
+*/
+static void dos_format(char *s)
+{
+ string_replace(s, '/', '\\');
+}
/****************************************************************************
change directory - inner section
dos_clean_name(cur_dir);
if (!strequal(cur_dir,"\\")) {
- if (!cli_chkpath(cli, dname)) {
- d_printf("cd %s: %s\n", dname, cli_errstr(cli));
+ if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, dname))) {
+ d_printf("cd %s: %s\n", dname, smbcli_errstr(cli->tree));
pstrcpy(cur_dir,saved_dir);
}
}
/****************************************************************************
change directory
****************************************************************************/
-static int cmd_cd(void)
+static int cmd_cd(const char **cmd_ptr)
{
fstring buf;
int rc = 0;
- if (next_token_nr(NULL,buf,NULL,sizeof(buf)))
+ if (next_token(cmd_ptr,buf,NULL,sizeof(buf)))
rc = do_cd(buf);
else
d_printf("Current directory is %s\n",cur_dir);
}
+BOOL mask_match(struct smbcli_state *c, const char *string, char *pattern,
+ BOOL is_case_sensitive)
+{
+ fstring p2, s2;
+
+ if (strcmp(string,"..") == 0)
+ string = ".";
+ if (strcmp(pattern,".") == 0)
+ return False;
+
+ if (is_case_sensitive)
+ return ms_fnmatch(pattern, string,
+ c->transport->negotiate.protocol) == 0;
+
+ fstrcpy(p2, pattern);
+ fstrcpy(s2, string);
+ strlower(p2);
+ strlower(s2);
+ return ms_fnmatch(p2, s2, c->transport->negotiate.protocol) == 0;
+}
+
+
+
/*******************************************************************
decide if a file should be operated on
********************************************************************/
-static BOOL do_this_one(file_info *finfo)
+static BOOL do_this_one(struct clilist_file_info *finfo)
{
- if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) return(True);
+ if (finfo->attrib & FILE_ATTRIBUTE_DIRECTORY) return(True);
if (*fileselection &&
!mask_match(cli, finfo->name,fileselection,False)) {
return(False);
}
- if ((archive_level==1 || archive_level==2) && !(finfo->mode & FILE_ATTRIBUTE_ARCHIVE)) {
+ if ((archive_level==1 || archive_level==2) && !(finfo->attrib & FILE_ATTRIBUTE_ARCHIVE)) {
DEBUG(3,("archive %s failed\n", finfo->name));
return(False);
}
return(True);
}
-/*******************************************************************
- Return a string representing an attribute for a file.
-********************************************************************/
-static const char *attrib_string(uint16 mode)
-{
- static fstring attrstr;
- int i, len;
- const struct {
- char c;
- uint16 attr;
- } attr_strs[] = {
- {'V', FILE_ATTRIBUTE_VOLUME},
- {'D', FILE_ATTRIBUTE_DIRECTORY},
- {'A', FILE_ATTRIBUTE_ARCHIVE},
- {'H', FILE_ATTRIBUTE_HIDDEN},
- {'S', FILE_ATTRIBUTE_SYSTEM},
- {'R', FILE_ATTRIBUTE_READONLY},
- {'d', FILE_ATTRIBUTE_DEVICE},
- {'t', FILE_ATTRIBUTE_TEMPORARY},
- {'s', FILE_ATTRIBUTE_SPARSE},
- {'r', FILE_ATTRIBUTE_REPARSE_POINT},
- {'c', FILE_ATTRIBUTE_COMPRESSED},
- {'o', FILE_ATTRIBUTE_OFFLINE},
- {'n', FILE_ATTRIBUTE_NONINDEXED},
- {'e', FILE_ATTRIBUTE_ENCRYPTED}
- };
-
- for (len=i=0; i<ARRAY_SIZE(attr_strs); i++) {
- if (mode & attr_strs[i].attr) {
- attrstr[len++] = attr_strs[i].c;
- }
- }
-
- attrstr[len] = 0;
-
- return(attrstr);
-}
-
/****************************************************************************
display info about a file
****************************************************************************/
-static void display_finfo(file_info *finfo)
+static void display_finfo(struct clilist_file_info *finfo)
{
if (do_this_one(finfo)) {
time_t t = finfo->mtime; /* the time is assumed to be passed as GMT */
+ char *astr = attrib_string(NULL, finfo->attrib);
d_printf(" %-30s%7.7s %8.0f %s",
finfo->name,
- attrib_string(finfo->mode),
+ astr,
(double)finfo->size,
- asctime(LocalTime(&t)));
+ asctime(localtime(&t)));
dir_total += finfo->size;
+ talloc_free(astr);
}
}
/****************************************************************************
accumulate size of a file
****************************************************************************/
-static void do_du(file_info *finfo)
+static void do_du(struct clilist_file_info *finfo)
{
if (do_this_one(finfo)) {
dir_total += finfo->size;
static long do_list_queue_size = 0;
static long do_list_queue_start = 0;
static long do_list_queue_end = 0;
-static void (*do_list_fn)(file_info *);
+static void (*do_list_fn)(struct clilist_file_info *);
/****************************************************************************
functions for do_list_queue
do_list_queue_size *= 2;
DEBUG(4,("enlarging do_list_queue to %d\n",
(int)do_list_queue_size));
- dlq = Realloc(do_list_queue, do_list_queue_size);
+ dlq = realloc_p(do_list_queue, char, do_list_queue_size);
if (! dlq) {
d_printf("failure enlarging do_list_queue to %d bytes\n",
(int)do_list_queue_size);
/****************************************************************************
a helper for do_list
****************************************************************************/
-static void do_list_helper(file_info *f, const char *mask, void *state)
+static void do_list_helper(struct clilist_file_info *f, const char *mask, void *state)
{
- if (f->mode & FILE_ATTRIBUTE_DIRECTORY) {
+ if (f->attrib & FILE_ATTRIBUTE_DIRECTORY) {
if (do_list_dirs && do_this_one(f)) {
do_list_fn(f);
}
/****************************************************************************
-a wrapper around cli_list that adds recursion
+a wrapper around smbcli_list that adds recursion
****************************************************************************/
-void do_list(const char *mask,uint16 attribute,void (*fn)(file_info *),BOOL rec, BOOL dirs)
+void do_list(const char *mask,uint16_t attribute,
+ void (*fn)(struct clilist_file_info *),BOOL rec, BOOL dirs)
{
static int in_do_list = 0;
{
/*
* Need to copy head so that it doesn't become
- * invalid inside the call to cli_list. This
+ * invalid inside the call to smbcli_list. This
* would happen if the list were expanded
* during the call.
* Fix from E. Jay Berkenbilt (ejb@ql.org)
*/
pstring head;
pstrcpy(head, do_list_queue_head());
- cli_list(cli, head, attribute, do_list_helper, NULL);
+ smbcli_list(cli->tree, head, attribute, do_list_helper, NULL);
remove_do_list_queue_head();
if ((! do_list_queue_empty()) && (fn == display_finfo))
{
}
else
{
- if (cli_list(cli, mask, attribute, do_list_helper, NULL) == -1)
+ if (smbcli_list(cli->tree, mask, attribute, do_list_helper, NULL) == -1)
{
- d_printf("%s listing %s\n", cli_errstr(cli), mask);
+ d_printf("%s listing %s\n", smbcli_errstr(cli->tree), mask);
}
}
/****************************************************************************
get a directory listing
****************************************************************************/
-static int cmd_dir(void)
+static int cmd_dir(const char **cmd_ptr)
{
- uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+ uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
pstring mask;
fstring buf;
char *p=buf;
if(mask[strlen(mask)-1]!='\\')
pstrcat(mask,"\\");
- if (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+ if (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
dos_format(p);
if (*p == '\\')
pstrcpy(mask,p);
pstrcat(mask,p);
}
else {
- pstrcat(mask,"*");
+ if (cli->tree->session->transport->negotiate.protocol <=
+ PROTOCOL_LANMAN1) {
+ pstrcat(mask,"*.*");
+ } else {
+ pstrcat(mask,"*");
+ }
}
do_list(mask, attribute, display_finfo, recurse, True);
/****************************************************************************
get a directory listing
****************************************************************************/
-static int cmd_du(void)
+static int cmd_du(const char **cmd_ptr)
{
- uint16 attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+ uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
pstring mask;
fstring buf;
char *p=buf;
if(mask[strlen(mask)-1]!='\\')
pstrcat(mask,"\\");
- if (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+ if (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
dos_format(p);
if (*p == '\\')
pstrcpy(mask,p);
else
pstrcat(mask,p);
} else {
- pstrcat(mask,"*");
+ pstrcat(mask,"\\*");
}
do_list(mask, attribute, do_du, recurse, True);
{
int handle = 0, fnum;
BOOL newhandle = False;
- char *data;
+ uint8_t *data;
struct timeval tp_start;
int read_size = io_bufsize;
- uint16 attr;
+ uint16_t attr;
size_t size;
off_t start = 0;
off_t nread = 0;
GetTimeOfDay(&tp_start);
if (lowercase) {
- strlower(lname);
+ strlower(discard_const_p(char, lname));
}
- fnum = cli_open(cli, rname, O_RDONLY, DENY_NONE);
+ fnum = smbcli_open(cli->tree, rname, O_RDONLY, DENY_NONE);
if (fnum == -1) {
- d_printf("%s opening remote file %s\n",cli_errstr(cli),rname);
+ d_printf("%s opening remote file %s\n",smbcli_errstr(cli->tree),rname);
return 1;
}
handle = fileno(stdout);
} else {
if (reget) {
- handle = sys_open(lname, O_WRONLY|O_CREAT, 0644);
+ handle = open(lname, O_WRONLY|O_CREAT, 0644);
if (handle >= 0) {
- start = sys_lseek(handle, 0, SEEK_END);
+ start = lseek(handle, 0, SEEK_END);
if (start == -1) {
d_printf("Error seeking local file\n");
return 1;
}
}
} else {
- handle = sys_open(lname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ handle = open(lname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
}
newhandle = True;
}
}
- if (!cli_qfileinfo(cli, fnum,
- &attr, &size, NULL, NULL, NULL, NULL, NULL) &&
- !cli_getattrE(cli, fnum,
- &attr, &size, NULL, NULL, NULL)) {
- d_printf("getattrib: %s\n",cli_errstr(cli));
+ if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum,
+ &attr, &size, NULL, NULL, NULL, NULL, NULL)) &&
+ NT_STATUS_IS_ERR(smbcli_getattrE(cli->tree, fnum,
+ &attr, &size, NULL, NULL, NULL))) {
+ d_printf("getattrib: %s\n",smbcli_errstr(cli->tree));
return 1;
}
DEBUG(2,("getting file %s of size %.0f as %s ",
rname, (double)size, lname));
- if(!(data = (char *)malloc(read_size))) {
+ if(!(data = (uint8_t *)malloc(read_size))) {
d_printf("malloc fail for size %d\n", read_size);
- cli_close(cli, fnum);
+ smbcli_close(cli->tree, fnum);
return 1;
}
while (1) {
- int n = cli_read(cli, fnum, data, nread + start, read_size);
+ int n = smbcli_read(cli->tree, fnum, data, nread + start, read_size);
if (n <= 0) break;
SAFE_FREE(data);
- if (!cli_close(cli, fnum)) {
- d_printf("Error %s closing remote file\n",cli_errstr(cli));
+ if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
+ d_printf("Error %s closing remote file\n",smbcli_errstr(cli->tree));
rc = 1;
}
}
if (archive_level >= 2 && (attr & FILE_ATTRIBUTE_ARCHIVE)) {
- cli_setatr(cli, rname, attr & ~(uint16)FILE_ATTRIBUTE_ARCHIVE, 0);
+ smbcli_setatr(cli->tree, rname, attr & ~(uint16_t)FILE_ATTRIBUTE_ARCHIVE, 0);
}
{
/****************************************************************************
get a file
****************************************************************************/
-static int cmd_get(void)
+static int cmd_get(const char **cmd_ptr)
{
pstring lname;
pstring rname;
p = rname + strlen(rname);
- if (!next_token_nr(NULL,p,NULL,sizeof(rname)-strlen(rname))) {
+ if (!next_token(cmd_ptr,p,NULL,sizeof(rname)-strlen(rname))) {
d_printf("get <filename>\n");
return 1;
}
pstrcpy(lname,p);
dos_clean_name(rname);
- next_token_nr(NULL,lname,NULL,sizeof(lname));
+ next_token(cmd_ptr,lname,NULL,sizeof(lname));
return do_get(rname, lname, False);
}
+/****************************************************************************
+ Put up a yes/no prompt.
+****************************************************************************/
+static BOOL yesno(char *p)
+{
+ pstring ans;
+ printf("%s",p);
+
+ if (!fgets(ans,sizeof(ans)-1,stdin))
+ return(False);
+
+ if (*ans == 'y' || *ans == 'Y')
+ return(True);
+
+ return(False);
+}
/****************************************************************************
do a mget operation on one file
****************************************************************************/
-static void do_mget(file_info *finfo)
+static void do_mget(struct clilist_file_info *finfo)
{
pstring rname;
pstring quest;
return;
}
- if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY)
+ if (finfo->attrib & FILE_ATTRIBUTE_DIRECTORY)
slprintf(quest,sizeof(pstring)-1,
"Get directory %s? ",finfo->name);
else
if (prompt && !yesno(quest)) return;
- if (!(finfo->mode & FILE_ATTRIBUTE_DIRECTORY)) {
+ if (!(finfo->attrib & FILE_ATTRIBUTE_DIRECTORY)) {
pstrcpy(rname,cur_dir);
pstrcat(rname,finfo->name);
do_get(rname, finfo->name, False);
pstrcat(cur_dir,finfo->name);
pstrcat(cur_dir,"\\");
- unix_format(finfo->name);
- if (lowercase)
- strlower(finfo->name);
+ string_replace(discard_const_p(char, finfo->name), '\\', '/');
+ if (lowercase) {
+ strlower(discard_const_p(char, finfo->name));
+ }
- if (!directory_exist(finfo->name,NULL) &&
+ if (!directory_exist(finfo->name) &&
mkdir(finfo->name,0777) != 0) {
d_printf("failed to create directory %s\n",finfo->name);
pstrcpy(cur_dir,saved_curdir);
/****************************************************************************
view the file using the pager
****************************************************************************/
-static int cmd_more(void)
+static int cmd_more(const char **cmd_ptr)
{
fstring rname,lname,pager_cmd;
char *pager;
}
close(fd);
- if (!next_token_nr(NULL,rname+strlen(rname),NULL,sizeof(rname)-strlen(rname))) {
+ if (!next_token(cmd_ptr,rname+strlen(rname),NULL,sizeof(rname)-strlen(rname))) {
d_printf("more <filename>\n");
unlink(lname);
return 1;
/****************************************************************************
do a mget command
****************************************************************************/
-static int cmd_mget(void)
+static int cmd_mget(const char **cmd_ptr)
{
- uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+ uint16_t attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
pstring mget_mask;
fstring buf;
char *p=buf;
abort_mget = False;
- while (next_token_nr(NULL,p,NULL,sizeof(buf))) {
+ while (next_token(cmd_ptr,p,NULL,sizeof(buf))) {
pstrcpy(mget_mask,cur_dir);
if(mget_mask[strlen(mget_mask)-1]!='\\')
pstrcat(mget_mask,"\\");
/****************************************************************************
make a directory of name "name"
****************************************************************************/
-static BOOL do_mkdir(char *name)
+static NTSTATUS do_mkdir(char *name)
{
- if (!cli_mkdir(cli, name)) {
+ NTSTATUS status;
+
+ if (NT_STATUS_IS_ERR(status = smbcli_mkdir(cli->tree, name))) {
d_printf("%s making remote directory %s\n",
- cli_errstr(cli),name);
- return(False);
+ smbcli_errstr(cli->tree),name);
+ return status;
}
- return(True);
+ return status;
}
/****************************************************************************
static BOOL do_altname(char *name)
{
const char *altname;
- if (!NT_STATUS_IS_OK(cli_qpathinfo_alt_name(cli, name, &altname))) {
+ if (!NT_STATUS_IS_OK(smbcli_qpathinfo_alt_name(cli->tree, name, &altname))) {
d_printf("%s getting alt name for %s\n",
- cli_errstr(cli),name);
+ smbcli_errstr(cli->tree),name);
return(False);
}
d_printf("%s\n", altname);
/****************************************************************************
Exit client.
****************************************************************************/
-static int cmd_quit(void)
+static int cmd_quit(const char **cmd_ptr)
{
- cli_shutdown(cli);
+ smbcli_shutdown(cli);
exit(0);
/* NOTREACHED */
return 0;
/****************************************************************************
make a directory
****************************************************************************/
-static int cmd_mkdir(void)
+static int cmd_mkdir(const char **cmd_ptr)
{
pstring mask;
fstring buf;
pstrcpy(mask,cur_dir);
- if (!next_token_nr(NULL,p,NULL,sizeof(buf))) {
+ if (!next_token(cmd_ptr,p,NULL,sizeof(buf))) {
if (!recurse)
d_printf("mkdir <dirname>\n");
return 1;
p = strtok(ddir,"/\\");
while (p) {
pstrcat(ddir2,p);
- if (!cli_chkpath(cli, ddir2)) {
+ if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, ddir2))) {
do_mkdir(ddir2);
}
pstrcat(ddir2,"\\");
/****************************************************************************
show alt name
****************************************************************************/
-static int cmd_altname(void)
+static int cmd_altname(const char **cmd_ptr)
{
pstring name;
fstring buf;
pstrcpy(name,cur_dir);
- if (!next_token_nr(NULL,p,NULL,sizeof(buf))) {
+ if (!next_token(cmd_ptr,p,NULL,sizeof(buf))) {
d_printf("altname <file>\n");
return 1;
}
XFILE *f;
size_t start = 0;
off_t nread = 0;
- char *buf = NULL;
+ uint8_t *buf = NULL;
int maxwrite = io_bufsize;
int rc = 0;
GetTimeOfDay(&tp_start);
if (reput) {
- fnum = cli_open(cli, rname, O_RDWR|O_CREAT, DENY_NONE);
+ fnum = smbcli_open(cli->tree, rname, O_RDWR|O_CREAT, DENY_NONE);
if (fnum >= 0) {
- if (!cli_qfileinfo(cli, fnum, NULL, &start, NULL, NULL, NULL, NULL, NULL) &&
- !cli_getattrE(cli, fnum, NULL, &start, NULL, NULL, NULL)) {
- d_printf("getattrib: %s\n",cli_errstr(cli));
+ if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &start, NULL, NULL, NULL, NULL, NULL)) &&
+ NT_STATUS_IS_ERR(smbcli_getattrE(cli->tree, fnum, NULL, &start, NULL, NULL, NULL))) {
+ d_printf("getattrib: %s\n",smbcli_errstr(cli->tree));
return 1;
}
}
} else {
- fnum = cli_open(cli, rname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
+ fnum = smbcli_open(cli->tree, rname, O_RDWR|O_CREAT|O_TRUNC,
+ DENY_NONE);
}
if (fnum == -1) {
- d_printf("%s opening remote file %s\n",cli_errstr(cli),rname);
+ d_printf("%s opening remote file %s\n",smbcli_errstr(cli->tree),rname);
return 1;
}
DEBUG(1,("putting file %s as %s ",lname,
rname));
- buf = (char *)malloc(maxwrite);
+ buf = (uint8_t *)malloc(maxwrite);
if (!buf) {
d_printf("ERROR: Not enough memory!\n");
return 1;
break;
}
- ret = cli_write(cli, fnum, 0, buf, nread + start, n);
+ ret = smbcli_write(cli->tree, fnum, 0, buf, nread + start, n);
if (n != ret) {
- d_printf("Error writing file: %s\n", cli_errstr(cli));
+ d_printf("Error writing file: %s\n", smbcli_errstr(cli->tree));
rc = 1;
break;
}
nread += n;
}
- if (!cli_close(cli, fnum)) {
- d_printf("%s closing remote file %s\n",cli_errstr(cli),rname);
+ if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
+ d_printf("%s closing remote file %s\n",smbcli_errstr(cli->tree),rname);
x_fclose(f);
SAFE_FREE(buf);
return 1;
}
if (f == x_stdin) {
- cli_shutdown(cli);
+ smbcli_shutdown(cli);
exit(0);
}
/****************************************************************************
put a file
****************************************************************************/
-static int cmd_put(void)
+static int cmd_put(const char **cmd_ptr)
{
pstring lname;
pstring rname;
pstrcpy(rname,cur_dir);
pstrcat(rname,"\\");
- if (!next_token_nr(NULL,p,NULL,sizeof(buf))) {
+ if (!next_token(cmd_ptr,p,NULL,sizeof(buf))) {
d_printf("put <filename>\n");
return 1;
}
pstrcpy(lname,p);
- if (next_token_nr(NULL,p,NULL,sizeof(buf)))
+ if (next_token(cmd_ptr,p,NULL,sizeof(buf)))
pstrcat(rname,p);
else
pstrcat(rname,lname);
dos_clean_name(rname);
- {
- SMB_STRUCT_STAT st;
- /* allow '-' to represent stdin
- jdblair, 24.jun.98 */
- if (!file_exist(lname,&st) &&
- (strcmp(lname,"-"))) {
- d_printf("%s does not exist\n",lname);
- return 1;
- }
+ /* allow '-' to represent stdin
+ jdblair, 24.jun.98 */
+ if (!file_exist(lname) && (strcmp(lname,"-"))) {
+ d_printf("%s does not exist\n",lname);
+ return 1;
}
return do_put(rname, lname, False);
/****************************************************************************
set the file selection mask
****************************************************************************/
-static int cmd_select(void)
+static int cmd_select(const char **cmd_ptr)
{
pstrcpy(fileselection,"");
- next_token_nr(NULL,fileselection,NULL,sizeof(fileselection));
+ next_token(cmd_ptr,fileselection,NULL,sizeof(fileselection));
return 0;
}
+/*******************************************************************
+ A readdir wrapper which just returns the file name.
+ ********************************************************************/
+static const char *readdirname(DIR *p)
+{
+ struct dirent *ptr;
+ char *dname;
+
+ if (!p)
+ return(NULL);
+
+ ptr = (struct dirent *)readdir(p);
+ if (!ptr)
+ return(NULL);
+
+ dname = ptr->d_name;
+
+#ifdef NEXT2
+ if (telldir(p) < 0)
+ return(NULL);
+#endif
+
+#ifdef HAVE_BROKEN_READDIR
+ /* using /usr/ucb/cc is BAD */
+ dname = dname - 2;
+#endif
+
+ {
+ static pstring buf;
+ int len = NAMLEN(ptr);
+ memcpy(buf, dname, len);
+ buf[len] = 0;
+ dname = buf;
+ }
+
+ return(dname);
+}
+
/****************************************************************************
Recursive file matching function act as find
match must be always set to True when calling this function
return -1;
}
}
- entry = (struct file_list *) malloc(sizeof (struct file_list));
+ entry = malloc_p(struct file_list);
if (!entry) {
d_printf("Out of memory in file_find\n");
closedir(dir);
/****************************************************************************
mput some files
****************************************************************************/
-static int cmd_mput(void)
+static int cmd_mput(const char **cmd_ptr)
{
fstring buf;
char *p=buf;
- while (next_token_nr(NULL,p,NULL,sizeof(buf))) {
+ while (next_token(cmd_ptr,p,NULL,sizeof(buf))) {
int ret;
struct file_list *temp_list;
char *quest, *lname, *rname;
SAFE_FREE(rname);
if(asprintf(&rname, "%s%s", cur_dir, lname) < 0) break;
dos_format(rname);
- if (!cli_chkpath(cli, rname) &&
- !do_mkdir(rname)) {
+ if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, rname)) &&
+ NT_STATUS_IS_ERR(do_mkdir(rname))) {
DEBUG (0, ("Unable to make dir, skipping..."));
/* Skip the directory */
lname[strlen(lname)-1] = '/';
/****************************************************************************
cancel a print job
****************************************************************************/
-static int cmd_cancel(void)
+static int cmd_cancel(const char **cmd_ptr)
{
fstring buf;
int job;
- if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
d_printf("cancel <jobid> ...\n");
return 1;
}
do {
job = atoi(buf);
do_cancel(job);
- } while (next_token_nr(NULL,buf,NULL,sizeof(buf)));
+ } while (next_token(cmd_ptr,buf,NULL,sizeof(buf)));
return 0;
}
/****************************************************************************
print a file
****************************************************************************/
-static int cmd_print(void)
+static int cmd_print(const char **cmd_ptr)
{
pstring lname;
pstring rname;
char *p;
- if (!next_token_nr(NULL,lname,NULL, sizeof(lname))) {
+ if (!next_token(cmd_ptr,lname,NULL, sizeof(lname))) {
d_printf("print <filename>\n");
return 1;
}
/****************************************************************************
show a print queue
****************************************************************************/
-static int cmd_queue(void)
+static int cmd_queue(const char **cmd_ptr)
{
d_printf("REWRITE: print job queue not implemented\n");
/****************************************************************************
delete some files
****************************************************************************/
-static void do_del(file_info *finfo)
-{
- pstring mask;
-
- pstrcpy(mask,cur_dir);
- pstrcat(mask,finfo->name);
-
- if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY)
- return;
-
- if (!cli_unlink(cli, mask)) {
- d_printf("%s deleting remote file %s\n",cli_errstr(cli),mask);
- }
-}
-
-/****************************************************************************
-delete some files
-****************************************************************************/
-static int cmd_del(void)
+static int cmd_del(const char **cmd_ptr)
{
pstring mask;
fstring buf;
- uint16 attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
+ uint16_t attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
if (recurse)
attribute |= FILE_ATTRIBUTE_DIRECTORY;
pstrcpy(mask,cur_dir);
- if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
d_printf("del <filename>\n");
return 1;
}
pstrcat(mask,buf);
- do_list(mask, attribute,do_del,False,False);
+ if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, mask))) {
+ d_printf("%s deleting remote file %s\n",smbcli_errstr(cli->tree),mask);
+ }
return 0;
}
/****************************************************************************
delete a whole directory tree
****************************************************************************/
-static int cmd_deltree(void)
+static int cmd_deltree(const char **cmd_ptr)
{
pstring dname;
fstring buf;
pstrcpy(dname,cur_dir);
- if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
d_printf("deltree <dirname>\n");
return 1;
}
pstrcat(dname,buf);
- ret = cli_deltree(cli, dname);
+ ret = smbcli_deltree(cli->tree, dname);
if (ret == -1) {
- printf("Failed to delete tree %s - %s\n", dname, cli_errstr(cli));
+ printf("Failed to delete tree %s - %s\n", dname, smbcli_errstr(cli->tree));
return -1;
}
/****************************************************************************
show as much information as possible about a file
****************************************************************************/
-static int cmd_allinfo(void)
+static int cmd_allinfo(const char **cmd_ptr)
{
pstring fname;
fstring buf;
pstrcpy(fname,cur_dir);
- if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
d_printf("allinfo <filename>\n");
return 1;
}
pstrcat(fname,buf);
- mem_ctx = talloc_init(fname);
+ mem_ctx = talloc_init("%s", fname);
/* first a ALL_INFO QPATHINFO */
finfo.generic.level = RAW_FILEINFO_ALL_INFO;
goto done;
}
- d_printf("\tcreate_time: %s\n", nt_time_string(mem_ctx, &finfo.all_info.out.create_time));
- d_printf("\taccess_time: %s\n", nt_time_string(mem_ctx, &finfo.all_info.out.access_time));
- d_printf("\twrite_time: %s\n", nt_time_string(mem_ctx, &finfo.all_info.out.write_time));
- d_printf("\tchange_time: %s\n", nt_time_string(mem_ctx, &finfo.all_info.out.change_time));
+ d_printf("\tcreate_time: %s\n", nt_time_string(mem_ctx, finfo.all_info.out.create_time));
+ d_printf("\taccess_time: %s\n", nt_time_string(mem_ctx, finfo.all_info.out.access_time));
+ d_printf("\twrite_time: %s\n", nt_time_string(mem_ctx, finfo.all_info.out.write_time));
+ d_printf("\tchange_time: %s\n", nt_time_string(mem_ctx, finfo.all_info.out.change_time));
d_printf("\tattrib: 0x%x\n", finfo.all_info.out.attrib);
d_printf("\talloc_size: %lu\n", (unsigned long)finfo.all_info.out.alloc_size);
d_printf("\tsize: %lu\n", (unsigned long)finfo.all_info.out.size);
d_printf("\talt_name: %s\n", finfo.alt_name_info.out.fname.s);
}
- /* dev/inode if available */
+ /* file_id if available */
finfo.generic.level = RAW_FILEINFO_INTERNAL_INFORMATION;
status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
if (NT_STATUS_IS_OK(status)) {
- d_printf("\tdevice 0x%x\n", finfo.internal_information.out.device);
- d_printf("\tinode 0x%x\n", finfo.internal_information.out.inode);
+ d_printf("\tfile_id %.0f\n",
+ (double)finfo.internal_information.out.file_id);
}
/* the EAs, if any */
if (NT_STATUS_IS_OK(status)) {
int i;
for (i=0;i<finfo.all_eas.out.num_eas;i++) {
- d_printf("\tEA[%d] flags=%d %s=%*.*s\n", i,
+ d_printf("\tEA[%d] flags=%d len=%d '%s'\n", i,
finfo.all_eas.out.eas[i].flags,
- finfo.all_eas.out.eas[i].name.s,
finfo.all_eas.out.eas[i].value.length,
- finfo.all_eas.out.eas[i].value.length,
- finfo.all_eas.out.eas[i].value.data);
+ finfo.all_eas.out.eas[i].name.s);
}
}
d_printf("\tcluster_shift %ld\n", (long)finfo.compression_info.out.cluster_shift);
}
- talloc_destroy(mem_ctx);
+ talloc_free(mem_ctx);
+
+done:
+ return ret;
+}
+
+
+/****************************************************************************
+shows EA contents
+****************************************************************************/
+static int cmd_eainfo(const char **cmd_ptr)
+{
+ pstring fname;
+ fstring buf;
+ int ret = 0;
+ TALLOC_CTX *mem_ctx;
+ union smb_fileinfo finfo;
+ NTSTATUS status;
+ int i;
+
+ pstrcpy(fname,cur_dir);
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("eainfo <filename>\n");
+ return 1;
+ }
+ pstrcat(fname,buf);
+
+ mem_ctx = talloc_init("%s", fname);
+
+ finfo.generic.in.fname = fname;
+ finfo.generic.level = RAW_FILEINFO_ALL_EAS;
+ status = smb_raw_pathinfo(cli->tree, mem_ctx, &finfo);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("RAW_FILEINFO_ALL_EAS - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ d_printf("%s has %d EAs\n", fname, finfo.all_eas.out.num_eas);
+
+ for (i=0;i<finfo.all_eas.out.num_eas;i++) {
+ d_printf("\tEA[%d] flags=%d len=%d '%s'\n", i,
+ finfo.all_eas.out.eas[i].flags,
+ finfo.all_eas.out.eas[i].value.length,
+ finfo.all_eas.out.eas[i].name.s);
+ fflush(stdout);
+ dump_data(0,
+ finfo.all_eas.out.eas[i].value.data,
+ finfo.all_eas.out.eas[i].value.length);
+ }
+
+ talloc_free(mem_ctx);
+
+ return ret;
+}
+
+
+/****************************************************************************
+show any ACL on a file
+****************************************************************************/
+static int cmd_acl(const char **cmd_ptr)
+{
+ pstring fname;
+ fstring buf;
+ int ret = 0;
+ TALLOC_CTX *mem_ctx;
+ union smb_fileinfo query;
+ NTSTATUS status;
+ int fnum;
+
+ pstrcpy(fname,cur_dir);
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("acl <filename>\n");
+ return 1;
+ }
+ pstrcat(fname,buf);
+
+ fnum = smbcli_nt_create_full(cli->tree, fname, 0,
+ SEC_STD_READ_CONTROL,
+ 0,
+ NTCREATEX_SHARE_ACCESS_DELETE|
+ NTCREATEX_SHARE_ACCESS_READ|
+ NTCREATEX_SHARE_ACCESS_WRITE,
+ NTCREATEX_DISP_OPEN,
+ 0, 0);
+ if (fnum == -1) {
+ d_printf("%s - %s\n", fname, smbcli_errstr(cli->tree));
+ return -1;
+ }
+
+ mem_ctx = talloc_init("%s", fname);
+
+ query.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ query.query_secdesc.in.fnum = fnum;
+ query.query_secdesc.in.secinfo_flags = 0x7;
+
+ status = smb_raw_fileinfo(cli->tree, mem_ctx, &query);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("%s - %s\n", fname, nt_errstr(status));
+ ret = 1;
+ goto done;
+ }
+
+ NDR_PRINT_DEBUG(security_descriptor, query.query_secdesc.out.sd);
+
+ talloc_free(mem_ctx);
done:
return ret;
}
+/****************************************************************************
+lookup a name or sid
+****************************************************************************/
+static int cmd_lookup(const char **cmd_ptr)
+{
+ fstring buf;
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
+ NTSTATUS status;
+ struct dom_sid *sid;
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("lookup <sid|name>\n");
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ sid = dom_sid_parse_talloc(mem_ctx, buf);
+ if (sid == NULL) {
+ const char *sidstr;
+ status = smblsa_lookup_name(cli, buf, mem_ctx, &sidstr);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_LookupNames - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ d_printf("%s\n", sidstr);
+ } else {
+ const char *name;
+ status = smblsa_lookup_sid(cli, buf, mem_ctx, &name);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_LookupSids - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ d_printf("%s\n", name);
+ }
+
+ talloc_free(mem_ctx);
+
+ return 0;
+}
+
+/****************************************************************************
+show privileges for a user
+****************************************************************************/
+static int cmd_privileges(const char **cmd_ptr)
+{
+ fstring buf;
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
+ NTSTATUS status;
+ struct dom_sid *sid;
+ struct lsa_RightSet rights;
+ unsigned i;
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("privileges <sid|name>\n");
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ sid = dom_sid_parse_talloc(mem_ctx, buf);
+ if (sid == NULL) {
+ const char *sid_str;
+ status = smblsa_lookup_name(cli, buf, mem_ctx, &sid_str);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_LookupNames - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+ sid = dom_sid_parse_talloc(mem_ctx, sid_str);
+ }
+
+ status = smblsa_sid_privileges(cli, sid, mem_ctx, &rights);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_EnumAccountRights - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ for (i=0;i<rights.count;i++) {
+ d_printf("\t%s\n", rights.names[i].string);
+ }
+
+ talloc_free(mem_ctx);
+
+ return 0;
+}
+
/****************************************************************************
+add privileges for a user
****************************************************************************/
-static int cmd_open(void)
+static int cmd_addprivileges(const char **cmd_ptr)
+{
+ fstring buf;
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
+ NTSTATUS status;
+ struct dom_sid *sid;
+ struct lsa_RightSet rights;
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("addprivileges <sid|name> <privilege...>\n");
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ sid = dom_sid_parse_talloc(mem_ctx, buf);
+ if (sid == NULL) {
+ const char *sid_str;
+ status = smblsa_lookup_name(cli, buf, mem_ctx, &sid_str);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_LookupNames - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+ sid = dom_sid_parse_talloc(mem_ctx, sid_str);
+ }
+
+ ZERO_STRUCT(rights);
+ while (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ rights.names = talloc_realloc(mem_ctx, rights.names,
+ struct lsa_String, rights.count+1);
+ rights.names[rights.count].string = talloc_strdup(mem_ctx, buf);
+ rights.count++;
+ }
+
+
+ status = smblsa_sid_add_privileges(cli, sid, mem_ctx, &rights);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_AddAccountRights - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ talloc_free(mem_ctx);
+
+ return 0;
+}
+
+/****************************************************************************
+delete privileges for a user
+****************************************************************************/
+static int cmd_delprivileges(const char **cmd_ptr)
+{
+ fstring buf;
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
+ NTSTATUS status;
+ struct dom_sid *sid;
+ struct lsa_RightSet rights;
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("delprivileges <sid|name> <privilege...>\n");
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ sid = dom_sid_parse_talloc(mem_ctx, buf);
+ if (sid == NULL) {
+ const char *sid_str;
+ status = smblsa_lookup_name(cli, buf, mem_ctx, &sid_str);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_LookupNames - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+ sid = dom_sid_parse_talloc(mem_ctx, sid_str);
+ }
+
+ ZERO_STRUCT(rights);
+ while (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ rights.names = talloc_realloc(mem_ctx, rights.names,
+ struct lsa_String, rights.count+1);
+ rights.names[rights.count].string = talloc_strdup(mem_ctx, buf);
+ rights.count++;
+ }
+
+
+ status = smblsa_sid_del_privileges(cli, sid, mem_ctx, &rights);
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("lsa_RemoveAccountRights - %s\n", nt_errstr(status));
+ talloc_free(mem_ctx);
+ return 1;
+ }
+
+ talloc_free(mem_ctx);
+
+ return 0;
+}
+
+
+/****************************************************************************
+****************************************************************************/
+static int cmd_open(const char **cmd_ptr)
{
pstring mask;
fstring buf;
pstrcpy(mask,cur_dir);
- if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
d_printf("open <filename>\n");
return 1;
}
pstrcat(mask,buf);
- cli_open(cli, mask, O_RDWR, DENY_ALL);
+ smbcli_open(cli->tree, mask, O_RDWR, DENY_ALL);
return 0;
}
/****************************************************************************
remove a directory
****************************************************************************/
-static int cmd_rmdir(void)
+static int cmd_rmdir(const char **cmd_ptr)
{
pstring mask;
fstring buf;
pstrcpy(mask,cur_dir);
- if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
d_printf("rmdir <dirname>\n");
return 1;
}
pstrcat(mask,buf);
- if (!cli_rmdir(cli, mask)) {
+ if (NT_STATUS_IS_ERR(smbcli_rmdir(cli->tree, mask))) {
d_printf("%s removing remote directory file %s\n",
- cli_errstr(cli),mask);
+ smbcli_errstr(cli->tree),mask);
}
return 0;
/****************************************************************************
UNIX hardlink.
****************************************************************************/
-static int cmd_link(void)
+static int cmd_link(const char **cmd_ptr)
{
pstring src,dest;
fstring buf,buf2;
pstrcpy(src,cur_dir);
pstrcpy(dest,cur_dir);
- if (!next_token(NULL,buf,NULL,sizeof(buf)) ||
- !next_token(NULL,buf2,NULL, sizeof(buf2))) {
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)) ||
+ !next_token(cmd_ptr,buf2,NULL, sizeof(buf2))) {
d_printf("link <src> <dest>\n");
return 1;
}
pstrcat(src,buf);
pstrcat(dest,buf2);
- if (!cli_unix_hardlink(cli, src, dest)) {
- d_printf("%s linking files (%s -> %s)\n", cli_errstr(cli), src, dest);
+ if (NT_STATUS_IS_ERR(smbcli_unix_hardlink(cli->tree, src, dest))) {
+ d_printf("%s linking files (%s -> %s)\n", smbcli_errstr(cli->tree), src, dest);
return 1;
}
UNIX symlink.
****************************************************************************/
-static int cmd_symlink(void)
+static int cmd_symlink(const char **cmd_ptr)
{
pstring src,dest;
fstring buf,buf2;
pstrcpy(src,cur_dir);
pstrcpy(dest,cur_dir);
- if (!next_token(NULL,buf,NULL,sizeof(buf)) ||
- !next_token(NULL,buf2,NULL, sizeof(buf2))) {
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)) ||
+ !next_token(cmd_ptr,buf2,NULL, sizeof(buf2))) {
d_printf("symlink <src> <dest>\n");
return 1;
}
pstrcat(src,buf);
pstrcat(dest,buf2);
- if (!cli_unix_symlink(cli, src, dest)) {
+ if (NT_STATUS_IS_ERR(smbcli_unix_symlink(cli->tree, src, dest))) {
d_printf("%s symlinking files (%s -> %s)\n",
- cli_errstr(cli), src, dest);
+ smbcli_errstr(cli->tree), src, dest);
return 1;
}
UNIX chmod.
****************************************************************************/
-static int cmd_chmod(void)
+static int cmd_chmod(const char **cmd_ptr)
{
pstring src;
mode_t mode;
pstrcpy(src,cur_dir);
- if (!next_token(NULL,buf,NULL,sizeof(buf)) ||
- !next_token(NULL,buf2,NULL, sizeof(buf2))) {
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)) ||
+ !next_token(cmd_ptr,buf2,NULL, sizeof(buf2))) {
d_printf("chmod mode file\n");
return 1;
}
mode = (mode_t)strtol(buf, NULL, 8);
pstrcat(src,buf2);
- if (!cli_unix_chmod(cli, src, mode)) {
+ if (NT_STATUS_IS_ERR(smbcli_unix_chmod(cli->tree, src, mode))) {
d_printf("%s chmod file %s 0%o\n",
- cli_errstr(cli), src, (unsigned int)mode);
+ smbcli_errstr(cli->tree), src, (uint_t)mode);
return 1;
}
UNIX chown.
****************************************************************************/
-static int cmd_chown(void)
+static int cmd_chown(const char **cmd_ptr)
{
pstring src;
uid_t uid;
pstrcpy(src,cur_dir);
- if (!next_token(NULL,buf,NULL,sizeof(buf)) ||
- !next_token(NULL,buf2,NULL, sizeof(buf2)) ||
- !next_token(NULL,buf3,NULL, sizeof(buf3))) {
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)) ||
+ !next_token(cmd_ptr,buf2,NULL, sizeof(buf2)) ||
+ !next_token(cmd_ptr,buf3,NULL, sizeof(buf3))) {
d_printf("chown uid gid file\n");
return 1;
}
gid = (gid_t)atoi(buf2);
pstrcat(src,buf3);
- if (!cli_unix_chown(cli, src, uid, gid)) {
+ if (NT_STATUS_IS_ERR(smbcli_unix_chown(cli->tree, src, uid, gid))) {
d_printf("%s chown file %s uid=%d, gid=%d\n",
- cli_errstr(cli), src, (int)uid, (int)gid);
+ smbcli_errstr(cli->tree), src, (int)uid, (int)gid);
return 1;
}
/****************************************************************************
rename some files
****************************************************************************/
-static int cmd_rename(void)
+static int cmd_rename(const char **cmd_ptr)
{
pstring src,dest;
fstring buf,buf2;
pstrcpy(src,cur_dir);
pstrcpy(dest,cur_dir);
- if (!next_token_nr(NULL,buf,NULL,sizeof(buf)) ||
- !next_token_nr(NULL,buf2,NULL, sizeof(buf2))) {
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf)) ||
+ !next_token(cmd_ptr,buf2,NULL, sizeof(buf2))) {
d_printf("rename <src> <dest>\n");
return 1;
}
pstrcat(src,buf);
pstrcat(dest,buf2);
- if (!cli_rename(cli, src, dest)) {
- d_printf("%s renaming files\n",cli_errstr(cli));
+ if (NT_STATUS_IS_ERR(smbcli_rename(cli->tree, src, dest))) {
+ d_printf("%s renaming files\n",smbcli_errstr(cli->tree));
return 1;
}
/****************************************************************************
toggle the prompt flag
****************************************************************************/
-static int cmd_prompt(void)
+static int cmd_prompt(const char **cmd_ptr)
{
prompt = !prompt;
DEBUG(2,("prompting is now %s\n",prompt?"on":"off"));
/****************************************************************************
set the newer than time
****************************************************************************/
-static int cmd_newer(void)
+static int cmd_newer(const char **cmd_ptr)
{
fstring buf;
BOOL ok;
- SMB_STRUCT_STAT sbuf;
+ struct stat sbuf;
- ok = next_token_nr(NULL,buf,NULL,sizeof(buf));
- if (ok && (sys_stat(buf,&sbuf) == 0)) {
+ ok = next_token(cmd_ptr,buf,NULL,sizeof(buf));
+ if (ok && (stat(buf,&sbuf) == 0)) {
newer_than = sbuf.st_mtime;
DEBUG(1,("Getting files newer than %s",
- asctime(LocalTime(&newer_than))));
+ asctime(localtime(&newer_than))));
} else {
newer_than = 0;
}
/****************************************************************************
set the archive level
****************************************************************************/
-static int cmd_archive(void)
+static int cmd_archive(const char **cmd_ptr)
{
fstring buf;
- if (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+ if (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
archive_level = atoi(buf);
} else
d_printf("Archive level is %d\n",archive_level);
/****************************************************************************
toggle the lowercaseflag
****************************************************************************/
-static int cmd_lowercase(void)
+static int cmd_lowercase(const char **cmd_ptr)
{
lowercase = !lowercase;
DEBUG(2,("filename lowercasing is now %s\n",lowercase?"on":"off"));
/****************************************************************************
toggle the recurse flag
****************************************************************************/
-static int cmd_recurse(void)
+static int cmd_recurse(const char **cmd_ptr)
{
recurse = !recurse;
DEBUG(2,("directory recursion is now %s\n",recurse?"on":"off"));
/****************************************************************************
toggle the translate flag
****************************************************************************/
-static int cmd_translate(void)
+static int cmd_translate(const char **cmd_ptr)
{
translation = !translation;
DEBUG(2,("CR/LF<->LF and print text translation now %s\n",
/****************************************************************************
do a printmode command
****************************************************************************/
-static int cmd_printmode(void)
+static int cmd_printmode(const char **cmd_ptr)
{
fstring buf;
fstring mode;
- if (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+ if (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
if (strequal(buf,"text")) {
printmode = 0;
} else {
/****************************************************************************
do the lcd command
****************************************************************************/
-static int cmd_lcd(void)
+static int cmd_lcd(const char **cmd_ptr)
{
fstring buf;
pstring d;
- if (next_token_nr(NULL,buf,NULL,sizeof(buf)))
+ if (next_token(cmd_ptr,buf,NULL,sizeof(buf)))
chdir(buf);
DEBUG(2,("the local directory is now %s\n",sys_getwd(d)));
/****************************************************************************
get a file restarting at end of local file
****************************************************************************/
-static int cmd_reget(void)
+static int cmd_reget(const char **cmd_ptr)
{
pstring local_name;
pstring remote_name;
p = remote_name + strlen(remote_name);
- if (!next_token_nr(NULL, p, NULL, sizeof(remote_name) - strlen(remote_name))) {
+ if (!next_token(cmd_ptr, p, NULL, sizeof(remote_name) - strlen(remote_name))) {
d_printf("reget <filename>\n");
return 1;
}
pstrcpy(local_name, p);
dos_clean_name(remote_name);
- next_token_nr(NULL, local_name, NULL, sizeof(local_name));
+ next_token(cmd_ptr, local_name, NULL, sizeof(local_name));
return do_get(remote_name, local_name, True);
}
/****************************************************************************
put a file restarting at end of local file
****************************************************************************/
-static int cmd_reput(void)
+static int cmd_reput(const char **cmd_ptr)
{
pstring local_name;
pstring remote_name;
fstring buf;
char *p = buf;
- SMB_STRUCT_STAT st;
pstrcpy(remote_name, cur_dir);
pstrcat(remote_name, "\\");
- if (!next_token_nr(NULL, p, NULL, sizeof(buf))) {
+ if (!next_token(cmd_ptr, p, NULL, sizeof(buf))) {
d_printf("reput <filename>\n");
return 1;
}
pstrcpy(local_name, p);
- if (!file_exist(local_name, &st)) {
+ if (!file_exist(local_name)) {
d_printf("%s does not exist\n", local_name);
return 1;
}
- if (next_token_nr(NULL, p, NULL, sizeof(buf)))
+ if (next_token(cmd_ptr, p, NULL, sizeof(buf)))
pstrcat(remote_name, p);
else
pstrcat(remote_name, local_name);
}
+/*
+ return a string representing a share type
+*/
+static const char *share_type_str(uint32_t type)
+{
+ switch (type & 0xF) {
+ case STYPE_DISKTREE:
+ return "Disk";
+ case STYPE_PRINTQ:
+ return "Printer";
+ case STYPE_DEVICE:
+ return "Device";
+ case STYPE_IPC:
+ return "IPC";
+ default:
+ return "Unknown";
+ }
+}
+
+
+/*
+ display a list of shares from a level 1 share enum
+*/
+static void display_share_result(struct srvsvc_NetShareCtr1 *ctr1)
+{
+ int i;
+
+ for (i=0;i<ctr1->count;i++) {
+ struct srvsvc_NetShareInfo1 *info = ctr1->array+i;
+
+ printf("\t%-15s %-10.10s %s\n",
+ info->name,
+ share_type_str(info->type),
+ info->comment);
+ }
+}
+
+
+
/****************************************************************************
-try and browse available connections on a host
+try and browse available shares on a host
****************************************************************************/
-static BOOL browse_host(BOOL sort)
+static BOOL browse_host(const char *query_host)
{
- d_printf("REWRITE: host browsing not implemented\n");
+ struct dcerpc_pipe *p;
+ char *binding;
+ NTSTATUS status;
+ struct srvsvc_NetShareEnumAll r;
+ uint32_t resume_handle = 0;
+ TALLOC_CTX *mem_ctx = talloc_init("browse_host");
+ struct srvsvc_NetShareCtr1 ctr1;
+
+ binding = talloc_asprintf(mem_ctx, "ncacn_np:%s", query_host);
+
+ status = dcerpc_pipe_connect(&p, binding,
+ DCERPC_SRVSVC_UUID,
+ DCERPC_SRVSVC_VERSION,
+ lp_netbios_name(),
+ cli_credentials_get_domain(cmdline_credentials),
+ cli_credentials_get_username(cmdline_credentials),
+ cli_credentials_get_password(cmdline_credentials));
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Failed to connect to %s - %s\n",
+ binding, nt_errstr(status));
+ talloc_free(mem_ctx);
+ return False;
+ }
+ talloc_steal(mem_ctx, p);
+
+ r.in.server_unc = talloc_asprintf(mem_ctx,"\\\\%s",dcerpc_server_name(p));
+ r.in.level = 1;
+ r.in.ctr.ctr1 = &ctr1;
+ r.in.max_buffer = ~0;
+ r.in.resume_handle = &resume_handle;
+
+ d_printf("\n\tSharename Type Comment\n");
+ d_printf("\t--------- ---- -------\n");
+
+ do {
+ ZERO_STRUCT(ctr1);
+ status = dcerpc_srvsvc_NetShareEnumAll(p, mem_ctx, &r);
+
+ if (NT_STATUS_IS_OK(status) &&
+ (W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA) ||
+ W_ERROR_IS_OK(r.out.result)) &&
+ r.out.ctr.ctr1) {
+ display_share_result(r.out.ctr.ctr1);
+ resume_handle += r.out.ctr.ctr1->count;
+ }
+ } while (NT_STATUS_IS_OK(status) && W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA));
+
+ talloc_free(mem_ctx);
+
+ if (!NT_STATUS_IS_OK(status) || !W_ERROR_IS_OK(r.out.result)) {
+ d_printf("Failed NetShareEnumAll %s - %s/%s\n",
+ binding, nt_errstr(status), win_errstr(r.out.result));
+ return False;
+ }
return False;
}
/****************************************************************************
try and browse available connections on a host
****************************************************************************/
-static BOOL list_servers(char *wk_grp)
+static BOOL list_servers(const char *wk_grp)
{
d_printf("REWRITE: list servers not implemented\n");
return False;
static struct
{
const char *name;
- int (*fn)(void);
+ int (*fn)(const char **cmd_ptr);
const char *description;
char compl_args[2]; /* Completion argument info */
} commands[] =
{
{"?",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
+ {"addprivileges",cmd_addprivileges,"<sid|name> <privilege...> add privileges for a user",{COMPL_NONE,COMPL_NONE}},
{"altname",cmd_altname,"<file> show alt name",{COMPL_NONE,COMPL_NONE}},
+ {"acl",cmd_acl,"<file> show file ACL",{COMPL_NONE,COMPL_NONE}},
{"allinfo",cmd_allinfo,"<file> show all possible info about a file",{COMPL_NONE,COMPL_NONE}},
{"archive",cmd_archive,"<level>\n0=ignore archive bit\n1=only get archive files\n2=only get archive files and reset archive bit\n3=get all files and reset archive bit",{COMPL_NONE,COMPL_NONE}},
- {"blocksize",cmd_block,"blocksize <number> (default 20)",{COMPL_NONE,COMPL_NONE}},
{"cancel",cmd_cancel,"<jobid> cancel a print queue entry",{COMPL_NONE,COMPL_NONE}},
{"cd",cmd_cd,"[directory] change/report the remote directory",{COMPL_REMOTE,COMPL_NONE}},
{"chmod",cmd_chmod,"<src> <mode> chmod a file using UNIX permission",{COMPL_REMOTE,COMPL_REMOTE}},
{"chown",cmd_chown,"<src> <uid> <gid> chown a file using UNIX uids and gids",{COMPL_REMOTE,COMPL_REMOTE}},
{"del",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
+ {"delprivileges",cmd_delprivileges,"<sid|name> <privilege...> remove privileges for a user",{COMPL_NONE,COMPL_NONE}},
{"deltree",cmd_deltree,"<dir> delete a whole directory tree",{COMPL_REMOTE,COMPL_NONE}},
{"dir",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
{"du",cmd_du,"<mask> computes the total size of the current directory",{COMPL_REMOTE,COMPL_NONE}},
+ {"eainfo",cmd_eainfo,"<file> show EA contents for a file",{COMPL_NONE,COMPL_NONE}},
{"exit",cmd_quit,"logoff the server",{COMPL_NONE,COMPL_NONE}},
{"get",cmd_get,"<remote name> [local name] get a file",{COMPL_REMOTE,COMPL_LOCAL}},
{"help",cmd_help,"[command] give help on a command",{COMPL_NONE,COMPL_NONE}},
{"history",cmd_history,"displays the command history",{COMPL_NONE,COMPL_NONE}},
{"lcd",cmd_lcd,"[directory] change/report the local current working directory",{COMPL_LOCAL,COMPL_NONE}},
{"link",cmd_link,"<src> <dest> create a UNIX hard link",{COMPL_REMOTE,COMPL_REMOTE}},
+ {"lookup",cmd_lookup,"<sid|name> show SID for name or name for SID",{COMPL_NONE,COMPL_NONE}},
{"lowercase",cmd_lowercase,"toggle lowercasing of filenames for get",{COMPL_NONE,COMPL_NONE}},
{"ls",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
{"mask",cmd_select,"<mask> mask all filenames against this",{COMPL_REMOTE,COMPL_NONE}},
{"mput",cmd_mput,"<mask> put all matching files",{COMPL_REMOTE,COMPL_NONE}},
{"newer",cmd_newer,"<file> only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}},
{"open",cmd_open,"<mask> open a file",{COMPL_REMOTE,COMPL_NONE}},
+ {"privileges",cmd_privileges,"<user> show privileges for a user",{COMPL_NONE,COMPL_NONE}},
{"print",cmd_print,"<file name> print a file",{COMPL_NONE,COMPL_NONE}},
{"printmode",cmd_printmode,"<graphics or text> set the print mode",{COMPL_NONE,COMPL_NONE}},
{"prompt",cmd_prompt,"toggle prompting for filenames for mget and mput",{COMPL_NONE,COMPL_NONE}},
{"reput",cmd_reput,"<local name> [remote name] put a file restarting at end of remote file",{COMPL_LOCAL,COMPL_REMOTE}},
{"rm",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
{"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
- {"setmode",cmd_setmode,"filename <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
{"symlink",cmd_symlink,"<src> <dest> create a UNIX symlink",{COMPL_REMOTE,COMPL_REMOTE}},
- {"tar",cmd_tar,"tar <c|x>[IXFqbgNan] current directory to/from <file name>",{COMPL_NONE,COMPL_NONE}},
- {"tarmode",cmd_tarmode,"<full|inc|reset|noreset> tar's behaviour towards archive bits",{COMPL_NONE,COMPL_NONE}},
{"translate",cmd_translate,"toggle text translation for printing",{COMPL_NONE,COMPL_NONE}},
/* Yes, this must be here, see crh's comment above. */
matches = 1;
cmd = i;
break;
- } else if (strnequal(commands[i].name, tok, tok_len)) {
+ } else if (strncasecmp(commands[i].name, tok, tok_len) == 0) {
matches++;
cmd = i;
}
/****************************************************************************
help
****************************************************************************/
-static int cmd_help(void)
+static int cmd_help(const char **cmd_ptr)
{
int i=0,j;
fstring buf;
- if (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+ if (next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
if ((i = process_tok(buf)) >= 0)
d_printf("HELP %s:\n\t%s\n\n",commands[i].name,commands[i].description);
} else {
/* establish the connection if not already */
if (!cli) {
- cli = do_connect(desthost, service);
+ cli = do_connect(desthost, service, cmdline_credentials);
if (!cli)
return 0;
}
/* and get the first part of the command */
ptr = line;
- if (!next_token_nr(&ptr,tok,NULL,sizeof(tok))) continue;
+ if (!next_token(&ptr,tok,NULL,sizeof(tok))) continue;
if ((i = process_tok(tok)) >= 0) {
- rc = commands[i].fn();
+ rc = commands[i].fn(&ptr);
} else if (i == -2) {
d_printf("%s: command abbreviation ambiguous\n",tok);
} else {
int len;
} completion_remote_t;
-static void completion_remote_filter(file_info *f, const char *mask, void *state)
+static void completion_remote_filter(struct clilist_file_info *f, const char *mask, void *state)
{
completion_remote_t *info = (completion_remote_t *)state;
if ((info->count < MAX_COMPLETIONS - 1) && (strncmp(info->text, f->name, info->len) == 0) && (strcmp(f->name, ".") != 0) && (strcmp(f->name, "..") != 0)) {
- if ((info->dirmask[0] == 0) && !(f->mode & FILE_ATTRIBUTE_DIRECTORY))
+ if ((info->dirmask[0] == 0) && !(f->attrib & FILE_ATTRIBUTE_DIRECTORY))
info->matches[info->count] = strdup(f->name);
else {
pstring tmp;
else
tmp[0] = 0;
pstrcat(tmp, f->name);
- if (f->mode & FILE_ATTRIBUTE_DIRECTORY)
+ if (f->attrib & FILE_ATTRIBUTE_DIRECTORY)
pstrcat(tmp, "/");
info->matches[info->count] = strdup(tmp);
}
if (info->matches[info->count] == NULL)
return;
- if (f->mode & FILE_ATTRIBUTE_DIRECTORY)
+ if (f->attrib & FILE_ATTRIBUTE_DIRECTORY)
smb_readline_ca_char(0);
if (info->count == 1)
{
pstring dirmask;
int i;
- completion_remote_t info = { "", NULL, 1, len, text, len };
+ completion_remote_t info = { "", NULL, 1, 0, NULL, 0 };
+ info.samelen = len;
+ info.text = text;
+ info.len = len;
+
if (len >= PATH_MAX)
return(NULL);
- info.matches = (char **)malloc(sizeof(info.matches[0])*MAX_COMPLETIONS);
+ info.matches = malloc_array_p(char *, MAX_COMPLETIONS);
if (!info.matches) return NULL;
info.matches[0] = NULL;
} else
snprintf(dirmask, sizeof(dirmask), "%s*", cur_dir);
- if (cli_list(cli, dirmask,
+ if (smbcli_list(cli->tree, dirmask,
FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,
completion_remote_filter, &info) < 0)
goto cleanup;
return NULL;
} else {
char **matches;
- int i, len, samelen, count=1;
+ int i, len, samelen = 0, count=1;
- matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
+ matches = malloc_array_p(char *, MAX_COMPLETIONS);
if (!matches) return NULL;
matches[0] = NULL;
****************************************************************************/
static void readline_callback(void)
{
- fd_set fds;
- struct timeval timeout;
static time_t last_t;
time_t t;
last_t = t;
- again:
- if (cli->transport->socket->fd == -1)
- return;
-
- FD_ZERO(&fds);
- FD_SET(cli->transport->socket->fd, &fds);
-
- timeout.tv_sec = 0;
- timeout.tv_usec = 0;
- sys_select_intr(cli->transport->socket->fd+1,&fds,NULL,NULL,&timeout);
-
- /* We deliberately use cli_swallow_keepalives instead of
- client_receive_smb as we want to receive
- session keepalives and then drop them here.
- */
- if (FD_ISSET(cli->transport->socket->fd, &fds)) {
- if (!cli_request_receive_next(cli->transport)) {
- d_printf("Lost connection to server\n");
- exit(1);
- }
- goto again;
- }
+ smbcli_transport_process(cli->transport);
if (cli->tree) {
- cli_chkpath(cli, "\\");
+ smbcli_chkpath(cli->tree, "\\");
}
}
****************************************************************************/
static void process_stdin(void)
{
- const char *ptr;
-
while (1) {
fstring tok;
fstring the_prompt;
char *cline;
pstring line;
+ const char *ptr;
int i;
/* display a prompt */
/* and get the first part of the command */
ptr = line;
- if (!next_token_nr(&ptr,tok,NULL,sizeof(tok))) continue;
+ if (!next_token(&ptr,tok,NULL,sizeof(tok))) continue;
if ((i = process_tok(tok)) >= 0) {
- commands[i].fn();
+ commands[i].fn(&ptr);
} else if (i == -2) {
d_printf("%s: command abbreviation ambiguous\n",tok);
} else {
/*****************************************************
return a connection to a server
*******************************************************/
-static struct cli_state *do_connect(const char *server, const char *share)
+static struct smbcli_state *do_connect(const char *server, const char *share, struct cli_credentials *cred)
{
- struct cli_state *c;
- struct nmb_name called, calling;
- const char *server_n;
- struct in_addr ip;
- fstring servicename;
- char *sharename;
-
- /* make a copy so we don't modify the global string 'service' */
- fstrcpy(servicename, share);
- sharename = servicename;
- if (*sharename == '\\') {
- server = sharename+2;
- sharename = strchr_m(server,'\\');
- if (!sharename) return NULL;
- *sharename = 0;
- sharename++;
- }
-
- asprintf(&sharename, "\\\\%s\\%s", server, sharename);
-
- server_n = server;
-
- zero_ip(&ip);
-
- make_nmb_name(&calling, lp_netbios_name(), 0x0);
- make_nmb_name(&called , server, name_type);
-
- again:
- zero_ip(&ip);
- if (have_ip) ip = dest_ip;
-
- /* have to open a new connection */
- if (!(c=cli_state_init()) || !cli_socket_connect(c, server_n, &ip)) {
- d_printf("Connection to %s failed\n", server_n);
- return NULL;
- }
-
- if (!cli_transport_establish(c, &calling, &called)) {
- char *p;
- d_printf("session request to %s failed (%s)\n",
- called.name, cli_errstr(c));
- cli_shutdown(c);
- if ((p=strchr_m(called.name, '.'))) {
- *p = 0;
- goto again;
- }
- if (strcmp(called.name, "*SMBSERVER")) {
- make_nmb_name(&called , "*SMBSERVER", 0x20);
- goto again;
- }
- return NULL;
- }
-
- DEBUG(4,(" session request ok\n"));
-
- if (!cli_negprot(c)) {
- d_printf("protocol negotiation failed\n");
- cli_shutdown(c);
- return NULL;
- }
-
- if (!got_pass) {
- const char *pass = getpass("Password: ");
- if (pass) {
- pstrcpy(password, pass);
- }
- }
+ struct smbcli_state *c;
+ NTSTATUS status;
- if (!cli_session_setup(c, username, password,
- lp_workgroup())) {
- /* if a password was not supplied then try again with a null username */
- if (password[0] || !username[0] || use_kerberos ||
- !cli_session_setup(c, "", "", lp_workgroup())) {
- d_printf("session setup failed: %s\n", cli_errstr(c));
- cli_shutdown(c);
- return NULL;
- }
- d_printf("Anonymous login successful\n");
+ if (strncmp(share, "\\\\", 2) == 0 ||
+ strncmp(share, "//", 2) == 0) {
+ smbcli_parse_unc(share, NULL, &server, &share);
}
-
- DEBUG(4,(" session setup ok\n"));
-
- if (!cli_send_tconX(c, sharename, "?????", password)) {
- d_printf("tree connect failed: %s\n", cli_errstr(c));
- cli_shutdown(c);
+
+ status = smbcli_full_connection(NULL, &c, lp_netbios_name(), server,
+ share, NULL, cli_credentials_get_username(cred),
+ cli_credentials_get_domain(cred),
+ cli_credentials_get_password(cred));
+ if (!NT_STATUS_IS_OK(status)) {
+ d_printf("Connection to \\\\%s\\%s failed - %s\n",
+ server, share, nt_errstr(status));
return NULL;
}
- DEBUG(4,(" tconx ok\n"));
-
return c;
}
{
int rc = 0;
- cli = do_connect(desthost, service);
+ cli = do_connect(desthost, service, cmdline_credentials);
if (!cli) {
return 1;
}
process_stdin();
}
- cli_shutdown(cli);
+ smbcli_shutdown(cli);
return rc;
}
****************************************************************************/
static int do_host_query(char *query_host)
{
- cli = do_connect(query_host, "IPC$");
- if (!cli)
- return 1;
-
- browse_host(True);
+ browse_host(query_host);
list_servers(lp_workgroup());
-
- cli_shutdown(cli);
-
return(0);
}
-/****************************************************************************
-handle a tar operation
-****************************************************************************/
-static int do_tar_op(char *base_directory)
-{
- int ret;
-
- /* do we already have a connection? */
- if (!cli) {
- cli = do_connect(desthost, service);
- if (!cli)
- return 1;
- }
-
- recurse=True;
-
- if (*base_directory) do_cd(base_directory);
-
- ret=process_tar();
-
- cli_shutdown(cli);
-
- return(ret);
-}
-
/****************************************************************************
handle a message operation
****************************************************************************/
static int do_message_op(void)
{
- struct in_addr ip;
- struct nmb_name called, calling;
- fstring server_name;
- char name_type_hex[10];
+ struct nbt_name called, calling;
+ const char *server_name;
- make_nmb_name(&calling, lp_netbios_name(), 0x0);
- make_nmb_name(&called , desthost, name_type);
+ calling.name = lp_netbios_name();
+ calling.type = NBT_NAME_CLIENT;
+ calling.scope = NULL;
- fstrcpy(server_name, desthost);
- snprintf(name_type_hex, sizeof(name_type_hex), "#%X", name_type);
- fstrcat(server_name, name_type_hex);
+ nbt_choose_called_name(NULL, &called, desthost, name_type);
- zero_ip(&ip);
- if (have_ip) ip = dest_ip;
+ server_name = dest_ip ? dest_ip : desthost;
- if (!(cli=cli_state_init()) || !cli_socket_connect(cli, server_name, &ip)) {
- d_printf("Connection to %s failed\n", desthost);
+ if (!(cli=smbcli_state_init(NULL)) || !smbcli_socket_connect(cli, server_name)) {
+ d_printf("Connection to %s failed\n", server_name);
return 1;
}
- if (!cli_transport_establish(cli, &calling, &called)) {
+ if (!smbcli_transport_establish(cli, &calling, &called)) {
d_printf("session request failed\n");
- cli_shutdown(cli);
+ smbcli_shutdown(cli);
return 1;
}
send_message();
- cli_shutdown(cli);
+ smbcli_shutdown(cli);
return 0;
}
int opt;
pstring query_host;
BOOL message = False;
- extern char tar_type;
pstring term_code;
poptContext pc;
char *p;
struct poptOption long_options[] = {
POPT_AUTOHELP
- { "name-resolve", 'R', POPT_ARG_STRING, NULL, 'R', "Use these name resolution services only", "NAME-RESOLVE-ORDER" },
{ "message", 'M', POPT_ARG_STRING, NULL, 'M', "Send message", "HOST" },
{ "ip-address", 'I', POPT_ARG_STRING, NULL, 'I', "Use this IP to connect to", "IP" },
{ "stderr", 'E', POPT_ARG_NONE, NULL, 'E', "Write messages to stderr instead of stdout" },
{ "list", 'L', POPT_ARG_STRING, NULL, 'L', "Get a list of shares available on a host", "HOST" },
{ "terminal", 't', POPT_ARG_STRING, NULL, 't', "Terminal I/O code {sjis|euc|jis7|jis8|junet|hex}", "CODE" },
- { "max-protocol", 'm', POPT_ARG_STRING, NULL, 'm', "Set the max protocol level", "LEVEL" },
- { "tar", 'T', POPT_ARG_STRING, NULL, 'T', "Command line tar", "<c|x>IXFqgbNan" },
{ "directory", 'D', POPT_ARG_STRING, NULL, 'D', "Start from directory", "DIR" },
{ "command", 'c', POPT_ARG_STRING, &cmdstr, 'c', "Execute semicolon separated commands" },
{ "send-buffer", 'b', POPT_ARG_INT, NULL, 'b', "Changes the transmit/send buffer", "BYTES" },
POPT_COMMON_SAMBA
POPT_COMMON_CONNECTION
POPT_COMMON_CREDENTIALS
+ POPT_COMMON_VERSION
POPT_TABLEEND
};
-
#ifdef KANJI
pstrcpy(term_code, KANJI);
#else /* KANJI */
*query_host = 0;
*base_directory = 0;
- setup_logging(argv[0],True);
+ setup_logging(argv[0],DEBUG_STDOUT);
mem_ctx = talloc_init("client.c/main");
if (!mem_ctx) {
d_printf("\nclient.c: Not enough memory\n");
argv[0], dyn_CONFIGFILE);
}
- pc = poptGetContext("smbclient", argc, (const char **) argv, long_options,
- POPT_CONTEXT_KEEP_FIRST);
- poptSetOtherOptionHelp(pc, "service <password>");
+ pc = poptGetContext("smbclient", argc, (const char **) argv, long_options, 0);
+ poptSetOtherOptionHelp(pc, "[OPTIONS] service <password>");
in_client = True; /* Make sure that we tell lp_load we are */
message = True;
break;
case 'I':
- {
- dest_ip = *interpret_addr2(mem_ctx, poptGetOptArg(pc));
- if (is_zero_ip(dest_ip))
- exit(1);
- have_ip = True;
- }
+ dest_ip = poptGetOptArg(pc);
break;
case 'E':
setup_logging("client", DEBUG_STDERR);
case 't':
pstrcpy(term_code, poptGetOptArg(pc));
break;
- case 'm':
- lp_set_cmdline("max protocol", poptGetOptArg(pc));
- break;
- case 'R':
- lp_set_cmdline("name resolve order", poptGetOptArg(pc));
- break;
- case 'T':
- if (!tar_parseargs(argc, argv, poptGetOptArg(pc), optind)) {
- poptPrintUsage(pc, stderr, 0);
- exit(1);
- }
- break;
case 'D':
fstrcpy(base_directory,poptGetOptArg(pc));
break;
}
}
- poptGetArg(pc);
-
load_interfaces();
+ smbclient_init_subsystems;
+
if(poptPeekArg(pc)) {
pstrcpy(service,poptGetArg(pc));
/* Convert any '/' characters in the service name to '\' characters */
}
if (poptPeekArg(pc)) {
- cmdline_auth_info.got_pass = True;
- pstrcpy(cmdline_auth_info.password,poptGetArg(pc));
+ cli_credentials_set_password(cmdline_credentials, poptGetArg(pc), CRED_SPECIFIED);
}
- //init_names();
+ /*init_names(); */
- if (!tar_type && !*query_host && !*service && !message) {
+ if (!*query_host && !*service && !message) {
poptPrintUsage(pc, stderr, 0);
exit(1);
}
poptFreeContext(pc);
- pstrcpy(username, cmdline_auth_info.username);
- pstrcpy(password, cmdline_auth_info.password);
- use_kerberos = cmdline_auth_info.use_kerberos;
- got_pass = cmdline_auth_info.got_pass;
+ DEBUG( 3, ( "Client started (version %s).\n", SAMBA_VERSION_STRING ) );
- DEBUG( 3, ( "Client started (version %s).\n", SAMBA_VERSION ) );
-
- talloc_destroy(mem_ctx);
- if (tar_type) {
- if (cmdstr)
- process_command_string(cmdstr);
- return do_tar_op(base_directory);
- }
+ talloc_free(mem_ctx);
if ((p=strchr_m(query_host,'#'))) {
*p = 0;