static char CLI_DIRSEP_CHAR = '\\';
static char CLI_DIRSEP_STR[] = { '\\', '\0' };
+/* Authentication for client connections. */
+struct user_auth_info *auth_info;
+
/* Accessor functions for directory paths. */
static char *fileselection;
static const char *client_get_fileselection(void)
char *targetpath = NULL;
TALLOC_CTX *ctx = talloc_tos();
- if ( !cli_resolve_path(ctx, "", cli, client_get_cur_dir(), &targetcli, &targetpath)) {
+ if ( !cli_resolve_path(ctx, "", auth_info, cli, client_get_cur_dir(), &targetcli, &targetpath)) {
d_printf("Error in dskattr: %s\n", cli_errstr(cli));
return 1;
}
- if (!cli_dskattr(targetcli, &bsize, &total, &avail)) {
+ if (!NT_STATUS_IS_OK(cli_dskattr(targetcli, &bsize, &total, &avail))) {
d_printf("Error in dskattr: %s\n",cli_errstr(targetcli));
return 1;
}
new_cd = clean_name(ctx, new_cd);
client_set_cur_dir(new_cd);
- if ( !cli_resolve_path(ctx, "", cli, new_cd, &targetcli, &targetpath)) {
+ if ( !cli_resolve_path(ctx, "", auth_info, cli, new_cd, &targetcli, &targetpath)) {
d_printf("cd %s: %s\n", new_cd, cli_errstr(cli));
client_set_cur_dir(saved_dir);
goto out;
goto out;
}
- if (!cli_chkpath(targetcli, targetpath)) {
+ if (!NT_STATUS_IS_OK(cli_chkpath(targetcli, targetpath))) {
d_printf("cd %s: %s\n", new_cd, cli_errstr(targetcli));
client_set_cur_dir(saved_dir);
goto out;
dir_total += finfo->size;
} else {
char *afname = NULL;
- int fnum;
+ uint16_t fnum;
/* skip if this is . or .. */
if ( strequal(finfo->name,"..") || strequal(finfo->name,".") )
return;
- /* create absolute filename for cli_nt_create() FIXME */
+ /* create absolute filename for cli_ntcreate() FIXME */
afname = talloc_asprintf(ctx,
"%s%s%s",
dir,
d_printf( "MODE:%s\n", attrib_string(finfo->mode));
d_printf( "SIZE:%.0f\n", (double)finfo->size);
d_printf( "MTIME:%s", time_to_asc(t));
- fnum = cli_nt_create(finfo->cli, afname, CREATE_ACCESS_READ);
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(finfo->cli, afname, 0,
+ CREATE_ACCESS_READ, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
+ FILE_OPEN, 0x0, 0x0, &fnum))) {
DEBUG( 0, ("display_finfo() Failed to open %s: %s\n",
afname,
cli_errstr( finfo->cli)));
/* check for dfs */
- if ( !cli_resolve_path(ctx, "", cli, head, &targetcli, &targetpath ) ) {
+ if ( !cli_resolve_path(ctx, "", auth_info, cli, head, &targetcli, &targetpath ) ) {
d_printf("do_list: [%s] %s\n", head, cli_errstr(cli));
remove_do_list_queue_head();
continue;
}
} else {
/* check for dfs */
- if (cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetpath)) {
+ if (cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetpath)) {
if (cli_list(targetcli, targetpath, attribute, do_list_helper, NULL) == -1) {
d_printf("%s listing %s\n",
cli_errstr(targetcli), targetpath);
static int do_get(const char *rname, const char *lname_in, bool reget)
{
TALLOC_CTX *ctx = talloc_tos();
- int handle = 0, fnum;
+ int handle = 0;
+ uint16_t fnum;
bool newhandle = false;
struct timeval tp_start;
uint16 attr;
strlower_m(lname);
}
- if (!cli_resolve_path(ctx, "", cli, rname, &targetcli, &targetname ) ) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli, &targetname ) ) {
d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli));
return 1;
}
GetTimeOfDay(&tp_start);
- fnum = cli_open(targetcli, targetname, O_RDONLY, DENY_NONE);
-
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(cli_open(targetcli, targetname, O_RDONLY, DENY_NONE, &fnum))) {
d_printf("%s opening remote file %s\n",cli_errstr(cli),rname);
return 1;
}
if (!cli_qfileinfo(targetcli, fnum,
&attr, &size, NULL, NULL, NULL, NULL, NULL) &&
- !cli_getattrE(targetcli, fnum,
- &attr, &size, NULL, NULL, NULL)) {
+ !NT_STATUS_IS_OK(cli_getattrE(targetcli, fnum,
+ &attr, &size, NULL, NULL, NULL))) {
d_printf("getattrib: %s\n",cli_errstr(targetcli));
return 1;
}
return 1;
}
- if (!cli_close(targetcli, fnum)) {
+ if (!NT_STATUS_IS_OK(cli_close(targetcli, fnum))) {
d_printf("Error %s closing remote file\n",cli_errstr(cli));
rc = 1;
}
if (!lname) {
return 1;
}
- fd = smb_mkstemp(lname);
+ fd = mkstemp(lname);
if (fd == -1) {
d_printf("failed to create temporary file for more\n");
return 1;
struct cli_state *targetcli;
char *targetname = NULL;
- if (!cli_resolve_path(ctx, "", cli, name, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli, &targetname)) {
d_printf("mkdir %s: %s\n", name, cli_errstr(cli));
return false;
}
- if (!cli_mkdir(targetcli, targetname)) {
+ if (!NT_STATUS_IS_OK(cli_mkdir(targetcli, targetname))) {
d_printf("%s making remote directory %s\n",
cli_errstr(targetcli),name);
return false;
static int cmd_quit(void)
{
- cli_cm_shutdown();
+ cli_shutdown(cli);
exit(0);
/* NOTREACHED */
return 0;
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
return 1;
}
if (!ddir2) {
return 1;
}
- if (!cli_chkpath(targetcli, ddir2)) {
+ if (!NT_STATUS_IS_OK(cli_chkpath(targetcli, ddir2))) {
do_mkdir(ddir2);
}
ddir2 = talloc_asprintf_append(ddir2, "%s", CLI_DIRSEP_STR);
static int do_put(const char *rname, const char *lname, bool reput)
{
TALLOC_CTX *ctx = talloc_tos();
- int fnum;
+ uint16_t fnum;
XFILE *f;
SMB_OFF_T start = 0;
int rc = 0;
struct push_state state;
NTSTATUS status;
- if (!cli_resolve_path(ctx, "", cli, rname, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli, &targetname)) {
d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli));
return 1;
}
GetTimeOfDay(&tp_start);
if (reput) {
- fnum = cli_open(targetcli, targetname, O_RDWR|O_CREAT, DENY_NONE);
- if (fnum >= 0) {
+ status = cli_open(targetcli, targetname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
+ if (NT_STATUS_IS_OK(status)) {
if (!cli_qfileinfo(targetcli, fnum, NULL, &start, NULL, NULL, NULL, NULL, NULL) &&
- !cli_getattrE(targetcli, fnum, NULL, &start, NULL, NULL, NULL)) {
+ !NT_STATUS_IS_OK(cli_getattrE(targetcli, fnum, NULL, &start, NULL, NULL, NULL))) {
d_printf("getattrib: %s\n",cli_errstr(cli));
return 1;
}
}
} else {
- fnum = cli_open(targetcli, targetname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
+ status = cli_open(targetcli, targetname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnum);
}
- if (fnum == -1) {
+ if (!NT_STATUS_IS_OK(status)) {
d_printf("%s opening remote file %s\n",cli_errstr(targetcli),rname);
return 1;
}
d_fprintf(stderr, "cli_push returned %s\n", nt_errstr(status));
}
- if (!cli_close(targetcli, fnum)) {
+ if (!NT_STATUS_IS_OK(cli_close(targetcli, fnum))) {
d_printf("%s closing remote file %s\n",cli_errstr(cli),rname);
x_fclose(f);
return 1;
}
if (f == x_stdin) {
- cli_cm_shutdown();
+ cli_shutdown(cli);
exit(0);
}
Free a file_list structure.
****************************************************************************/
-static void free_file_list (struct file_list *list_head)
+static void free_file_list (struct file_list *l_head)
{
struct file_list *list, *next;
- for (list = list_head; list; list = next) {
+ for (list = l_head; list; list = next) {
next = list->next;
- DLIST_REMOVE(list_head, list);
+ DLIST_REMOVE(l_head, list);
SAFE_FREE(list->file_path);
SAFE_FREE(list);
}
break;
}
normalize_name(rname);
- if (!cli_chkpath(cli, rname) &&
+ if (!NT_STATUS_IS_OK(cli_chkpath(cli, rname)) &&
!do_mkdir(rname)) {
DEBUG (0, ("Unable to make dir, skipping..."));
/* Skip the directory */
return;
}
- if (!cli_unlink(finfo->cli, mask)) {
+ if (!NT_STATUS_IS_OK(cli_unlink(finfo->cli, mask, aSYSTEM | aHIDDEN))) {
d_printf("%s deleting remote file %s\n",
cli_errstr(finfo->cli),mask);
}
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("cmd_wdel %s: %s\n", mask, cli_errstr(cli));
return 1;
}
- if (!cli_unlink_full(targetcli, targetname, attribute)) {
+ if (!NT_STATUS_IS_OK(cli_unlink(targetcli, targetname, attribute))) {
d_printf("%s deleting remote files %s\n",cli_errstr(targetcli),targetname);
}
return 0;
char *buf = NULL;
char *targetname = NULL;
struct cli_state *targetcli;
- int fnum;
+ uint16_t fnum = (uint16_t)-1;
if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
d_printf("open <filename>\n");
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("open %s: %s\n", mask, cli_errstr(cli));
return 1;
}
- fnum = cli_nt_create(targetcli, targetname, FILE_READ_DATA|FILE_WRITE_DATA);
- if (fnum == -1) {
- fnum = cli_nt_create(targetcli, targetname, FILE_READ_DATA);
- if (fnum != -1) {
+ if (!NT_STATUS_IS_OK(cli_ntcreate(targetcli, targetname, 0,
+ FILE_READ_DATA|FILE_WRITE_DATA, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
+ if (NT_STATUS_IS_OK(cli_ntcreate(targetcli, targetname, 0,
+ FILE_READ_DATA, 0,
+ FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum))) {
d_printf("open file %s: for read/write fnum %d\n", targetname, fnum);
} else {
d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli));
}
mode = (mode_t)strtol(buf, (char **)NULL, 8);
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("posix_open %s: %s\n", mask, cli_errstr(cli));
return 1;
}
}
mode = (mode_t)strtol(buf, (char **)NULL, 8);
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("posix_mkdir %s: %s\n", mask, cli_errstr(cli));
return 1;
}
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("posix_unlink %s: %s\n", mask, cli_errstr(cli));
return 1;
}
- if (!cli_posix_unlink(targetcli, targetname)) {
+ if (!NT_STATUS_IS_OK(cli_posix_unlink(targetcli, targetname))) {
d_printf("Failed to unlink file %s. %s\n", targetname, cli_errstr(cli));
} else {
d_printf("posix_unlink deleted file %s\n", targetname);
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("posix_rmdir %s: %s\n", mask, cli_errstr(cli));
return 1;
}
- if (!cli_posix_rmdir(targetcli, targetname)) {
+ if (!NT_STATUS_IS_OK(cli_posix_rmdir(targetcli, targetname))) {
d_printf("Failed to unlink directory %s. %s\n", targetname, cli_errstr(cli));
} else {
d_printf("posix_rmdir deleted directory %s\n", targetname);
fnum = atoi(buf);
/* We really should use the targetcli here.... */
- if (!cli_close(cli, fnum)) {
+ if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) {
d_printf("close %d: %s\n", fnum, cli_errstr(cli));
return 1;
}
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) {
d_printf("rmdir %s: %s\n", mask, cli_errstr(cli));
return 1;
}
- if (!cli_rmdir(targetcli, targetname)) {
+ if (!NT_STATUS_IS_OK(cli_rmdir(targetcli, targetname))) {
d_printf("%s removing remote directory file %s\n",
cli_errstr(targetcli),mask);
}
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, oldname, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli, &targetname)) {
d_printf("link %s: %s\n", oldname, cli_errstr(cli));
return 1;
}
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, oldname, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli, &targetname)) {
d_printf("link %s: %s\n", oldname, cli_errstr(cli));
return 1;
}
mode = (mode_t)strtol(buf, NULL, 8);
- if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) {
d_printf("chmod %s: %s\n", src, cli_errstr(cli));
return 1;
}
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) {
d_printf("stat %s: %s\n", src, cli_errstr(cli));
return 1;
}
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) {
d_printf("stat %s: %s\n", src, cli_errstr(cli));
return 1;
}
if (!src) {
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname) ) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname) ) {
d_printf("chown %s: %s\n", src, cli_errstr(cli));
return 1;
}
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetsrc)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetsrc)) {
d_printf("rename %s: %s\n", src, cli_errstr(cli));
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, dest, &targetcli, &targetdest)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, dest, &targetcli, &targetdest)) {
d_printf("rename %s: %s\n", dest, cli_errstr(cli));
return 1;
}
- if (!cli_rename(targetcli, targetsrc, targetdest)) {
+ if (!NT_STATUS_IS_OK(cli_rename(targetcli, targetsrc, targetdest))) {
d_printf("%s renaming files %s -> %s \n",
cli_errstr(targetcli),
targetsrc,
return 1;
}
- if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) {
d_printf("hardlink %s: %s\n", src, cli_errstr(cli));
return 1;
}
- if (!cli_nt_hardlink(targetcli, targetname, dest)) {
+ if (!NT_STATUS_IS_OK(cli_nt_hardlink(targetcli, targetname, dest))) {
d_printf("%s doing an NT hard link of files\n",cli_errstr(targetcli));
return 1;
}
static int cmd_list_connect(void)
{
- cli_cm_display();
+ cli_cm_display(cli);
return 0;
}
struct cli_state *targetcli;
char *targetpath;
- if (!cli_resolve_path(ctx, "", cli, client_get_cur_dir(),
+ if (!cli_resolve_path(ctx, "", auth_info, cli, client_get_cur_dir(),
&targetcli, &targetpath ) ) {
d_printf("showconnect %s: %s\n", cur_dir, cli_errstr(cli));
return 1;
if (!cli) {
cli = cli_cm_open(talloc_tos(), NULL,
have_ip ? dest_ss_str : desthost,
- service, true, smb_encrypt,
- max_protocol);
+ service, auth_info,
+ true, smb_encrypt,
+ max_protocol, port, name_type);
if (!cli) {
return 1;
}
goto cleanup;
}
- if (!cli_resolve_path(ctx, "", cli, dirmask, &targetcli, &targetpath)) {
+ if (!cli_resolve_path(ctx, "", auth_info, cli, dirmask, &targetcli, &targetpath)) {
goto cleanup;
}
if (cli_list(targetcli, targetpath, aDIR | aSYSTEM | aHIDDEN,
cli = cli_cm_open(talloc_tos(), NULL,
have_ip ? dest_ss_str : desthost,
- service, true, smb_encrypt,
- max_protocol);
+ service, auth_info, true, smb_encrypt,
+ max_protocol, port, name_type);
if (!cli) {
return 1;
}
if (base_directory && *base_directory) {
rc = do_cd(base_directory);
if (rc) {
- cli_cm_shutdown();
+ cli_shutdown(cli);
return rc;
}
}
process_stdin();
}
- cli_cm_shutdown();
+ cli_shutdown(cli);
return rc;
}
static int do_host_query(const char *query_host)
{
- struct sockaddr_storage ss;
-
cli = cli_cm_open(talloc_tos(), NULL,
- query_host, "IPC$", true, smb_encrypt,
- max_protocol);
+ query_host, "IPC$", auth_info, true, smb_encrypt,
+ max_protocol, port, name_type);
if (!cli)
return 1;
browse_host(true);
- if (interpret_string_addr(&ss, query_host, 0) && (ss.ss_family != AF_INET)) {
- d_printf("%s is an IPv6 address -- no workgroup available\n",
- query_host);
- return 1;
+ /* Ensure that the host can do IPv4 */
+
+ if (!interpret_addr(query_host)) {
+ struct sockaddr_storage ss;
+ if (interpret_string_addr(&ss, query_host, 0) &&
+ (ss.ss_family != AF_INET)) {
+ d_printf("%s is an IPv6 address -- no workgroup available\n",
+ query_host);
+ return 1;
+ }
}
if (port != 139) {
/* Workgroups simply don't make sense over anything
else but port 139... */
- cli_cm_shutdown();
- cli_cm_set_port( 139 );
+ cli_shutdown(cli);
cli = cli_cm_open(talloc_tos(), NULL,
- query_host, "IPC$", true, smb_encrypt,
- max_protocol);
+ query_host, "IPC$", auth_info, true, smb_encrypt,
+ max_protocol, 139, name_type);
}
if (cli == NULL) {
list_servers(lp_workgroup());
- cli_cm_shutdown();
+ cli_shutdown(cli);
return(0);
}
if (!cli) {
cli = cli_cm_open(talloc_tos(), NULL,
have_ip ? dest_ss_str : desthost,
- service, true, smb_encrypt,
- max_protocol);
+ service, auth_info, true, smb_encrypt,
+ max_protocol, port, name_type);
if (!cli)
return 1;
}
if (base_directory && *base_directory) {
ret = do_cd(base_directory);
if (ret) {
- cli_cm_shutdown();
+ cli_shutdown(cli);
return ret;
}
}
ret=process_tar();
- cli_cm_shutdown();
+ cli_shutdown(cli);
return(ret);
}
Handle a message operation.
****************************************************************************/
-static int do_message_op(struct user_auth_info *auth_info)
+static int do_message_op(struct user_auth_info *a_info)
{
struct sockaddr_storage ss;
struct nmb_name called, calling;
msg_port = port ? port : 139;
- if (!(cli=cli_initialise()) || (cli_set_port(cli, msg_port) != msg_port)) {
+ if (!(cli=cli_initialise())) {
d_printf("Connection to %s failed\n", desthost);
return 1;
}
+ cli_set_port(cli, msg_port);
status = cli_connect(cli, server_name, &ss);
if (!NT_STATUS_IS_OK(status)) {
if (!cli_session_request(cli, &calling, &called)) {
d_printf("session request failed\n");
- cli_cm_shutdown();
+ cli_shutdown(cli);
return 1;
}
- send_message(get_cmdline_auth_info_username(auth_info));
- cli_cm_shutdown();
+ send_message(get_cmdline_auth_info_username(a_info));
+ cli_shutdown(cli);
return 0;
}
POPT_TABLEEND
};
TALLOC_CTX *frame = talloc_stackframe();
- struct user_auth_info *auth_info;
if (!client_set_cur_dir("\\")) {
exit(ENOMEM);
* to port 139 instead of port 445. srl,crh
*/
name_type = 0x03;
- cli_cm_set_dest_name_type( name_type );
desthost = talloc_strdup(frame,poptGetOptArg(pc));
if (!desthost) {
exit(ENOMEM);
}
if( !port )
- cli_cm_set_port( 139 );
+ port = 139;
message = true;
break;
case 'I':
poptGetArg(pc));
}
- /* check for the -P option */
-
- if ( port != 0 )
- cli_cm_set_port( port );
-
/*
* Don't load debug level from smb.conf. It should be
* set by cmdline arg or remain default (0)
poptFreeContext(pc);
- /* Store the username and password for dfs support */
-
- cli_cm_set_credentials(auth_info);
+ DEBUG(3,("Client started (version %s).\n", samba_version_string()));
- DEBUG(3,("Client started (version %s).\n", SAMBA_VERSION_STRING));
+ /* Ensure we have a password (or equivalent). */
+ set_cmdline_auth_info_getpass(auth_info);
if (tar_type) {
if (cmdstr)
*p = 0;
p++;
sscanf(p, "%x", &name_type);
- cli_cm_set_dest_name_type( name_type );
}
return do_host_query(qhost);