*/
#include "includes.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
static pstring service;
static pstring desthost;
static pstring username;
+static pstring domain;
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)
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;
}
/****************************************************************************
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
/****************************************************************************
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_t mode)
-{
- static fstring attrstr;
- int i, len;
- const struct {
- char c;
- uint16_t 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)));
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 smbcli_list that adds recursion
****************************************************************************/
-void do_list(const char *mask,uint16_t 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;
/****************************************************************************
get a directory listing
****************************************************************************/
-static int cmd_dir(void)
+static int cmd_dir(const char **cmd_ptr)
{
uint16_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
pstring mask;
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_t attribute = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
pstring mask;
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_t attr;
GetTimeOfDay(&tp_start);
if (lowercase) {
- strlower(lname);
+ strlower(discard_const_p(char, lname));
}
fnum = smbcli_open(cli->tree, rname, O_RDONLY, DENY_NONE);
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;
}
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);
smbcli_close(cli->tree, fnum);
return 1;
/****************************************************************************
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) &&
mkdir(finfo->name,0777) != 0) {
/****************************************************************************
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_t attribute = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN;
pstring mget_mask;
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,"\\");
/****************************************************************************
Exit client.
****************************************************************************/
-static int cmd_quit(void)
+static int cmd_quit(const char **cmd_ptr)
{
smbcli_shutdown(cli);
exit(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;
/****************************************************************************
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;
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;
/****************************************************************************
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;
+ struct stat st;
/* allow '-' to represent stdin
jdblair, 24.jun.98 */
if (!file_exist(lname,&st) &&
/****************************************************************************
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;
/****************************************************************************
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 (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, mask))) {
- d_printf("%s deleting remote file %s\n",smbcli_errstr(cli->tree),mask);
- }
-}
-
-/****************************************************************************
-delete some files
-****************************************************************************/
-static int cmd_del(void)
+static int cmd_del(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("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;
}
/****************************************************************************
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;
/****************************************************************************
show any ACL on a file
****************************************************************************/
-static int cmd_acl(void)
+static int cmd_acl(const char **cmd_ptr)
{
pstring fname;
fstring buf;
int ret = 0;
TALLOC_CTX *mem_ctx;
- struct smb_query_secdesc query;
+ union smb_fileinfo query;
NTSTATUS status;
int fnum;
pstrcpy(fname,cur_dir);
- if (!next_token_nr(NULL,buf,NULL,sizeof(buf))) {
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
d_printf("acl <filename>\n");
return 1;
}
return -1;
}
- mem_ctx = talloc_init(fname);
+ mem_ctx = talloc_init("%s", fname);
- query.in.fnum = fnum;
- query.in.secinfo_flags = 0x7;
+ query.query_secdesc.level = RAW_FILEINFO_SEC_DESC;
+ query.query_secdesc.in.fnum = fnum;
+ query.query_secdesc.in.secinfo_flags = 0x7;
- status = smb_raw_query_secdesc(cli->tree, mem_ctx, &query);
+ 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_destroy(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(NULL, 0);
+ NTSTATUS status;
+ struct dom_sid *sid;
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("lookup <name|sid>\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_open(void)
+static int cmd_privileges(const char **cmd_ptr)
+{
+ fstring buf;
+ TALLOC_CTX *mem_ctx = talloc(NULL, 0);
+ 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_addprivileges(const char **cmd_ptr)
+{
+ fstring buf;
+ TALLOC_CTX *mem_ctx = talloc(NULL, 0);
+ NTSTATUS status;
+ struct dom_sid *sid;
+ struct lsa_RightSet rights;
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("addprivileges <sid> <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_p(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(NULL, 0);
+ NTSTATUS status;
+ struct dom_sid *sid;
+ struct lsa_RightSet rights;
+
+ if (!next_token(cmd_ptr,buf,NULL,sizeof(buf))) {
+ d_printf("delprivileges <sid> <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_p(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;
}
/****************************************************************************
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;
}
/****************************************************************************
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;
}
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;
}
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;
}
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;
}
/****************************************************************************
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;
}
/****************************************************************************
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))));
/****************************************************************************
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;
+ 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;
}
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);
status = dcerpc_pipe_connect(&p, binding,
DCERPC_SRVSVC_UUID,
DCERPC_SRVSVC_VERSION,
- lp_workgroup(),
+ domain,
username, password);
if (!NT_STATUS_IS_OK(status)) {
d_printf("Failed to connect to %s - %s\n",
talloc_destroy(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;
}
} while (NT_STATUS_IS_OK(status) && W_ERROR_EQUAL(r.out.result, WERR_MORE_DATA));
+ talloc_destroy(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));
- talloc_destroy(mem_ctx);
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|user> <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|user> <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}},
{"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,"<name|sid> 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 {
/* 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)
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;
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 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 {
again:
/* have to open a new connection */
- if (!(c=smbcli_state_init()) || !smbcli_socket_connect(c, server_n)) {
+ if (!(c=smbcli_state_init(NULL)) || !smbcli_socket_connect(c, server_n)) {
d_printf("Connection to %s failed\n", server_n);
return NULL;
}
return NULL;
}
- if (!got_pass) {
- const char *pass = getpass("Password: ");
- if (pass) {
- pstrcpy(password, pass);
- }
- }
-
- status = smbcli_session_setup(c, username, password, lp_workgroup());
+ status = smbcli_session_setup(c, username, password, domain);
if (NT_STATUS_IS_ERR(status)) {
d_printf("authenticated session setup failed: %s\n", nt_errstr(status));
/* if a password was not supplied then try again with a null username */
- if (password[0] || !username[0] || use_kerberos) {
+ if (password[0] || !username[0]) {
status = smbcli_session_setup(c, "", "", lp_workgroup());
}
if (NT_STATUS_IS_ERR(status)) {
}
-/****************************************************************************
-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();
-
- smbcli_shutdown(cli);
-
- return(ret);
-}
-
/****************************************************************************
handle a message operation
****************************************************************************/
server_name = dest_ip ? dest_ip : desthost;
- if (!(cli=smbcli_state_init()) || !smbcli_socket_connect(cli, server_name)) {
+ if (!(cli=smbcli_state_init(NULL)) || !smbcli_socket_connect(cli, server_name)) {
d_printf("Connection to %s failed\n", server_name);
return 1;
}
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 */
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;
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));
+ cmdline_set_userpassword(poptGetArg(pc));
}
/*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;
+ pstrcpy(username, cmdline_get_username());
+ pstrcpy(domain, cmdline_get_userdomain());
+ pstrcpy(password, cmdline_get_userpassword());
DEBUG( 3, ( "Client started (version %s).\n", SAMBA_VERSION_STRING ) );
talloc_destroy(mem_ctx);
- if (tar_type) {
- if (cmdstr)
- process_command_string(cmdstr);
- return do_tar_op(base_directory);
- }
if ((p=strchr_m(query_host,'#'))) {
*p = 0;