~ubuntu-branches/ubuntu/gutsy/samba/gutsy-updates

« back to all changes in this revision

Viewing changes to source/client/client.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-11-28 20:14:37 UTC
  • mfrom: (0.10.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061128201437-a6x4lzlhempazocp
Tags: 3.0.23d-1ubuntu1
* Merge from debian unstable.
* Drop python2.4-samba, replace with python-samba. Added Conflicts/Replaces
  on python2.4-samba
* Drop track-connection-dos.patch, ubuntu-winbind-panic.patch, 
  ubuntu-fix-ldap.patch, ubuntu-setlocale.patch, ubuntu-setlocale-fixes.patch
* Remaining Ubuntu changes:
  - Revert Debian's installation of mount.cifs and umount.cifs as suid
  - Comment out the default [homes] shares and add more verbose comments to
    explain what they do and how they work (closes: launchpad.net/27608)
  - Add a "valid users = %S" stanza to the commented-out [homes] section, to
    show users how to restrict access to \\server\username to only username.
  - Change the (commented-out) "printer admin" example to use "@lpadmin"
    instead of "@ntadmin", since the lpadmin group is used for spool admin.
  - Alter the panic-action script to encourage users to report their
    bugs in Ubuntu packages to Ubuntu, rather than reporting to Debian.
    Modify text to more closely match the Debian script
  - Munge our init script to deal with the fact that our implementation
    (or lack thereof) of log_daemon_msg and log_progress_msg differs
    from Debian's implementation of the same (Ubuntu #19691)
  - Kept ubuntu-auxsrc.patch: some auxilliary sources (undocumented in 
    previous changelogs)
  - Set default workgroup to MSHOME

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
static int process_tok(pstring tok);
50
50
static int cmd_help(void);
51
51
 
 
52
static TALLOC_CTX *ctx;
 
53
#define CREATE_ACCESS_READ READ_CONTROL_ACCESS
 
54
static pstring cwd;
 
55
 
52
56
/* 30 second timeout on most commands */
53
57
#define CLIENT_TIMEOUT (30*1000)
54
58
#define SHORT_TIMEOUT (5*1000)
72
76
static BOOL prompt = True;
73
77
 
74
78
static BOOL recurse = False;
 
79
static BOOL showacls = False;
75
80
BOOL lowercase = False;
76
81
 
77
82
static struct in_addr dest_ip;
269
274
        else
270
275
                pstrcat(cur_dir,p);
271
276
 
272
 
        if (*(cur_dir+strlen(cur_dir)-1) != '\\') {
 
277
        if ((cur_dir[0] != '\0') && (*(cur_dir+strlen(cur_dir)-1) != '\\')) {
273
278
                pstrcat(cur_dir, "\\");
274
279
        }
275
280
        
375
380
{
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",
379
 
                         finfo->name,
380
 
                         attrib_string(finfo->mode),
381
 
                         (double)finfo->size,
382
 
                         asctime(localtime(&t)));
383
 
                dir_total += finfo->size;
 
383
                if (!showacls) {
 
384
                        d_printf("  %-30s%7.7s %8.0f  %s",
 
385
                                 finfo->name,
 
386
                                 attrib_string(finfo->mode),
 
387
                                 (double)finfo->size,
 
388
                                 time_to_asc(&t));
 
389
                        dir_total += finfo->size;
 
390
                } else { /* showacls */
 
391
                        static pstring afname;
 
392
                        int fnum;
 
393
 
 
394
                        /* skip if this is . or .. */
 
395
                        if ( strequal(finfo->name,"..") || strequal(finfo->name,".") )
 
396
                                return;
 
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);
 
407
                        if (fnum == -1) {
 
408
                                DEBUG( 0, ("display_finfo() Failed to open %s: %s\n",
 
409
                                                        afname,
 
410
                                                        cli_errstr( cli)));
 
411
                        } else {
 
412
                                SEC_DESC *sd = NULL;
 
413
                                sd = cli_query_secdesc(cli, fnum, ctx);
 
414
                                if (!sd) {
 
415
                                        DEBUG( 0, ("display_finfo() failed to "
 
416
                                                "get security descriptor: %s",
 
417
                                                cli_errstr( cli)));
 
418
                                } else {
 
419
                                        display_sec_desc(sd);
 
420
                                }
 
421
                        }
 
422
                }
384
423
        }
385
424
}
386
425
 
447
486
         * If the starting point of the queue is more than half way through,
448
487
         * move everything toward the beginning.
449
488
         */
450
 
        if (do_list_queue && (do_list_queue_start == do_list_queue_end)) {
 
489
 
 
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;
 
493
                return;
 
494
        }
 
495
                
 
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';
463
509
 
464
510
static void add_to_do_list_queue(const char* entry)
465
511
{
466
 
        char *dlq;
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);
473
 
                if (! dlq) {
 
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();
477
522
                } else {
478
 
                        do_list_queue = dlq;
479
523
                        memset(do_list_queue + do_list_queue_size / 2,
480
524
                               0, do_list_queue_size / 2);
481
525
                }
