49
49
static int process_tok(pstring tok);
50
50
static int cmd_help(void);
52
static TALLOC_CTX *ctx;
53
#define CREATE_ACCESS_READ READ_CONTROL_ACCESS
52
56
/* 30 second timeout on most commands */
53
57
#define CLIENT_TIMEOUT (30*1000)
54
58
#define SHORT_TIMEOUT (5*1000)
376
381
if (do_this_one(finfo)) {
377
382
time_t t = finfo->mtime; /* the time is assumed to be passed as GMT */
378
d_printf(" %-30s%7.7s %8.0f %s",
380
attrib_string(finfo->mode),
382
asctime(localtime(&t)));
383
dir_total += finfo->size;
384
d_printf(" %-30s%7.7s %8.0f %s",
386
attrib_string(finfo->mode),
389
dir_total += finfo->size;
390
} else { /* showacls */
391
static pstring afname;
394
/* skip if this is . or .. */
395
if ( strequal(finfo->name,"..") || strequal(finfo->name,".") )
397
/* create absolute filename for cli_nt_create() FIXME */
398
pstrcpy( afname, cwd);
399
pstrcat( afname, "\\");
400
pstrcat( afname, finfo->name);
401
/* print file meta date header */
402
d_printf( "FILENAME:%s\n", afname);
403
d_printf( "MODE:%s\n", attrib_string(finfo->mode));
404
d_printf( "SIZE:%.0f\n", (double)finfo->size);
405
d_printf( "MTIME:%s", time_to_asc(&t));
406
fnum = cli_nt_create(cli, afname, CREATE_ACCESS_READ);
408
DEBUG( 0, ("display_finfo() Failed to open %s: %s\n",
413
sd = cli_query_secdesc(cli, fnum, ctx);
415
DEBUG( 0, ("display_finfo() failed to "
416
"get security descriptor: %s",
419
display_sec_desc(sd);
447
486
* If the starting point of the queue is more than half way through,
448
487
* move everything toward the beginning.
450
if (do_list_queue && (do_list_queue_start == do_list_queue_end)) {
490
if (do_list_queue == NULL) {
491
DEBUG(4,("do_list_queue is empty\n"));
492
do_list_queue_start = do_list_queue_end = 0;
496
if (do_list_queue_start == do_list_queue_end) {
451
497
DEBUG(4,("do_list_queue is empty\n"));
452
498
do_list_queue_start = do_list_queue_end = 0;
453
499
*do_list_queue = '\0';
464
510
static void add_to_do_list_queue(const char* entry)
467
512
long new_end = do_list_queue_end + ((long)strlen(entry)) + 1;
468
513
while (new_end > do_list_queue_size) {
469
514
do_list_queue_size *= 2;
470
515
DEBUG(4,("enlarging do_list_queue to %d\n",
471
516
(int)do_list_queue_size));
472
dlq = SMB_REALLOC(do_list_queue, do_list_queue_size);
517
do_list_queue = SMB_REALLOC(do_list_queue, do_list_queue_size);
518
if (! do_list_queue) {
474
519
d_printf("failure enlarging do_list_queue to %d bytes\n",
475
520
(int)do_list_queue_size);
476
521
reset_do_list_queue();
479
523
memset(do_list_queue + do_list_queue_size / 2,
480
524
0, do_list_queue_size / 2);
611
655
save_ch = next_file +
612
656
strlen(next_file) - 2;
658
if (showacls) /* cwd is only used if showacls is on */
659
pstrcpy( cwd, next_file);
615
d_printf("\n%s\n",next_file);
661
if (!showacls) /* don't disturbe the showacls output */
662
d_printf("\n%s\n",next_file);
690
737
pstrcpy(mask,cur_dir);
691
if(mask[strlen(mask)-1]!='\\')
738
if ((mask[0] != '\0') && (mask[strlen(mask)-1]!='\\'))
692
739
pstrcat(mask,"\\");
694
741
if (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1011
1058
while (next_token_nr(NULL,p,NULL,sizeof(buf))) {
1012
1059
pstrcpy(mget_mask,cur_dir);
1013
if(mget_mask[strlen(mget_mask)-1]!='\\')
1060
if ((mget_mask[0] != '\0') && (mget_mask[strlen(mget_mask)-1]!='\\'))
1014
1061
pstrcat(mget_mask,"\\");
1016
1063
if (*p == '\\')
1338
1386
Free a file_list structure.
1339
1387
****************************************************************************/
1341
static void free_file_list (struct file_list * list)
1389
static void free_file_list (struct file_list *list_head)
1343
struct file_list *tmp;
1391
struct file_list *list, *next;
1347
DLIST_REMOVE(list, list);
1348
SAFE_FREE(tmp->file_path);
1393
for (list = list_head; list; list = next) {
1395
DLIST_REMOVE(list_head, list);
1396
SAFE_FREE(list->file_path);
2167
2216
(unsigned int)sbuf.st_uid,
2168
2217
(unsigned int)sbuf.st_gid);
2170
strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_atime));
2219
lt = localtime(&sbuf.st_atime);
2221
strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
2223
fstrcpy(mode_str, "unknown");
2171
2225
d_printf("Access: %s\n", mode_str);
2173
strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_mtime));
2227
lt = localtime(&sbuf.st_mtime);
2229
strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
2231
fstrcpy(mode_str, "unknown");
2174
2233
d_printf("Modify: %s\n", mode_str);
2176
strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_ctime));
2235
lt = localtime(&sbuf.st_ctime);
2237
strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
2239
fstrcpy(mode_str, "unknown");
2177
2241
d_printf("Change: %s\n", mode_str);
2341
2405
if (ok && (sys_stat(buf,&sbuf) == 0)) {
2342
2406
newer_than = sbuf.st_mtime;
2343
2407
DEBUG(1,("Getting files newer than %s",
2344
asctime(localtime(&newer_than))));
2408
time_to_asc(&newer_than)));
2346
2410
newer_than = 0;
2400
2464
/****************************************************************************
2465
Toggle the showacls flag.
2466
****************************************************************************/
2468
static int cmd_showacls(void)
2470
showacls = !showacls;
2471
DEBUG(2,("showacls is now %s\n",showacls?"on":"off"));
2473
if (!ctx && showacls)
2474
ctx = talloc_init("smbclient:showacls");
2476
DEBUG( 0, ("cmd_showacls() out of memory. talloc_init() failed.\n"));
2483
/****************************************************************************
2401
2484
Toggle the recurse flag.
2402
2485
****************************************************************************/
2620
static BOOL browse_host_rpc(BOOL sort)
2623
struct rpc_pipe_client *pipe_hnd;
2624
TALLOC_CTX *mem_ctx;
2627
SRV_SHARE_INFO_CTR ctr;
2630
mem_ctx = talloc_new(NULL);
2631
if (mem_ctx == NULL) {
2632
DEBUG(0, ("talloc_new failed\n"));
2636
init_enum_hnd(&enum_hnd, 0);
2638
pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &status);
2640
if (pipe_hnd == NULL) {
2641
DEBUG(10, ("Could not connect to srvsvc pipe: %s\n",
2642
nt_errstr(status)));
2643
TALLOC_FREE(mem_ctx);
2647
werr = rpccli_srvsvc_net_share_enum(pipe_hnd, mem_ctx, 1, &ctr,
2648
0xffffffff, &enum_hnd);
2650
if (!W_ERROR_IS_OK(werr)) {
2651
TALLOC_FREE(mem_ctx);
2652
cli_rpc_pipe_close(pipe_hnd);
2656
for (i=0; i<ctr.num_entries; i++) {
2657
SRV_SHARE_INFO_1 *info = &ctr.share.info1[i];
2658
char *name, *comment;
2659
name = rpcstr_pull_unistr2_talloc(
2660
mem_ctx, &info->info_1_str.uni_netname);
2661
comment = rpcstr_pull_unistr2_talloc(
2662
mem_ctx, &info->info_1_str.uni_remark);
2663
browse_fn(name, info->info_1.type, comment, NULL);
2666
TALLOC_FREE(mem_ctx);
2667
cli_rpc_pipe_close(pipe_hnd);
2537
2671
/****************************************************************************
2538
2672
Try and browse available connections on a host.
2539
2673
****************************************************************************/
2546
2680
d_printf("\t--------- ---- -------\n");
2683
if (browse_host_rpc(sort)) {
2549
2687
if((ret = cli_RNetShareEnum(cli, browse_fn, NULL)) == -1)
2550
2688
d_printf("Error returning browse list: %s\n", cli_errstr(cli));
2743
2881
{"reput",cmd_reput,"<local name> [remote name] put a file restarting at end of remote file",{COMPL_LOCAL,COMPL_REMOTE}},
2744
2882
{"rm",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
2745
2883
{"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
2884
{"showacls",cmd_showacls,"toggle if ACLs are shown or not",{COMPL_NONE,COMPL_NONE}},
2746
2885
{"setmode",cmd_setmode,"filename <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
2747
2886
{"stat",cmd_stat,"filename Do a UNIX extensions stat call on a file",{COMPL_REMOTE,COMPL_REMOTE}},
2748
2887
{"symlink",cmd_symlink,"<oldname> <newname> create a UNIX symlink",{COMPL_REMOTE,COMPL_REMOTE}},
2921
3060
info.text = text;
2922
3061
info.len = len;
2924
if (len >= PATH_MAX)
3063
if (len >= MIN(PATH_MAX,sizeof(pstring))) {
2927
3067
info.matches = SMB_MALLOC_ARRAY(char *,MAX_COMPLETIONS);
2928
if (!info.matches) return NULL;
3068
if (!info.matches) {
2929
3071
info.matches[0] = NULL;
2931
for (i = len-1; i >= 0; i--)
2932
if ((text[i] == '/') || (text[i] == '\\'))
3073
for (i = len-1; i >= 0; i--) {
3074
if ((text[i] == '/') || (text[i] == '\\')) {
2934
3079
info.text = text+i+1;
2935
3080
info.samelen = info.len = len-i-1;
2938
3083
strncpy(info.dirmask, text, i+1);
2939
3084
info.dirmask[i+1] = 0;
2940
3085
pstr_sprintf(dirmask, "%s%*s*", cur_dir, i-1, text);
2942
3087
pstr_sprintf(dirmask, "%s*", cur_dir);
2944
3090
if (cli_list(cli, dirmask, aDIR | aSYSTEM | aHIDDEN, completion_remote_filter, &info) < 0)
3346
3492
/* set default debug level to 0 regardless of what smb.conf sets */
3347
3493
setup_logging( "smbclient", True );
3348
3494
DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
3350
x_setbuf( x_stderr, NULL );
3495
if ((dbf = x_fdup(x_stderr))) {
3496
x_setbuf( dbf, NULL );
3352
3499
pc = poptGetContext("smbclient", argc, (const char **) argv, long_options,
3353
3500
POPT_CONTEXT_KEEP_FIRST);
3449
3599
if ( override_logfile )
3450
3600
setup_logging( lp_logfile(), False );
3452
if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
3602
if (!lp_load(dyn_CONFIGFILE,True,False,False,True)) {
3453
3603
fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n",
3454
3604
argv[0], dyn_CONFIGFILE);