db92af9510877aa79c032147bffba6ef923c27af
[samba.git] / source / utils / smbw_sample.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <stdlib.h>
4 #include <dirent.h>
5 #include <sys/stat.h>
6
7 static void usage(void)
8 {
9         printf("
10 smbw_sample - a sample program that uses smbw
11
12 smbw_sample <options> path
13
14   options:
15      -W workgroup
16      -l logfile
17      -P prefix
18      -d debuglevel
19      -U username%%password
20      -R resolve order
21
22 note that path must start with /smb/
23 ");
24 }
25
26 int main(int argc, char *argv[])
27 {
28         DIR *dir;
29         struct dirent *dent;
30         int opt;
31         char *p;
32         extern char *optarg;
33         extern int optind;
34         char *path;
35
36         charset_initialise();
37         lp_load(CONFIGFILE,1,0,0);
38         codepage_initialise(lp_client_code_page());
39         smbw_setup_shared();
40
41         while ((opt = getopt(argc, argv, "W:U:R:d:P:l:hL:")) != EOF) {
42                 switch (opt) {
43                 case 'W':
44                         smbw_setshared("WORKGROUP", optarg);
45                         break;
46                 case 'l':
47                         smbw_setshared("LOGFILE", optarg);
48                         break;
49                 case 'P':
50                         smbw_setshared("PREFIX", optarg);
51                         break;
52                 case 'd':
53                         smbw_setshared("DEBUG", optarg);
54                         break;
55                 case 'U':
56                         p = strchr(optarg,'%');
57                         if (p) {
58                                 *p=0;
59                                 smbw_setshared("PASSWORD",p+1);
60                         }
61                         smbw_setshared("USER", optarg);
62                         break;
63                 case 'R':
64                         smbw_setshared("RESOLVE_ORDER",optarg);
65                         break;
66                 case 'h':
67                 default:
68                         usage();
69                         exit(1);
70                 }
71         }
72
73         argc -= optind;
74         argv += optind;
75
76         if (argc < 1) {
77                 usage();
78                 exit(1);
79         }
80
81         path = argv[0];
82
83         smbw_init();
84
85         dir = smbw_opendir(path);
86         if (!dir) {
87                 printf("failed to open %s\n", path);
88                 exit(1);
89         }
90         
91         while ((dent = smbw_readdir(dir))) {
92                 printf("%s\n", dent->d_name);
93         }
94         smbw_closedir(dir);
95         return 0;
96 }