#define REGISTER 0
#endif
+const char prog_name[] = "smbclient";
+
struct cli_state *cli;
extern BOOL in_client;
+extern BOOL AllowDebugChange;
static int port = 0;
pstring cur_dir = "\\";
pstring cd_path = "";
static BOOL got_pass;
static int io_bufsize = 64512;
static BOOL use_kerberos;
-extern struct in_addr ipzero;
static int name_type = 0x20;
static int max_protocol = PROTOCOL_NT1;
time_t newer_than = 0;
int archive_level = 0;
-extern pstring debugf;
-
BOOL translation = False;
static BOOL have_ip;
case STYPE_IPC:
fstrcpy(typestr,"IPC"); break;
}
+ /* FIXME: If the remote machine returns non-ascii characters
+ in any of these fields, they can corrupt the output. We
+ should remove them. */
d_printf("\t%-15.15s%-10.10s%s\n",
name,typestr,comment);
}
struct nmb_name called, calling;
const char *server_n;
struct in_addr ip;
- extern struct in_addr ipzero;
fstring servicename;
char *sharename;
server_n = server;
- ip = ipzero;
+ zero_ip(&ip);
make_nmb_name(&calling, global_myname, 0x0);
make_nmb_name(&called , server, name_type);
again:
- ip = ipzero;
+ zero_ip(&ip);
if (have_ip) ip = dest_ip;
/* have to open a new connection */
d_printf("session request to %s failed (%s)\n",
called.name, cli_errstr(c));
cli_shutdown(c);
- SAFE_FREE(c);
if ((p=strchr_m(called.name, '.'))) {
*p = 0;
goto again;
if (!cli_negprot(c)) {
d_printf("protocol negotiation failed\n");
cli_shutdown(c);
- SAFE_FREE(c);
return NULL;
}
password, strlen(password),
workgroup)) {
/* if a password was not supplied then try again with a null username */
- if (password[0] || !username[0] ||
+ if (password[0] || !username[0] || use_kerberos ||
!cli_session_setup(c, "", "", 0, "", 0, workgroup)) {
d_printf("session setup failed: %s\n", cli_errstr(c));
cli_shutdown(c);
- SAFE_FREE(c);
return NULL;
}
d_printf("Anonymous login successful\n");
}
- /*
- * These next two lines are needed to emulate
- * old client behaviour for people who have
- * scripts based on client output.
- * QUESTION ? Do we want to have a 'client compatibility
- * mode to turn these on/off ? JRA.
- */
-
- if (*c->server_domain || *c->server_os || *c->server_type){
+ if (*c->server_domain) {
DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n",
c->server_domain,c->server_os,c->server_type));
+ } else if (*c->server_os || *c->server_type){
+ DEBUG(1,("OS=[%s] Server=[%s]\n",
+ c->server_os,c->server_type));
}
DEBUG(4,(" session setup ok\n"));
password, strlen(password)+1)) {
d_printf("tree connect failed: %s\n", cli_errstr(c));
cli_shutdown(c);
- SAFE_FREE(c);
return NULL;
}
cli = do_connect(desthost, service);
if (!cli) {
- return(False);
+ return 1;
}
if (*base_directory) do_cd(base_directory);
struct in_addr ip;
struct nmb_name called, calling;
- ip = ipzero;
+ zero_ip(&ip);
make_nmb_name(&calling, global_myname, 0x0);
make_nmb_name(&called , desthost, name_type);
- ip = ipzero;
+ zero_ip(&ip);
if (have_ip) ip = dest_ip;
if (!(cli=cli_initialise(NULL)) || (cli_set_port(cli, port) != port) || !cli_connect(cli, desthost, &ip)) {
pstring query_host;
BOOL message = False;
extern char tar_type;
- static pstring servicesf = CONFIGFILE;
pstring term_code;
pstring new_name_resolve_order;
+ pstring logfile;
char *p;
int rc = 0;
*new_name_resolve_order = 0;
DEBUGLEVEL = 2;
+ AllowDebugChange = False;
setup_logging(pname,True);
dbf = x_stderr;
else if(strncmp(argv[opt], "-s", 2) == 0) {
if(argv[opt][2] != '\0')
- pstrcpy(servicesf, &argv[opt][2]);
+ pstrcpy(dyn_CONFIGFILE, &argv[opt][2]);
else if(argv[opt+1] != NULL) {
/*
* At least one more arg left.
*/
- pstrcpy(servicesf, argv[opt+1]);
+ pstrcpy(dyn_CONFIGFILE, argv[opt+1]);
} else {
usage(pname);
exit(1);
}
}
- TimeInit();
-
in_client = True; /* Make sure that we tell lp_load we are */
old_debug = DEBUGLEVEL;
- if (!lp_load(servicesf,True,False,False)) {
- fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf);
+ if (!lp_load(dyn_CONFIGFILE,True,False,False)) {
+ fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n",
+ prog_name, dyn_CONFIGFILE);
}
DEBUGLEVEL = old_debug;
usage(pname);
exit(1);
}
-
+
+ /* FIXME: At the moment, if the user should happen to give the
+ * options ahead of the service name (in standard Unix
+ * fashion) then smbclient just spits out the usage message
+ * with no explanation of what in particular was wrong. Is
+ * there any reason we can't just parse out the service name
+ * and password after running getopt?? -- mbp */
if (*argv[1] != '-') {
pstrcpy(service,argv[1]);
/* Convert any '/' characters in the service name to '\' characters */
getopt(argc, argv,"s:O:R:M:i:Nn:d:Pp:l:hI:EU:L:t:m:W:T:D:c:b:A:k")) != EOF) {
switch (opt) {
case 's':
- pstrcpy(servicesf, optarg);
+ pstrcpy(dyn_CONFIGFILE, optarg);
break;
case 'O':
pstrcpy(user_socket_options,optarg);
port = atoi(optarg);
break;
case 'l':
- slprintf(debugf,sizeof(debugf)-1, "%s.client",optarg);
+ slprintf(logfile,sizeof(logfile)-1, "%s.client",optarg);
+ lp_set_logfile(logfile);
break;
case 'h':
usage(pname);
case 'I':
{
dest_ip = *interpret_addr2(optarg);
- if (zero_ip(dest_ip))
+ if (is_zero_ip(dest_ip))
exit(1);
have_ip = True;
}
}
else if (strwicmp("username", param) == 0)
pstrcpy(username, val);
-
+ else if (strwicmp("domain", param) == 0)
+ pstrcpy(workgroup,val);
memset(buf, 0, sizeof(buf));
}
x_fclose(auth);
io_bufsize = MAX(1, atoi(optarg));
break;
case 'k':
-#if HAVE_KRB5
+#ifdef HAVE_KRB5
use_kerberos = True;
got_pass = True;
#else