Putting back the -p flag in smbclient.
[samba.git] / source / client / client.c
index 13f5adec05c2395cf3865d01e06937fee63e173e..afee7dbbd390c273316372c0bb523249c5880fce 100644 (file)
@@ -29,6 +29,7 @@
 
 struct cli_state *cli;
 extern BOOL in_client;
+static int port = SMB_PORT;
 pstring cur_dir = "\\";
 pstring cd_path = "";
 static pstring service;
@@ -40,7 +41,6 @@ static pstring username;
 static pstring workgroup;
 static char *cmdstr;
 static BOOL got_pass;
-static BOOL no_pass;
 extern struct in_addr ipzero;
 extern pstring scope;
 
@@ -189,7 +189,7 @@ static void send_message(void)
                int l=0;
                int c;
 
-               ZERO_STRUCT(msg);
+               ZERO_ARRAY(msg);
 
                for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) {
                        if (c == '\n')
@@ -375,7 +375,7 @@ static void do_list_helper(file_info *f, const char *mask)
                        if (do_list_fn == display_finfo) {
                                DEBUG(0,("\n%s\n",CNV_LANG(mask2)));
                        }
-                       pstrcat(mask2,"\\*.*");
+                       pstrcat(mask2,"\\*");
                        do_list(mask2, do_list_attr, do_list_fn, True, True);
                }
                return;
@@ -390,7 +390,7 @@ static void do_list_helper(file_info *f, const char *mask)
 /****************************************************************************
 a wrapper around cli_list that adds recursion
   ****************************************************************************/
-void do_list(const char *mask,int attribute,void (*fn)(file_info *),BOOL rec, BOOL dirs)
+void do_list(const char *mask,uint16 attribute,void (*fn)(file_info *),BOOL rec, BOOL dirs)
 {
        do_list_recurse = rec;
        do_list_dirs = dirs;
@@ -405,7 +405,7 @@ void do_list(const char *mask,int attribute,void (*fn)(file_info *),BOOL rec, BO
   ****************************************************************************/
 static void cmd_dir(void)
 {
-       int attribute = aDIR | aSYSTEM | aHIDDEN;
+       uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
        pstring mask;
        fstring buf;
        char *p=buf;
@@ -423,7 +423,7 @@ static void cmd_dir(void)
                        pstrcat(mask,p);
        }
        else {
-               pstrcat(mask,"*.*");
+               pstrcat(mask,"*");
        }
 
        do_list(mask, attribute, display_finfo, recurse, True);
@@ -439,7 +439,7 @@ static void cmd_dir(void)
   ****************************************************************************/
 static void cmd_du(void)
 {
-       int attribute = aDIR | aSYSTEM | aHIDDEN;
+       uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
        pstring mask;
        fstring buf;
        char *p=buf;
@@ -456,7 +456,7 @@ static void cmd_du(void)
                else
                        pstrcat(mask,p);
        } else {
-               pstrcat(mask,"*.*");
+               pstrcat(mask,"*");
        }
 
        do_list(mask, attribute, do_du, recurse, True);
@@ -477,7 +477,7 @@ static void do_get(char *rname,char *lname)
        char *data;
        struct timeval tp_start;
        int read_size = 65520;
-       uint32 attr;
+       uint16 attr;
        size_t size;
        off_t nread = 0;
 
@@ -497,7 +497,7 @@ static void do_get(char *rname,char *lname)
        if(!strcmp(lname,"-")) {
                handle = fileno(stdout);
        } else {
-               handle = open(lname,O_WRONLY|O_CREAT|O_TRUNC,0644);
+               handle = sys_open(lname,O_WRONLY|O_CREAT|O_TRUNC,0644);
                newhandle = True;
        }
        if (handle < 0) {
@@ -506,12 +506,14 @@ static void do_get(char *rname,char *lname)
        }
 
 
-       if (!cli_getattrE(cli, fnum, &attr, &size, NULL, NULL, NULL)) {
-               DEBUG(0,("getattrE: %s\n",cli_errstr(cli)));
+       if (!cli_qfileinfo(cli, fnum, 
+                          &attr, &size, NULL, NULL, NULL, NULL, NULL) &&
+           !cli_getattrE(cli, fnum, 
+                         &attr, &size, NULL, NULL, NULL)) {
+               DEBUG(0,("getattrib: %s\n",cli_errstr(cli)));
                return;
        }
 
-
        DEBUG(2,("getting file %s of size %.0f as %s ", 
                 lname, (double)size, lname));
 
@@ -539,7 +541,7 @@ static void do_get(char *rname,char *lname)
        }
 
        if (archive_level >= 2 && (attr & aARCH)) {
-               cli_setatr(cli, rname, attr & ~aARCH, 0);
+               cli_setatr(cli, rname, attr & ~(uint16)aARCH, 0);
        }
 
        {
@@ -631,7 +633,7 @@ static void do_mget(file_info *finfo)
        if (lowercase)
                strlower(finfo->name);
        
-       if (!directory_exist(finfo->name,NULL) && 
+       if (!dos_directory_exist(finfo->name,NULL) && 
            dos_mkdir(finfo->name,0777) != 0) {
                DEBUG(0,("failed to create directory %s\n",CNV_LANG(finfo->name)));
                pstrcpy(cur_dir,saved_curdir);
@@ -645,7 +647,7 @@ static void do_mget(file_info *finfo)
        }
 
        pstrcpy(mget_mask,cur_dir);
-       pstrcat(mget_mask,"*.*");
+       pstrcat(mget_mask,"*");
        
        do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,False, True);
        chdir("..");
@@ -691,7 +693,7 @@ do a mget command
 ****************************************************************************/
 static void cmd_mget(void)
 {
-       int attribute = aSYSTEM | aHIDDEN;
+       uint16 attribute = aSYSTEM | aHIDDEN;
        pstring mget_mask;
        fstring buf;
        char *p=buf;
@@ -719,7 +721,7 @@ static void cmd_mget(void)
                pstrcpy(mget_mask,cur_dir);
                if(mget_mask[strlen(mget_mask)-1]!='\\')
                        pstrcat(mget_mask,"\\");
-               pstrcat(mget_mask,"*.*");
+               pstrcat(mget_mask,"*");
                do_list(mget_mask, attribute,do_mget,False,True);
        }
 }
@@ -817,7 +819,7 @@ static void do_put(char *rname,char *lname)
                f = stdin;
                /* size of file is not known */
        } else {
-               f = fopen(lname,"r");
+               f = sys_fopen(lname,"r");
        }
 
        if (!f) {
@@ -893,8 +895,6 @@ static void cmd_put(void)
        pstring rname;
        fstring buf;
        char *p=buf;
-       file_info finfo;
-       finfo = def_finfo;
        
        pstrcpy(rname,cur_dir);
        pstrcat(rname,"\\");
@@ -921,7 +921,6 @@ static void cmd_put(void)
                        DEBUG(0,("%s does not exist\n",lname));
                        return;
                }
-               finfo.mtime = st.st_mtime;
        }
 
        do_put(rname,lname);
