2 smbget: a wget-like utility with support for recursive downloading of
4 Copyright (C) 2003-2004 Jelmer Vernooij <jelmer@samba.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "system/filesys.h"
21 #include "lib/cmdline/cmdline.h"
22 #include "lib/param/param.h"
23 #include "libsmbclient.h"
24 #include "cmdline_contexts.h"
25 #include "auth/credentials/credentials.h"
26 #include "auth/gensec/gensec.h"
28 static int columns
= 0;
30 static time_t total_start_time
= 0;
31 static off_t total_bytes
= 0;
33 #define SMB_MAXPATHLEN MAXPATHLEN
36 * Number of bytes to read when checking whether local and remote file
37 * are really the same file
39 #define RESUME_CHECK_SIZE 512
40 #define RESUME_DOWNLOAD_OFFSET 1024
41 #define RESUME_CHECK_OFFSET (RESUME_DOWNLOAD_OFFSET+RESUME_CHECK_SIZE)
42 /* Number of bytes to read at once */
43 #define SMB_DEFAULT_BLOCKSIZE 64000
56 static struct opt opt
= { .blocksize
= SMB_DEFAULT_BLOCKSIZE
};
58 static bool smb_download_file(const char *base
, const char *name
,
59 bool recursive
, bool resume
, bool toplevel
,
62 static int get_num_cols(void)
66 if (ioctl(STDOUT_FILENO
, TIOCGWINSZ
, &ws
) < 0) {
71 #warning No support for TIOCGWINSZ
72 char *cols
= getenv("COLUMNS");
80 static void change_columns(int sig
)
82 columns
= get_num_cols();
85 static void human_readable(off_t s
, char *buffer
, int l
)
87 if (s
> 1024 * 1024 * 1024) {
88 snprintf(buffer
, l
, "%.2fGB", 1.0 * s
/ (1024 * 1024 * 1024));
89 } else if (s
> 1024 * 1024) {
90 snprintf(buffer
, l
, "%.2fMB", 1.0 * s
/ (1024 * 1024));
91 } else if (s
> 1024) {
92 snprintf(buffer
, l
, "%.2fkB", 1.0 * s
/ 1024);
94 snprintf(buffer
, l
, "%jdb", (intmax_t)s
);
99 * Authentication callback for libsmbclient.
101 * The command line parser will take care asking for a password interactively!
103 static void get_auth_data_with_context_fn(SMBCCTX
*ctx
,
113 struct cli_credentials
*creds
= samba_cmdline_get_creds();
114 const char *username
= NULL
;
115 const char *password
= NULL
;
116 const char *domain
= NULL
;
117 enum credentials_obtained obtained
= CRED_UNINITIALISED
;
119 domain
= cli_credentials_get_domain_and_obtained(creds
, &obtained
);
120 if (domain
!= NULL
) {
121 bool overwrite
= false;
122 if (dom
[0] == '\0') {
125 if (obtained
>= CRED_CALLBACK_RESULT
) {
129 strncpy(dom
, domain
, dom_len
- 1);
132 cli_credentials_set_domain(creds
, dom
, obtained
);
134 username
= cli_credentials_get_username_and_obtained(creds
, &obtained
);
135 if (username
!= NULL
) {
136 bool overwrite
= false;
137 if (usr
[0] == '\0') {
140 if (obtained
>= CRED_CALLBACK_RESULT
) {
144 strncpy(usr
, username
, usr_len
- 1);
147 cli_credentials_set_username(creds
, usr
, obtained
);
149 password
= cli_credentials_get_password_and_obtained(creds
, &obtained
);
150 if (password
!= NULL
) {
151 bool overwrite
= false;
152 if (pwd
[0] == '\0') {
155 if (obtained
>= CRED_CALLBACK_RESULT
) {
159 strncpy(pwd
, password
, pwd_len
- 1);
162 cli_credentials_set_password(creds
, pwd
, obtained
);
164 smbc_set_credentials_with_fallback(ctx
, dom
, usr
, pwd
);
167 if (usr
[0] == '\0') {
168 printf("Using guest user\n");
169 } else if (dom
[0] == '\0') {
170 printf("Using user: %s\n", usr
);
172 printf("Using domain: %s, user: %s\n", dom
, usr
);
177 static bool smb_download_dir(const char *base
, const char *name
, int resume
)
179 char path
[SMB_MAXPATHLEN
];
181 struct smbc_dirent
*dirent
;
182 const char *relname
= name
;
186 snprintf(path
, SMB_MAXPATHLEN
-1, "%s%s%s", base
,
187 (base
[0] && name
[0] && name
[0] != '/' &&
188 base
[strlen(base
)-1] != '/') ? "/" : "",
191 /* List files in directory and call smb_download_file on them */
192 dirhandle
= smbc_opendir(path
);
194 if (errno
== ENOTDIR
) {
195 return smb_download_file(base
, name
, true, resume
,
198 fprintf(stderr
, "Can't open directory %s: %s\n", path
,
203 while (*relname
== '/') {
207 if (strlen(relname
) > 0) {
208 int rc
= mkdir(relname
, 0755);
209 if (rc
== -1 && errno
!= EEXIST
) {
210 fprintf(stderr
, "Can't create directory %s: %s\n",
211 relname
, strerror(errno
));
216 tmpname
= SMB_STRDUP(name
);
218 while ((dirent
= smbc_readdir(dirhandle
))) {
220 if (!strcmp(dirent
->name
, ".") || !strcmp(dirent
->name
, "..")) {
224 if (asprintf(&newname
, "%s/%s", tmpname
, dirent
->name
) == -1) {
228 switch (dirent
->smbc_type
) {
230 ok
= smb_download_dir(base
, newname
, resume
);
234 ok
= smb_download_dir("smb://", dirent
->name
, resume
);
238 ok
= smb_download_dir("smb://", dirent
->name
, resume
);
242 ok
= smb_download_file(base
, newname
, true, resume
,
246 case SMBC_FILE_SHARE
:
247 ok
= smb_download_dir(base
, newname
, resume
);
250 case SMBC_PRINTER_SHARE
:
252 printf("Ignoring printer share %s\n",
257 case SMBC_COMMS_SHARE
:
259 printf("Ignoring comms share %s\n",
266 printf("Ignoring ipc$ share %s\n",
272 fprintf(stderr
, "Ignoring file '%s' of type '%d'\n",
273 newname
, dirent
->smbc_type
);
278 fprintf(stderr
, "Failed to download %s: %s\n",
279 newname
, strerror(errno
));
288 smbc_closedir(dirhandle
);
292 static char *print_time(long t
)
294 static char buffer
[100];
295 int secs
, mins
, hours
;
297 strncpy(buffer
, "Unknown", sizeof(buffer
));
302 mins
= (int)t
/ 60 % 60;
303 hours
= (int)t
/ (60 * 60);
304 snprintf(buffer
, sizeof(buffer
) - 1, "%02d:%02d:%02d", hours
, mins
,
309 static void print_progress(const char *name
, time_t start
, time_t now
,
310 off_t start_pos
, off_t pos
, off_t total
)
315 char hpos
[22], htotal
[22], havg
[22];
316 char *status
, *filename
;
319 avg
= 1.0 * (pos
- start_pos
) / (now
- start
);
321 eta
= (total
- pos
) / avg
;
323 prcnt
= 100.0 * pos
/ total
;
326 human_readable(pos
, hpos
, sizeof(hpos
));
327 human_readable(total
, htotal
, sizeof(htotal
));
328 human_readable(avg
, havg
, sizeof(havg
));
330 len
= asprintf(&status
, "%s of %s (%.2f%%) at %s/s ETA: %s", hpos
,
331 htotal
, prcnt
, havg
, print_time(eta
));
337 int required
= strlen(name
),
338 available
= columns
- len
- strlen("[] ");
339 if (required
> available
) {
340 if (asprintf(&filename
, "...%s",
341 name
+ required
- available
+ 3) == -1) {
345 filename
= SMB_STRNDUP(name
, available
);
348 filename
= SMB_STRDUP(name
);
351 fprintf(stderr
, "\r[%s] %s", filename
, status
);
357 /* Return false on error, true on success. */
359 static bool smb_download_file(const char *base
, const char *name
,
360 bool recursive
, bool resume
, bool toplevel
,
363 int remotehandle
, localhandle
;
364 time_t start_time
= time_mono(NULL
);
366 char path
[SMB_MAXPATHLEN
];
367 char checkbuf
[2][RESUME_CHECK_SIZE
];
368 char *readbuf
= NULL
;
369 off_t offset_download
= 0, offset_check
= 0, curpos
= 0,
371 struct stat localstat
, remotestat
;
372 clock_t start_of_bucket_ticks
= 0;
373 size_t bytes_in_bucket
= 0;
374 size_t bucket_size
= 0;
375 clock_t ticks_to_fill_bucket
= 0;
377 snprintf(path
, SMB_MAXPATHLEN
-1, "%s%s%s", base
,
378 (*base
&& *name
&& name
[0] != '/' &&
379 base
[strlen(base
)-1] != '/') ? "/" : "",
382 remotehandle
= smbc_open(path
, O_RDONLY
, 0755);
384 if (remotehandle
< 0) {
389 "%s is a directory. Specify -R "
390 "to download recursively\n",
394 return smb_download_dir(base
, name
, resume
);
398 "%s can't be found on the remote server\n",
403 fprintf(stderr
, "Not enough memory\n");
408 "The share name used in %s does not exist\n",
413 fprintf(stderr
, "You don't have enough permissions "
424 if (smbc_fstat(remotehandle
, &remotestat
) < 0) {
425 fprintf(stderr
, "Can't stat %s: %s\n", path
, strerror(errno
));
431 } else if (!name
[0]) {
432 newpath
= strrchr(base
, '/');
442 if (!toplevel
&& (newpath
[0] == '/')) {
446 /* Open local file according to the mode */
448 /* if it is up-to-date, skip */
449 if (stat(newpath
, &localstat
) == 0 &&
450 localstat
.st_mtime
>= remotestat
.st_mtime
) {
452 printf("%s is up-to-date, skipping\n", newpath
);
454 smbc_close(remotehandle
);
457 /* else open it for writing and truncate if it exists */
459 newpath
, O_CREAT
| O_NONBLOCK
| O_RDWR
| O_TRUNC
, 0775);
460 if (localhandle
< 0) {
461 fprintf(stderr
, "Can't open %s : %s\n", newpath
,
463 smbc_close(remotehandle
);
467 } else if (!opt
.send_stdout
) {
468 localhandle
= open(newpath
, O_CREAT
| O_NONBLOCK
| O_RDWR
|
469 (!resume
? O_EXCL
: 0),
471 if (localhandle
< 0) {
472 fprintf(stderr
, "Can't open %s: %s\n", newpath
,
474 smbc_close(remotehandle
);
478 if (fstat(localhandle
, &localstat
) != 0) {
479 fprintf(stderr
, "Can't fstat %s: %s\n", newpath
,
481 smbc_close(remotehandle
);
486 start_offset
= localstat
.st_size
;
488 if (localstat
.st_size
&&
489 localstat
.st_size
== remotestat
.st_size
) {
491 fprintf(stderr
, "%s is already downloaded "
494 } else if (!opt
.quiet
) {
495 fprintf(stderr
, "%s\n", path
);
497 smbc_close(remotehandle
);
502 if (localstat
.st_size
> RESUME_CHECK_OFFSET
&&
503 remotestat
.st_size
> RESUME_CHECK_OFFSET
) {
505 localstat
.st_size
- RESUME_DOWNLOAD_OFFSET
;
506 offset_check
= localstat
.st_size
- RESUME_CHECK_OFFSET
;
508 printf("Trying to start resume of %s at %jd\n"
509 "At the moment %jd of %jd bytes have "
511 newpath
, (intmax_t)offset_check
,
512 (intmax_t)localstat
.st_size
,
513 (intmax_t)remotestat
.st_size
);
519 /* First, check all bytes from offset_check to
521 off1
= lseek(localhandle
, offset_check
, SEEK_SET
);
524 "Can't seek to %jd in local file %s\n",
525 (intmax_t)offset_check
, newpath
);
526 smbc_close(remotehandle
);
531 off2
= smbc_lseek(remotehandle
, offset_check
, SEEK_SET
);
534 "Can't seek to %jd in remote file %s\n",
535 (intmax_t)offset_check
, newpath
);
536 smbc_close(remotehandle
);
542 fprintf(stderr
, "Offset in local and remote "
543 "files are different "
544 "(local: %jd, remote: %jd)\n",
545 (intmax_t)off1
, (intmax_t)off2
);
546 smbc_close(remotehandle
);
551 if (smbc_read(remotehandle
, checkbuf
[0],
552 RESUME_CHECK_SIZE
) != RESUME_CHECK_SIZE
) {
553 fprintf(stderr
, "Can't read %d bytes from "
555 RESUME_CHECK_SIZE
, path
);
556 smbc_close(remotehandle
);
561 if (read(localhandle
, checkbuf
[1], RESUME_CHECK_SIZE
) !=
563 fprintf(stderr
, "Can't read %d bytes from "
565 RESUME_CHECK_SIZE
, name
);
566 smbc_close(remotehandle
);
571 if (memcmp(checkbuf
[0], checkbuf
[1],
572 RESUME_CHECK_SIZE
) == 0) {
574 printf("Current local and remote file "
575 "appear to be the same. "
576 "Starting download from "
578 (intmax_t)offset_download
);
581 fprintf(stderr
, "Local and remote file appear "
582 "to be different, not "
583 "doing resume for %s\n",
585 smbc_close(remotehandle
);
591 localhandle
= STDOUT_FILENO
;
597 /* We implement rate limiting by filling up a bucket with bytes and
598 * checking, once the bucket is filled, if it was filled too fast.
599 * If so, we sleep for some time to get an average transfer rate that
600 * equals to the one set by the user.
602 * The bucket size directly affects the traffic characteristics.
603 * The smaller the bucket the more frequent the pause/resume cycle.
604 * A large bucket can result in burst of high speed traffic and large
605 * pauses. A cycle of 100ms looks like a good value. This value (in
606 * ticks) is held in `ticks_to_fill_bucket`. The `bucket_size` is
608 * `limit_rate * 1024 * / (CLOCKS_PER_SEC / ticks_to_fill_bucket)`
610 * After selecting the bucket size we also need to check the blocksize
611 * of the transfer, since this is the minimum unit of traffic that we
612 * can observe. Achieving a ~10% precision requires a blocksize with a
613 * maximum size of `bucket_size / 10`.
615 if (opt
.limit_rate
> 0) {
616 unsigned max_block_size
;
617 /* This is the time that the bucket should take to fill. */
618 ticks_to_fill_bucket
= 100 /*ms*/ * CLOCKS_PER_SEC
/ 1000;
619 /* This is the size of the bucket in bytes.
620 * If we fill the bucket too quickly we should pause */
621 bucket_size
= opt
.limit_rate
* 1024 / (CLOCKS_PER_SEC
/ ticks_to_fill_bucket
);
622 max_block_size
= bucket_size
/ 10;
623 max_block_size
= max_block_size
> 0 ? max_block_size
: 1;
624 if (opt
.blocksize
> max_block_size
) {
625 if (opt
.blocksize
!= SMB_DEFAULT_BLOCKSIZE
) {
627 "Warning: Overriding block size to %d "
628 "due to limit-rate", max_block_size
);
630 opt
.blocksize
= max_block_size
;
632 start_of_bucket_ticks
= clock();
635 readbuf
= (char *)SMB_MALLOC(opt
.blocksize
);
637 fprintf(stderr
, "Failed to allocate %zu bytes for read "
638 "buffer (%s)", opt
.blocksize
, strerror(errno
));
639 if (localhandle
!= STDOUT_FILENO
) {
645 /* Now, download all bytes from offset_download to the end */
646 for (curpos
= offset_download
; curpos
< remotestat
.st_size
;
647 curpos
+= opt
.blocksize
) {
649 ssize_t byteswritten
;
651 /* Rate limiting. This pauses the transfer to limit traffic. */
652 if (opt
.limit_rate
> 0) {
653 if (bytes_in_bucket
> bucket_size
) {
654 clock_t now_ticks
= clock();
655 clock_t diff_ticks
= now_ticks
656 - start_of_bucket_ticks
;
657 /* Check if the bucket filled up too fast. */
658 if (diff_ticks
< ticks_to_fill_bucket
) {
659 /* Pause until `ticks_to_fill_bucket` */
661 = (ticks_to_fill_bucket
- diff_ticks
)
662 * 1000000.0 / CLOCKS_PER_SEC
;
665 /* Reset the byte counter and the ticks. */
667 start_of_bucket_ticks
= clock();
671 bytesread
= smbc_read(remotehandle
, readbuf
, opt
.blocksize
);
672 if (opt
.limit_rate
> 0) {
673 bytes_in_bucket
+= bytesread
;
677 "Can't read %zu bytes at offset %jd, file %s\n",
678 opt
.blocksize
, (intmax_t)curpos
, path
);
679 smbc_close(remotehandle
);
680 if (localhandle
!= STDOUT_FILENO
) {
687 total_bytes
+= bytesread
;
689 byteswritten
= write(localhandle
, readbuf
, bytesread
);
690 if (byteswritten
!= bytesread
) {
692 "Can't write %zd bytes to local file %s at "
693 "offset %jd\n", bytesread
, path
,
696 smbc_close(remotehandle
);
697 if (localhandle
!= STDOUT_FILENO
) {
705 } else if (!opt
.quiet
) {
706 print_progress(newpath
, start_time
, time_mono(NULL
),
707 start_offset
, curpos
,
716 printf("%s downloaded\n", path
);
717 } else if (!opt
.quiet
) {
719 fprintf(stderr
, "\r%s", path
);
721 for (i
= strlen(path
); i
< columns
; i
++) {
728 smbc_close(remotehandle
);
729 if (localhandle
!= STDOUT_FILENO
) {
735 static void clean_exit(void)
738 human_readable(total_bytes
, bs
, sizeof(bs
));
740 fprintf(stderr
, "Downloaded %s in %lu seconds\n", bs
,
741 (unsigned long)(time_mono(NULL
) - total_start_time
));
746 static void signal_quit(int v
)
751 int main(int argc
, char **argv
)
754 const char *file
= NULL
;
755 int smb_encrypt
= false;
756 int resume
= 0, recursive
= 0;
757 TALLOC_CTX
*frame
= talloc_stackframe();
759 const char **argv_const
= discard_const_p(const char *, argv
);
760 struct poptOption long_options
[] = {
766 .argInfo
= POPT_ARG_NONE
,
769 .descrip
= "Work as user guest"
772 .longName
= "encrypt",
774 .argInfo
= POPT_ARG_NONE
,
777 .descrip
= "Encrypt SMB transport"
780 .longName
= "resume",
782 .argInfo
= POPT_ARG_NONE
,
785 .descrip
= "Automatically resume aborted files"
788 .longName
= "update",
790 .argInfo
= POPT_ARG_NONE
,
793 .descrip
= "Download only when remote file is "
794 "newer than local file or local file "
798 .longName
= "recursive",
800 .argInfo
= POPT_ARG_NONE
,
803 .descrip
= "Recursively download files"
806 .longName
= "blocksize",
808 .argInfo
= POPT_ARG_INT
,
809 .arg
= &opt
.blocksize
,
811 .descrip
= "Change number of bytes in a block"
815 .longName
= "outputfile",
817 .argInfo
= POPT_ARG_STRING
,
818 .arg
= &opt
.outputfile
,
820 .descrip
= "Write downloaded data to specified file"
823 .longName
= "stdout",
825 .argInfo
= POPT_ARG_NONE
,
826 .arg
= &opt
.send_stdout
,
828 .descrip
= "Write data to stdout"
833 .argInfo
= POPT_ARG_NONE
,
836 .descrip
= "Show dots as progress indication"
841 .argInfo
= POPT_ARG_NONE
,
844 .descrip
= "Be quiet"
847 .longName
= "verbose",
849 .argInfo
= POPT_ARG_NONE
,
852 .descrip
= "Be verbose"
855 .longName
= "limit-rate",
857 .argInfo
= POPT_ARG_INT
,
858 .arg
= &opt
.limit_rate
,
860 .descrip
= "Limit download speed to this many KB/s"
864 POPT_COMMON_CONNECTION
865 POPT_COMMON_CREDENTIALS
870 poptContext pc
= NULL
;
871 struct cli_credentials
*creds
= NULL
;
872 enum smb_encryption_setting encryption_state
= SMB_ENCRYPTION_DEFAULT
;
873 enum credentials_use_kerberos use_kerberos
= CRED_USE_KERBEROS_DESIRED
;
874 smbc_smb_encrypt_level encrypt_level
= SMBC_ENCRYPTLEVEL_DEFAULT
;
876 enum smb_signing_setting signing_state
= SMB_SIGNING_DEFAULT
;
877 const char *use_signing
= "auto";
879 bool is_nt_hash
= false;
880 uint32_t gensec_features
;
881 bool use_wbccache
= false;
882 SMBCCTX
*smb_ctx
= NULL
;
888 ok
= samba_cmdline_init(frame
,
889 SAMBA_CMDLINE_CONFIG_CLIENT
,
896 signal(SIGWINCH
, change_columns
);
898 signal(SIGINT
, signal_quit
);
899 signal(SIGTERM
, signal_quit
);
901 pc
= samba_popt_get_context(getprogname(),
911 creds
= samba_cmdline_get_creds();
913 while ((c
= poptGetNextOpt(pc
)) != -1) {
916 cli_credentials_set_anonymous(creds
);
918 case POPT_ERROR_BADOPT
:
919 fprintf(stderr
, "\nInvalid option %s: %s\n\n",
920 poptBadOption(pc
, 0), poptStrerror(c
));
921 poptPrintUsage(pc
, stderr
, 0);
927 fprintf(stderr
, "%s: %s\n",
928 poptBadOption(pc
, POPT_BADOPTION_NOALIAS
),
935 if ((opt
.send_stdout
|| resume
|| opt
.outputfile
) && opt
.update
) {
936 fprintf(stderr
, "The -o, -R or -O and -U options can not be "
941 if ((opt
.send_stdout
|| opt
.outputfile
) && recursive
) {
942 fprintf(stderr
, "The -o or -O and -R options can not be "
948 if (opt
.outputfile
&& opt
.send_stdout
) {
949 fprintf(stderr
, "The -o and -O options can not be "
955 samba_cmdline_burn(argc
, argv
);
957 /* smbc_new_context() will set the log level to 0 */
958 dbg_lvl
= debuglevel_get();
960 smb_ctx
= smbc_new_context();
961 if (smb_ctx
== NULL
) {
962 fprintf(stderr
, "Unable to initialize libsmbclient\n");
966 smbc_setDebug(smb_ctx
, dbg_lvl
);
968 rc
= smbc_setConfiguration(smb_ctx
, lp_default_path());
974 smbc_setFunctionAuthDataWithContext(smb_ctx
,
975 get_auth_data_with_context_fn
);
977 ok
= smbc_init_context(smb_ctx
);
981 smbc_set_context(smb_ctx
);
983 encryption_state
= cli_credentials_get_smb_encryption(creds
);
984 switch (encryption_state
) {
985 case SMB_ENCRYPTION_REQUIRED
:
986 encrypt_level
= SMBC_ENCRYPTLEVEL_REQUIRE
;
988 case SMB_ENCRYPTION_DESIRED
:
989 case SMB_ENCRYPTION_IF_REQUIRED
:
990 encrypt_level
= SMBC_ENCRYPTLEVEL_REQUEST
;
992 case SMB_ENCRYPTION_OFF
:
993 encrypt_level
= SMBC_ENCRYPTLEVEL_NONE
;
995 case SMB_ENCRYPTION_DEFAULT
:
996 encrypt_level
= SMBC_ENCRYPTLEVEL_DEFAULT
;
1000 encrypt_level
= SMBC_ENCRYPTLEVEL_REQUIRE
;
1002 smbc_setOptionSmbEncryptionLevel(smb_ctx
, encrypt_level
);
1005 signing_state
= cli_credentials_get_smb_signing(creds
);
1006 if (encryption_state
>= SMB_ENCRYPTION_DESIRED
) {
1007 signing_state
= SMB_SIGNING_REQUIRED
;
1009 switch (signing_state
) {
1010 case SMB_SIGNING_REQUIRED
:
1011 use_signing
= "required";
1013 case SMB_SIGNING_DEFAULT
:
1014 case SMB_SIGNING_DESIRED
:
1015 case SMB_SIGNING_IF_REQUIRED
:
1016 use_signing
= "yes";
1018 case SMB_SIGNING_OFF
:
1019 use_signing
= "off";
1022 use_signing
= "auto";
1025 /* FIXME: There is no libsmbclient function to set signing state */
1028 use_kerberos
= cli_credentials_get_kerberos_state(creds
);
1029 switch (use_kerberos
) {
1030 case CRED_USE_KERBEROS_REQUIRED
:
1031 smbc_setOptionUseKerberos(smb_ctx
, true);
1032 smbc_setOptionFallbackAfterKerberos(smb_ctx
, false);
1034 case CRED_USE_KERBEROS_DESIRED
:
1035 smbc_setOptionUseKerberos(smb_ctx
, true);
1036 smbc_setOptionFallbackAfterKerberos(smb_ctx
, true);
1038 case CRED_USE_KERBEROS_DISABLED
:
1039 smbc_setOptionUseKerberos(smb_ctx
, false);
1043 /* Check if the password supplied is an NT hash */
1044 is_nt_hash
= cli_credentials_is_password_nt_hash(creds
);
1045 smbc_setOptionUseNTHash(smb_ctx
, is_nt_hash
);
1047 /* Check if we should use the winbind ccache */
1048 gensec_features
= cli_credentials_get_gensec_features(creds
);
1049 use_wbccache
= (gensec_features
& GENSEC_FEATURE_NTLM_CCACHE
);
1050 smbc_setOptionUseCCache(smb_ctx
, use_wbccache
);
1052 columns
= get_num_cols();
1054 total_start_time
= time_mono(NULL
);
1056 while ((file
= poptGetArg(pc
))) {
1058 ok
= smb_download_file(file
, "", recursive
, resume
,
1059 true, opt
.outputfile
);
1061 ok
= smb_download_dir(file
, "", resume
);
1067 poptFreeContext(pc
);