root/source3/utils/smbw_sample.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. usage
  2. main

   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)
     /* [<][>][^][v][top][bottom][index][help] */
   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[])
     /* [<][>][^][v][top][bottom][index][help] */
  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         TALLOC_CTX *frame = talloc_stackframe();
  36 
  37         lp_load(get_dyn_CONFIGFILE(),1,0,0,1);
  38         smbw_setup_shared();
  39 
  40         while ((opt = getopt(argc, argv, "W:U:R:d:P:l:hL:")) != EOF) {
  41                 switch (opt) {
  42                 case 'W':
  43                         smbw_setshared("WORKGROUP", optarg);
  44                         break;
  45                 case 'l':
  46                         smbw_setshared("LOGFILE", optarg);
  47                         break;
  48                 case 'P':
  49                         smbw_setshared("PREFIX", optarg);
  50                         break;
  51                 case 'd':
  52                         smbw_setshared("DEBUG", optarg);
  53                         break;
  54                 case 'U':
  55                         p = strchr_m(optarg,'%');
  56                         if (p) {
  57                                 *p=0;
  58                                 smbw_setshared("PASSWORD",p+1);
  59                         }
  60                         smbw_setshared("USER", optarg);
  61                         break;
  62                 case 'R':
  63                         smbw_setshared("RESOLVE_ORDER",optarg);
  64                         break;
  65                 case 'h':
  66                 default:
  67                         usage();
  68                         exit(1);
  69                 }
  70         }
  71 
  72         argc -= optind;
  73         argv += optind;
  74 
  75         if (argc < 1) {
  76                 usage();
  77                 exit(1);
  78         }
  79 
  80         path = argv[0];
  81 
  82         smbw_init();
  83 
  84         dir = smbw_opendir(path);
  85         if (!dir) {
  86                 printf("failed to open %s\n", path);
  87                 exit(1);
  88         }
  89         
  90         while ((dent = smbw_readdir(dir))) {
  91                 printf("%s\n", dent->d_name);
  92         }
  93         smbw_closedir(dir);
  94         TALLOC_FREE(frame);
  95         return 0;
  96 }

/* [<][>][^][v][top][bottom][index][help] */