@@ -965,12 +964,9 @@ static void cmd_mput(void)
 {
        pstring lname;
        pstring rname;
-       file_info finfo;
        fstring buf;
        char *p=buf;
        
-       finfo = def_finfo;
-
        while (next_token(NULL,p,NULL,sizeof(buf))) {
                SMB_STRUCT_STAT st;
                pstring cmd;
@@ -987,7 +983,7 @@ static void cmd_mput(void)
                                 "/bin/ls %s > %s",p,tmpname);
                system(cmd);
 
-               f = fopen(tmpname,"r");
+               f = sys_fopen(tmpname,"r");
                if (!f) continue;
                
                while (!feof(f)) {
@@ -1030,12 +1026,6 @@ static void cmd_mput(void)
 
                        dos_format(rname);
 
-                       /* null size so do_put knows to ignore it */
-                       finfo.size = -1;
-
-                       /* set the date on the file */
-                       finfo.mtime = st.st_mtime;
-                       
                        do_put(rname,lname);
                }
                fclose(f);
@@ -1145,7 +1135,7 @@ static void cmd_del(void)
 {
        pstring mask;
        fstring buf;
-       int attribute = aSYSTEM | aHIDDEN;
+       uint16 attribute = aSYSTEM | aHIDDEN;
 
        if (recurse)
                attribute |= aDIR;
@@ -1332,8 +1322,8 @@ static void cmd_lcd(void)
        pstring d;
        
        if (next_token(NULL,buf,NULL,sizeof(buf)))
-               dos_chdir(buf);
-       DEBUG(2,("the local directory is now %s\n",GetWd(d)));
+               chdir(buf);
+       DEBUG(2,("the local directory is now %s\n",sys_getwd(d)));
 }
 
 /****************************************************************************
@@ -1650,17 +1640,19 @@ struct cli_state *do_connect(char *server, char *share)
        
        ip = ipzero;
 
-       strupper(server);
-
        make_nmb_name(&calling, global_myname, 0x0, "");
        make_nmb_name(&called , server, name_type, "");
 
+       if (port == 0)
+         port = 139;   /* If not set, set to 139, FIXME, NUMBERS BAD */
+
  again:
        ip = ipzero;
        if (have_ip) ip = dest_ip;
 
        /* have to open a new connection */
-       if (!(c=cli_initialise(NULL)) || !cli_connect(c, server_n, &ip)) {
+       if (!(c=cli_initialise(NULL)) || (cli_set_port(c, port) == 0) ||
+            !cli_connect(c, server_n, &ip)) {
                DEBUG(0,("Connection to %s failed\n", server_n));
                return NULL;
        }
@@ -1698,6 +1690,18 @@ struct cli_state *do_connect(char *server, char *share)
                return NULL;
        }
 
+       /*
+        * 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)
+               DEBUG(1,("Domain=[%s] OS=[%s] Server=[%s]\n",
+                       c->server_domain,c->server_os,c->server_type));
+       
        DEBUG(4,(" session setup ok\n"));
 
        if (!cli_send_tconX(c, share, "?????",
@@ -1719,11 +1723,10 @@ struct cli_state *do_connect(char *server, char *share)
 static BOOL process(char *base_directory)
 {
        cli = do_connect(desthost, service);
-       
        if (!cli) {
                return(False);
        }
-       
+
        if (*base_directory) do_cd(base_directory);
        
        if (cmdstr) {
@@ -1789,7 +1792,7 @@ static void get_password_file(void)
                sscanf(p, "%d", &fd);
                close_it = False;
        } else if ((p = getenv("PASSWD_FILE")) != NULL) {
-               fd = open(p, O_RDONLY);
+               fd = sys_open(p, O_RDONLY, 0);
                pstrcpy(spec, p);
                if (fd < 0) {
                        fprintf(stderr, "Error opening PASSWD_FILE %s: %s\n",
@@ -1837,7 +1840,8 @@ handle a -L query
 static int do_host_query(char *query_host, int port)
 {
        cli = do_connect(query_host, "IPC$");
-       if (!cli) return 1;
+       if (!cli)
+               return 1;
 
        browse_host(True);
        list_servers(workgroup);
@@ -1855,6 +1859,8 @@ static int do_tar_op(int port, char *base_directory)
 {
        int ret;
        cli = do_connect(desthost, service);
+       if (!cli)
+               return 1;
 
        recurse=True;
 
@@ -1877,8 +1883,6 @@ static int do_message_op(void)
 
        ip = ipzero;
 
-       strupper(desthost);
-
        make_nmb_name(&calling, global_myname, 0x0, "");
        make_nmb_name(&called , desthost, name_type, "");
 
@@ -1910,7 +1914,6 @@ static int do_message_op(void)
 {
        fstring base_directory;
        char *pname = argv[0];
-       int port = SMB_PORT;
        int opt;
        extern FILE *dbf;
        extern char *optarg;
@@ -2047,7 +2050,6 @@ static int do_message_op(void)
                case 'M':
                        name_type = 0x03; /* messages are sent to NetBIOS name type 0x3 */
                        pstrcpy(desthost,optarg);
-                       strupper(desthost);
                        message = True;
                        break;
                case 'i':
@@ -2055,7 +2057,6 @@ static int do_message_op(void)
                        break;
                case 'N':
                        got_pass = True;
-                       no_pass = True;
                        break;
                case 'n':
                        pstrcpy(global_myname,optarg);
@@ -2104,7 +2105,6 @@ static int do_message_op(void)
                        }
                        break;
                case 'L':
-                       got_pass = True;
                        pstrcpy(query_host,optarg);
                        if(!explicit_user)
                                *username = '\0';
@@ -2138,7 +2138,6 @@ static int do_message_op(void)
        }
 
        get_myname((*global_myname)?NULL:global_myname,NULL);  
-       strupper(global_myname);
 
        if(*new_name_resolve_order)
                lp_set_name_resolve_order(new_name_resolve_order);