611
655
                                        save_ch = next_file +
612
656
                                                strlen(next_file) - 2;
613
657
                                        *save_ch = '\0';
 
658
                                        if (showacls) /* cwd is only used if showacls is on */
 
659
                                                pstrcpy( cwd, next_file);
614
660
                                }
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);
616
663
                                if (save_ch) {
617
664
                                        *save_ch = '\\';
618
665
                                }
649
696
        dir_total = 0;
650
697
        if (strcmp(cur_dir, "\\") != 0) {
651
698
                pstrcpy(mask,cur_dir);
652
 
                if(mask[strlen(mask)-1]!='\\')
 
699
                if ((mask[0] != '\0') && (mask[strlen(mask)-1]!='\\'))
653
700
                        pstrcat(mask,"\\");
654
701
        } else {
655
702
                pstrcpy(mask, "\\");
688
735
        
689
736
        dir_total = 0;
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,"\\");
693
740
        
694
741
        if (next_token_nr(NULL,buf,NULL,sizeof(buf))) {
1010
1057
 
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,"\\");
1015
1062
                
1016
1063
                if (*p == '\\')
1078
1125
static int cmd_quit(void)
1079
1126
{
1080
1127
        cli_cm_shutdown();
 
1128
        talloc_destroy( ctx);
1081
1129
        exit(0);
1082
1130
        /* NOTREACHED */
1083
1131
        return 0;
1338
1386
 Free a file_list structure.
1339
1387
****************************************************************************/
1340
1388
 
1341
 
static void free_file_list (struct file_list * list)
 
1389
static void free_file_list (struct file_list *list_head)
1342
1390
{
1343
 
        struct file_list *tmp;
 
1391
        struct file_list *list, *next;
1344
1392
        
1345
 
        while (list) {
1346
 
                tmp = list;
1347
 
                DLIST_REMOVE(list, list);
1348
 
                SAFE_FREE(tmp->file_path);
1349
 
                SAFE_FREE(tmp);
 
1393
        for (list = list_head; list; list = next) {
 
1394
                next = list->next;
 
1395
                DLIST_REMOVE(list_head, list);
 
1396
                SAFE_FREE(list->file_path);
 
1397
                SAFE_FREE(list);
1350
1398
        }
1351
1399
}
1352
1400
 
2113
2161
        fstring mode_str;
2114
2162
        SMB_STRUCT_STAT sbuf;
2115
2163
        struct cli_state *targetcli;
 
2164
        struct tm *lt;
2116
2165
        pstring targetname;
2117
2166
 
2118
2167
        if (!SERVER_HAS_UNIX_CIFS(cli)) {
2167
2216
                (unsigned int)sbuf.st_uid, 
2168
2217
                (unsigned int)sbuf.st_gid);
2169
2218
 
2170
 
        strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_atime));
 
2219
        lt = localtime(&sbuf.st_atime);
 
2220
        if (lt) {
 
2221
                strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
 
2222
        } else {
 
2223
                fstrcpy(mode_str, "unknown");
 
2224
        }
2171
2225
        d_printf("Access: %s\n", mode_str);
2172
2226
 
2173
 
        strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_mtime));
 
2227
        lt = localtime(&sbuf.st_mtime);
 
2228
        if (lt) {
 
2229
                strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
 
2230
        } else {
 
2231
                fstrcpy(mode_str, "unknown");
 
2232
        }
2174
2233
        d_printf("Modify: %s\n", mode_str);
2175
2234
 
2176
 
        strftime(mode_str, sizeof(mode_str), "%F %T %z", localtime(&sbuf.st_ctime));
 
2235
        lt = localtime(&sbuf.st_ctime);
 
2236
        if (lt) {
 
2237
                strftime(mode_str, sizeof(mode_str), "%F %T %z", lt);
 
2238
        } else {
 
2239
                fstrcpy(mode_str, "unknown");
 
2240
        }
2177
2241
        d_printf("Change: %s\n", mode_str);
2178
2242
        
2179
2243
        return 0;
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)));
2345
2409
        } else {
2346
2410
                newer_than = 0;
2347
2411
        }
2398
2462
}
2399
2463
 
2400
2464
/****************************************************************************
 
2465
 Toggle the showacls flag.
 
2466
****************************************************************************/
 
2467
 
 
2468
static int cmd_showacls(void)
 
2469
{
 
2470
        showacls = !showacls;
 
2471
        DEBUG(2,("showacls is now %s\n",showacls?"on":"off"));
 
2472
 
 
2473
        if (!ctx && showacls)
 
2474
                ctx = talloc_init("smbclient:showacls");
 
2475
                if (!ctx) {
 
2476
                        DEBUG( 0, ("cmd_showacls() out of memory.  talloc_init() failed.\n"));
 
2477
        }
 
2478
 
 
2479
        return 0;
 
2480
}
 
