added cli_list_old() to allow for old style directory listing from
authorAndrew Tridgell <tridge@samba.org>
Sun, 30 Apr 2000 12:34:26 +0000 (12:34 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 30 Apr 2000 12:34:26 +0000 (12:34 +0000)
masktest
(This used to be commit 8a5c8cfa0ede1d119bf9013e321a497beefd4dda)

source3/include/proto.h
source3/libsmb/clilist.c
source3/utils/masktest.c

index 27d97ee4c76b361ff20c8fa83ec84a300fd2153d..6e22fd171f1d554badca300fc7240d98b5a42425 100644 (file)
@@ -87,10 +87,6 @@ char *dos_GetWd(char *path);
 
 void fault_setup(void (*fn)(void *));
 
-/*The following definitions come from  lib/fnmatch.c  */
-
-int fnmatch (const char *pattern, const char *string, int flags);
-
 /*The following definitions come from  lib/fsusage.c  */
 
 int sys_fsusage(const char *path, SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
@@ -636,6 +632,8 @@ BOOL cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail);
 
 int cli_list(struct cli_state *cli,const char *Mask,uint16 attribute, 
             void (*fn)(file_info *, const char *));
+int cli_list_old(struct cli_state *cli,const char *Mask,uint16 attribute, 
+                void (*fn)(file_info *, const char *));
 
 /*The following definitions come from  libsmb/climessage.c  */
 
index f2e42be5234c8bda7b3e9456330a75f0bb941f5a..74b908ae583b4f52b24968fb9867a44dfc37f591 100644 (file)
@@ -160,8 +160,7 @@ int cli_list(struct cli_state *cli,const char *Mask,uint16 attribute,
        int ff_dir_handle=0;
        int loop_count = 0;
        char *rparam=NULL, *rdata=NULL;
-       int param_len, data_len;
-       
+       int param_len, data_len;        
        uint16 setup;
        pstring param;
        
@@ -302,3 +301,146 @@ int cli_list(struct cli_state *cli,const char *Mask,uint16 attribute,
        return(total_received);
 }
 
+
+
+/****************************************************************************
+interpret a short filename structure
+The length of the structure is returned
+****************************************************************************/
+static int interpret_short_filename(char *p,file_info *finfo)
+{
+       extern file_info def_finfo;
+
+       *finfo = def_finfo;
+
+       finfo->mode = CVAL(p,21);
+       
+       /* this date is converted to GMT by make_unix_date */
+       finfo->ctime = make_unix_date(p+22);
+       finfo->mtime = finfo->atime = finfo->ctime;
+       finfo->size = IVAL(p,26);
+       pstrcpy(finfo->name,p+30);
+       if (strcmp(finfo->name, "..") && strcmp(finfo->name, "."))
+               fstrcpy(finfo->short_name,finfo->name);
+       
+       return(DIR_STRUCT_SIZE);
+}
+
+
+/****************************************************************************
+  do a directory listing, calling fn on each file found
+  this uses the old SMBsearch interface. It is needed for testing Samba,
+  but should otherwise not be used
+  ****************************************************************************/
+int cli_list_old(struct cli_state *cli,const char *Mask,uint16 attribute, 
+                void (*fn)(file_info *, const char *))
+{
+       char *p;
+       int received = 0;
+       BOOL first = True;
+       char status[21];
+       int num_asked = (cli->max_xmit - 100)/DIR_STRUCT_SIZE;
+       int num_received = 0;
+       int i;
+       char *dirlist = NULL;
+       pstring mask;
+       
+       ZERO_ARRAY(status);
+
+       pstrcpy(mask,Mask);
+  
+       while (1) {
+               memset(cli->outbuf,'\0',smb_size);
+               memset(cli->inbuf,'\0',smb_size);
+
+               if (first)      
+                       set_message(cli->outbuf,2,5 + strlen(mask),True);
+               else
+                       set_message(cli->outbuf,2,5 + 21,True);
+
+               CVAL(cli->outbuf,smb_com) = SMBffirst;
+
+               SSVAL(cli->outbuf,smb_tid,cli->cnum);
+               cli_setup_packet(cli);
+
+               SSVAL(cli->outbuf,smb_vwv0,num_asked);
+               SSVAL(cli->outbuf,smb_vwv1,attribute);
+  
+               p = smb_buf(cli->outbuf);
+               *p++ = 4;
+      
+               if (first)
+                       pstrcpy(p,mask);
+               else
+                       pstrcpy(p,"");
+               p += strlen(p) + 1;
+      
+               *p++ = 5;
+               if (first) {
+                       SSVAL(p,0,0);
+               } else {
+                       SSVAL(p,0,21);
+                       p += 2;
+                       memcpy(p,status,21);
+               }
+
+               cli_send_smb(cli);
+               if (!cli_receive_smb(cli)) break;
+
+               received = SVAL(cli->inbuf,smb_vwv0);
+               if (received <= 0) break;
+
+               first = False;
+
+               dirlist = Realloc(dirlist,(num_received + received)*DIR_STRUCT_SIZE);
+
+               if (!dirlist) 
+                       return 0;
+
+               p = smb_buf(cli->inbuf) + 3;
+
+               memcpy(dirlist+num_received*DIR_STRUCT_SIZE,
+                      p,received*DIR_STRUCT_SIZE);
+               
+               memcpy(status,p + ((received-1)*DIR_STRUCT_SIZE),21);
+               
+               num_received += received;
+               
+               if (CVAL(cli->inbuf,smb_rcls) != 0) break;
+       }
+
+       if (!first) {
+               memset(cli->outbuf,'\0',smb_size);
+               memset(cli->inbuf,'\0',smb_size);
+
+               set_message(cli->outbuf,0,6,True);
+               CVAL(cli->outbuf,smb_com) = SMBfclose;
+               SSVAL(cli->outbuf,smb_tid,cli->cnum);
+               cli_setup_packet(cli);
+
+               p = smb_buf(cli->outbuf);
+               *p++ = 4;
+      
+               pstrcpy(p,"");
+               p += strlen(p) + 1;
+               
+               *p++ = 5;
+               SSVAL(p,0,21);
+               p += 2;
+               memcpy(p,status,21);
+               
+               cli_send_smb(cli);
+               if (!cli_receive_smb(cli)) {
+                       DEBUG(0,("Error closing search: %s\n",smb_errstr(cli->inbuf)));      
+               }
+       }
+
+       for (p=dirlist,i=0;i<num_received;i++) {
+               file_info finfo;
+               p += interpret_short_filename(p,&finfo);
+               fn(&finfo, Mask);
+       }
+
+       if (dirlist) free(dirlist);
+       return(num_received);
+}
index 137866b41c0d9beade148c3ba34a5dc43e1285c9..45c113f1120e946ed311aacc15f8be3a217b6762 100644 (file)
@@ -30,7 +30,7 @@ static fstring workgroup;
 static int got_pass;
 
 static BOOL showall = False;
-
+static BOOL old_list = False;
 static char *maskchars = "<>\"?*abc.";
 static char *filechars = "abcdefghijklm.";
 
@@ -190,7 +190,11 @@ static void testpair(struct cli_state *cli, char *mask, char *file)
        resultp = res1;
        fstrcpy(short_name, "");
        finfo = NULL;
-       cli_list(cli, mask, aHIDDEN | aDIR, listfn);
+       if (old_list) {
+               cli_list_old(cli, mask, aHIDDEN | aDIR, listfn);
+       } else {
+               cli_list(cli, mask, aHIDDEN | aDIR, listfn);
+       }
        if (finfo) {
                fstrcpy(short_name, finfo->short_name);
                strlower(short_name);
@@ -310,8 +314,8 @@ static void usage(void)
 
        setup_logging(argv[0],True);
 
-       argc -= 2;
-       argv += 2;
+       argc -= 1;
+       argv += 1;
 
        TimeInit();
        charset_initialise();
@@ -325,7 +329,7 @@ static void usage(void)
 
        seed = time(NULL);
 
-       while ((opt = getopt(argc, argv, "U:s:hm:f:a")) != EOF) {
+       while ((opt = getopt(argc, argv, "U:s:hm:f:ao")) != EOF) {
                switch (opt) {
                case 'U':
                        pstrcpy(username,optarg);
@@ -351,6 +355,9 @@ static void usage(void)
                case 'a':
                        showall = 1;
                        break;
+               case 'o':
+                       old_list = True;
+                       break;
                default:
                        printf("Unknown option %c (%d)\n", (char)opt, opt);
                        exit(1);