svn commit: samba r8751 - in branches/SOC/SAMBA_3_0/source/client: .
kalim at samba.org
kalim at samba.org
Mon Jul 25 05:30:41 GMT 2005
Author: kalim
Date: 2005-07-25 05:30:40 +0000 (Mon, 25 Jul 2005)
New Revision: 8751
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=8751
Log:
Added initialization stuff for libsmb
'cd' command updated
-kalim
Modified:
branches/SOC/SAMBA_3_0/source/client/client.c
Changeset:
Modified: branches/SOC/SAMBA_3_0/source/client/client.c
===================================================================
--- branches/SOC/SAMBA_3_0/source/client/client.c 2005-07-25 04:39:20 UTC (rev 8750)
+++ branches/SOC/SAMBA_3_0/source/client/client.c 2005-07-25 05:30:40 UTC (rev 8751)
@@ -5,6 +5,7 @@
Copyright (C) Simo Sorce 2001-2002
Copyright (C) Jelmer Vernooij 2003
Copyright (C) Gerald (Jerry) Carter 2004
+ Copyright (C) Kalim Moghul 2005
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -23,8 +24,10 @@
#define NO_SYSLOG
-#include "includes.h"
+#include <includes.h>
+#include <libsmbclient.h>
#include "client/client_proto.h"
+#include "client/get_auth_data_fn.h"
#ifndef REGISTER
#define REGISTER 0
#endif
@@ -35,7 +38,7 @@
extern BOOL in_client;
static int port = 0;
pstring cur_dir = "\\";
-static pstring cd_path = "";
+//static pstring cd_path = "";
static pstring service;
static pstring desthost;
static pstring username;
@@ -258,33 +261,60 @@
struct cli_state *targetcli;
SMB_STRUCT_STAT sbuf;
uint32 attributes;
+ int dh;
int ret = 1;
-
- dos_format(newdir);
+
+ unix_format(newdir);
/* Save the current directory in case the new directory is invalid */
pstrcpy(saved_dir, cur_dir);
- if (*p == '\\')
+ if (*p == '/')
pstrcpy(cur_dir,p);
else
pstrcat(cur_dir,p);
- if (*(cur_dir+strlen(cur_dir)-1) != '\\') {
- pstrcat(cur_dir, "\\");
+ if (*(cur_dir+strlen(cur_dir)-1) != '/') {
+ pstrcat(cur_dir, "/");
}
- dos_clean_name(cur_dir);
+ /*dos_clean_name(cur_dir);
pstrcpy( dname, cur_dir );
pstrcat(cur_dir,"\\");
- dos_clean_name(cur_dir);
-
- if ( !cli_resolve_path( "", cli, dname, &targetcli, targetpath ) ) {
+ dos_clean_name(cur_dir);*/
+
+
+ /* TODO: cleanup debugging print statements*/
+ /*d_printf("service: %s\n", service);
+ d_printf("desthost: %s\n", desthost);
+ d_printf("username: %s\n", username);
+ d_printf("calling_name: %s\n", calling_name);
+ d_printf("cur_dir: %s\n", cur_dir);*/
+
+ /* Format the directory in a libmsmbclient friendly way */
+ unix_clean_name(cur_dir);
+ pstrcpy( dname, cur_dir );
+ pstrcpy(targetpath, "smb:");
+ pstrcat(targetpath, service);
+ pstrcat(targetpath, dname);
+ unix_format(targetpath);
+ /*d_printf("Saved: %s\n", cur_dir);
+ d_printf("Result: %s\n", targetpath);*/
+
+ /*if ( !cli_resolve_path( "", cli, dname, &targetcli, targetpath ) ) {
d_printf("cd %s: %s\n", dname, cli_errstr(cli));
pstrcpy(cur_dir,saved_dir);
goto out;
- }
+ }*/
+ dh = smbc_opendir(targetpath);
+ if (dh < 0)
+ {
+ d_printf("%s changing to directory %s\n", strerror(errno), cur_dir);
+ pstrcpy(cur_dir, saved_dir);
+ return 1;
+ }
+ smbc_closedir(dh);
if ( strequal(targetpath,"\\" ) )
@@ -292,7 +322,7 @@
/* use a trans2_qpathinfo to test directories for modern servers */
- if ( targetcli->protocol >= PROTOCOL_LANMAN2 ) {
+ /*if ( targetcli->protocol >= PROTOCOL_LANMAN2 ) {
if ( !cli_qpathinfo_basic( targetcli, targetpath, &sbuf, &attributes ) ) {
d_printf("cd %s: %s\n", dname, cli_errstr(targetcli));
pstrcpy(cur_dir,saved_dir);
@@ -313,13 +343,11 @@
pstrcpy(cur_dir,saved_dir);
goto out;
}
- }
+ }*/
ret = 0;
out:
-
- pstrcpy(cd_path,cur_dir);
return ret;
}
@@ -2427,7 +2455,6 @@
if (next_token_nr(NULL,buf,NULL,sizeof(buf)))
chdir(buf);
- d_printf("Local directory now %s\n", sys_getwd(d));
DEBUG(2,("the local directory is now %s\n",sys_getwd(d)));
return 0;
@@ -2714,6 +2741,8 @@
{"history",cmd_history,"displays the command history",{COMPL_NONE,COMPL_NONE}},
{"lcd",cmd_lcd,"[directory] change/report the local current working directory",{COMPL_LOCAL,COMPL_NONE}},
{"link",cmd_link,"<oldname> <newname> create a UNIX hard link",{COMPL_REMOTE,COMPL_REMOTE}},
+ {"listconnect",cmd_list_connect,"list open connections",{COMPL_NONE,COMPL_NONE}},
+ {"logon",cmd_logon,"establish new logon",{COMPL_NONE,COMPL_NONE}},
{"lowercase",cmd_lowercase,"toggle lowercasing of filenames for get",{COMPL_NONE,COMPL_NONE}},
{"ls",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
{"mask",cmd_select,"<mask> mask all filenames against this",{COMPL_REMOTE,COMPL_NONE}},
@@ -2739,6 +2768,7 @@
{"rm",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
{"rmdir",cmd_rmdir,"<directory> remove a directory",{COMPL_NONE,COMPL_NONE}},
{"setmode",cmd_setmode,"filename <setmode string> change modes of file",{COMPL_REMOTE,COMPL_NONE}},
+ {"showconnect",cmd_show_connect,"display the current active connection",{COMPL_NONE,COMPL_NONE}},
{"stat",cmd_stat,"filename Do a UNIX extensions stat call on a file",{COMPL_REMOTE,COMPL_REMOTE}},
{"symlink",cmd_symlink,"<oldname> <newname> create a UNIX symlink",{COMPL_REMOTE,COMPL_REMOTE}},
{"tar",cmd_tar,"tar <c|x>[IXFqbgNan] current directory to/from <file name>",{COMPL_NONE,COMPL_NONE}},
@@ -2746,9 +2776,6 @@
{"translate",cmd_translate,"toggle text translation for printing",{COMPL_NONE,COMPL_NONE}},
{"volume",cmd_volume,"print the volume name",{COMPL_NONE,COMPL_NONE}},
{"vuid",cmd_vuid,"change current vuid",{COMPL_NONE,COMPL_NONE}},
- {"logon",cmd_logon,"establish new logon",{COMPL_NONE,COMPL_NONE}},
- {"listconnect",cmd_list_connect,"list open connections",{COMPL_NONE,COMPL_NONE}},
- {"showconnect",cmd_show_connect,"display the current active connection",{COMPL_NONE,COMPL_NONE}},
/* Yes, this must be here, see crh's comment above. */
{"!",NULL,"run a shell command on the local system",{COMPL_NONE,COMPL_NONE}},
@@ -2766,7 +2793,7 @@
int cmd=0;
int tok_len = strlen(tok);
- while (commands[i].fn != NULL) {
+ while ((commands[i].fn != NULL) || (strequal(commands[i].name, "!"))) {
if (strequal(commands[i].name,tok)) {
matches = 1;
cmd = i;
@@ -3103,9 +3130,11 @@
int i;
/* display a prompt */
- slprintf(the_prompt, sizeof(the_prompt)-1, "smb: %s> ", cur_dir);
- cline = smb_readline(the_prompt, readline_callback, completion_fn);
-
+ slprintf(the_prompt, sizeof(the_prompt)-1, "smb: %s> ", cur_dir);
+ /* Removed callback since we don't need to swallow keepalives with libsmbclient */
+ /*cline = smb_readline(the_prompt, readline_callback, completion_fn);*/
+ cline = smb_readline(the_prompt, NULL, completion_fn);
+
if (!cline) break;
pstrcpy(line, cline);
@@ -3115,7 +3144,7 @@
system(line + 1);
continue;
}
-
+
/* and get the first part of the command */
ptr = line;
if (!next_token_nr(&ptr,tok,NULL,sizeof(tok))) continue;
@@ -3139,18 +3168,31 @@
{
int rc = 0;
- cli = cli_cm_open(desthost, service, True);
- if (!cli) {
+ /*cli = cli_cm_open(desthost, service, True);
+ if (!cli) {
return 1;
- }
-
- if (*base_directory) {
+ }*/
+ /* FIXME: get_auth_datafn should turn local echo off for passwords, cf. smbwrapper */
+ rc = smbc_init(get_auth_data_fn, 0); /* Initialize libsmbclient */
+ if (rc < 0)
+ {
+ d_printf("Error initializing libsmbclient: %s\n", strerror(errno));
+ return 1;
+ }
+
+ if (*base_directory) {
rc = do_cd(base_directory);
if (rc) {
- cli_cm_shutdown();
+ /*cli_cm_shutdown();*/
return rc;
}
}
+ else /* start the auth fn*/
+ {
+ rc = do_cd("/");
+ if (rc)
+ return rc;
+ }
if (cmdstr) {
rc = process_command_string(cmdstr);
More information about the samba-cvs
mailing list