2481
 
 
2482
 
 
2483
/****************************************************************************
2401
2484
 Toggle the recurse flag.
2402
2485
****************************************************************************/
2403
2486
 
2512
2595
 
2513
2596
        *typestr=0;
2514
2597
 
2515
 
        switch (m)
 
2598
        switch (m & 7)
2516
2599
        {
2517
2600
          case STYPE_DISKTREE:
2518
2601
            fstrcpy(typestr,"Disk"); break;
2534
2617
        }
2535
2618
}
2536
2619
 
 
2620
static BOOL browse_host_rpc(BOOL sort)
 
2621
{
 
2622
        NTSTATUS status;
 
2623
        struct rpc_pipe_client *pipe_hnd;
 
2624
        TALLOC_CTX *mem_ctx;
 
2625
        ENUM_HND enum_hnd;
 
2626
        WERROR werr;
 
2627
        SRV_SHARE_INFO_CTR ctr;
 
2628
        int i;
 
2629
 
 
2630
        mem_ctx = talloc_new(NULL);
 
2631
        if (mem_ctx == NULL) {
 
2632
                DEBUG(0, ("talloc_new failed\n"));
 
2633
                return False;
 
2634
        }
 
2635
 
 
2636
        init_enum_hnd(&enum_hnd, 0);
 
2637
 
 
2638
        pipe_hnd = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC, &status);
 
2639
 
 
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);
 
2644
                return False;
 
2645
        }
 
2646
 
 
2647
        werr = rpccli_srvsvc_net_share_enum(pipe_hnd, mem_ctx, 1, &ctr,
 
2648
                                            0xffffffff, &enum_hnd);
 
2649
 
 
2650
        if (!W_ERROR_IS_OK(werr)) {
 
2651
                TALLOC_FREE(mem_ctx);
 
2652
                cli_rpc_pipe_close(pipe_hnd);
 
2653
                return False;
 
2654
        }
 
2655
 
 
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);
 
2664
        }
 
2665
 
 
2666
        TALLOC_FREE(mem_ctx);
 
2667
        cli_rpc_pipe_close(pipe_hnd);
 
2668
        return True;
 
2669
}
 
2670
 
2537
2671
/****************************************************************************
2538
2672
 Try and browse available connections on a host.
2539
2673
****************************************************************************/
2546
2680
                d_printf("\t---------       ----      -------\n");
2547
2681
        }
2548
2682
 
 
2683
        if (browse_host_rpc(sort)) {
 
2684
                return True;
 
2685
        }
 
2686
 
2549
2687
        if((ret = cli_RNetShareEnum(cli, browse_fn, NULL)) == -1)
2550
2688
                d_printf("Error returning browse list: %s\n", cli_errstr(cli));
2551
2689
 
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;
2923
3062
                
2924
 
        if (len >= PATH_MAX)
 
3063
        if (len >= MIN(PATH_MAX,sizeof(pstring))) {
2925
3064
                return(NULL);
 
3065
        }
2926
3066
 
2927
3067
        info.matches = SMB_MALLOC_ARRAY(char *,MAX_COMPLETIONS);
2928
 
        if (!info.matches) return NULL;
 
3068
        if (!info.matches) {
 
3069
                return NULL;
 
3070
        }
2929
3071
        info.matches[0] = NULL;
2930
3072
 
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] == '\\')) {
2933
3075
                        break;
 
3076
                }
 
3077
        }
 
3078
 
2934
3079
        info.text = text+i+1;
2935
3080
        info.samelen = info.len = len-i-1;
2936
3081
 
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);
2941
 
        } else
 
3086
        } else {
2942
3087
                pstr_sprintf(dirmask, "%s*", cur_dir);
 
3088
        }
2943
3089
 
2944
3090
        if (cli_list(cli, dirmask, aDIR | aSYSTEM | aHIDDEN, completion_remote_filter, &info) < 0)
2945
3091
                goto cleanup;
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;
3349
 
        dbf = x_stderr;
3350
 
        x_setbuf( x_stderr, NULL );
 
3495
        if ((dbf = x_fdup(x_stderr))) {
 
3496
                x_setbuf( dbf, NULL );
 
3497
        }
3351
3498
 
3352
3499
        pc = poptGetContext("smbclient", argc, (const char **) argv, long_options, 
3353
3500
                                POPT_CONTEXT_KEEP_FIRST);
3380
3527
                        }
3381
3528
                        break;
3382
3529
                case 'E':
 
3530
                        if (dbf) {
 
3531
                                x_fclose(dbf);
 
3532
                        }
3383
3533
                        dbf = x_stderr;
3384
3534
                        display_set_stderr();
3385
3535
                        break;
3449
3599
        if ( override_logfile )
3450
3600
                setup_logging( lp_logfile(), False );
3451
3601
        
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);
3455
3605
        }
3536
3686
                return 1;
3537
3687
        }
3538
3688
 
 
3689
        talloc_destroy( ctx);
3539
3690
        return rc;
3540
3691
}