Fix two problems identified by the test suite, one a major one
[Samba/gebeck_regimport.git] / source3 / utils / smbw_sample.c
blobdb92af9510877aa79c032147bffba6ef923c27af
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <stdlib.h>
4 #include <dirent.h>
5 #include <sys/stat.h>
7 static void usage(void)
9 printf("
10 smbw_sample - a sample program that uses smbw
12 smbw_sample <options> path
14 options:
15 -W workgroup
16 -l logfile
17 -P prefix
18 -d debuglevel
19 -U username%%password
20 -R resolve order
22 note that path must start with /smb/
23 ");
26 int main(int argc, char *argv[])
28 DIR *dir;
29 struct dirent *dent;
30 int opt;
31 char *p;
32 extern char *optarg;
33 extern int optind;
34 char *path;
36 charset_initialise();
37 lp_load(CONFIGFILE,1,0,0);
38 codepage_initialise(lp_client_code_page());
39 smbw_setup_shared();
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);
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);
73 argc -= optind;
74 argv += optind;
76 if (argc < 1) {
77 usage();
78 exit(1);
81 path = argv[0];
83 smbw_init();
85 dir = smbw_opendir(path);
86 if (!dir) {
87 printf("failed to open %s\n", path);
88 exit(1);
91 while ((dent = smbw_readdir(dir))) {
92 printf("%s\n", dent->d_name);
94 smbw_closedir(dir);
95 return 0;