use double instead of SMB_BIG_UINT for dir_total and ttarf
[samba.git] / source3 / client / client.c
index fb7e09f24110e58ceab07462bdfedd15c1fc2270..895cfb1456dd46db2f010947b351edb22efd2ac3 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;
@@ -100,7 +101,7 @@ int put_total_size = 0;
 int put_total_time_ms = 0;
 
 /* totals globals */
-int dir_total = 0;
+static double dir_total;
 
 #define USENMB
 
@@ -374,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;
@@ -422,14 +423,14 @@ static void cmd_dir(void)
                        pstrcat(mask,p);
        }
        else {
-               pstrcat(mask,"*.*");
+               pstrcat(mask,"*");
        }
 
        do_list(mask, attribute, display_finfo, recurse, True);
 
        do_dskattr();
 
-       DEBUG(3, ("Total bytes listed: %d\n", dir_total));
+       DEBUG(3, ("Total bytes listed: %.0f\n", dir_total));
 }
 
 
@@ -455,14 +456,14 @@ static void cmd_du(void)
                else
                        pstrcat(mask,p);
        } else {
-               pstrcat(mask,"*.*");
+               pstrcat(mask,"*");
        }
 
        do_list(mask, attribute, do_du, recurse, True);
 
        do_dskattr();
 
-       DEBUG(0, ("Total number of bytes: %d\n", dir_total));
+       DEBUG(0, ("Total number of bytes: %.0f\n", dir_total));
 }
 
 
@@ -496,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) {
@@ -505,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));
 
@@ -630,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);
@@ -644,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("..");
@@ -718,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);
        }
 }
@@ -816,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) {
@@ -980,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)) {
@@ -1319,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)));
 }
 
 /****************************************************************************
@@ -1617,7 +1620,7 @@ static void process_stdin(void)
 /***************************************************** 
 return a connection to a server
 *******************************************************/
-struct cli_state *do_connect(char *server, char *share)
+struct cli_state *do_connect(char *server, char *share, int smb_port)
 {
        struct cli_state *c;
        struct nmb_name called, calling;
@@ -1637,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 (smb_port == 0)
+         smb_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, smb_port) == 0) ||
+            !cli_connect(c, server_n, &ip)) {
                DEBUG(0,("Connection to %s failed\n", server_n));
                return NULL;
        }
@@ -1717,8 +1722,7 @@ struct cli_state *do_connect(char *server, char *share)
 ****************************************************************************/
 static BOOL process(char *base_directory)
 {
-       cli = do_connect(desthost, service);
-       
+       cli = do_connect(desthost, service, port);
        if (!cli) {
                return(False);
        }
@@ -1788,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",
@@ -1833,10 +1837,11 @@ static void get_password_file(void)
 /****************************************************************************
 handle a -L query
 ****************************************************************************/
-static int do_host_query(char *query_host, int port)
+static int do_host_query(char *query_host, int smb_port)
 {
-       cli = do_connect(query_host, "IPC$");
-       if (!cli) return 1;
+       cli = do_connect(query_host, "IPC$", smb_port);
+       if (!cli)
+               return 1;
 
        browse_host(True);
        list_servers(workgroup);
@@ -1850,10 +1855,12 @@ static int do_host_query(char *query_host, int port)
 /****************************************************************************
 handle a tar operation
 ****************************************************************************/
-static int do_tar_op(int port, char *base_directory)
+static int do_tar_op(int smb_port, char *base_directory)
 {
        int ret;
-       cli = do_connect(desthost, service);
+       cli = do_connect(desthost, service, smb_port);
+       if (!cli)
+               return 1;
 
        recurse=True;
 
@@ -1876,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, "");
 
@@ -1909,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;
@@ -2046,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':
@@ -2102,7 +2105,6 @@ static int do_message_op(void)
                        }
                        break;
                case 'L':
-                       got_pass = True;
                        pstrcpy(query_host,optarg);
                        if(!explicit_user)
                                *username = '\0';
@@ -2136,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);