r9557: Some more updates. Use combined function for parsing a set of
[samba.git] / source / lib / samba3 / samba3dump.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Samba3 database dump utility
4
5     Copyright (C) Jelmer Vernooij       2005
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "lib/samba3/samba3.h"
24 #include "lib/cmdline/popt_common.h"
25
26 static NTSTATUS print_policy(struct samba3_policy *ret)
27 {
28         printf("Min password length: %d\n", ret->min_password_length);
29
30         return NT_STATUS_OK;
31 }
32
33 static NTSTATUS print_sam(struct samba3 *samba3)
34 {
35         struct samba3_samaccount *accounts = samba3->samaccounts;
36         uint32_t count = samba3->samaccount_count, i;
37         
38         for (i = 0; i < count; i++) {
39                 printf("%d: %s\n", accounts[i].user_rid, accounts[i].username);
40         }
41
42         return NT_STATUS_OK;
43 }
44  
45 int main(int argc, char **argv)
46 {
47         int opt;
48         const char *libdir = "/var/lib/samba";
49         struct samba3 *samba3;
50         poptContext pc;
51         struct poptOption long_options[] = {
52                 POPT_AUTOHELP
53                 { "libdir", 0, POPT_ARG_STRING, &libdir, 'l', "Set libdir [/var/lib/samba]", "LIBDIR" },
54                 POPT_COMMON_SAMBA
55                 POPT_TABLEEND
56         };
57
58         pc = poptGetContext(argv[0], argc, (const char **) argv, long_options,0);
59
60         poptSetOtherOptionHelp(pc, "<smb.conf>");
61
62         while((opt = poptGetNextOpt(pc)) != -1) {
63         }
64
65         samba3 = samba3_read(libdir, NULL);
66
67         print_sam(samba3);
68         print_policy(&samba3->policy);
69
70         poptFreeContext(pc);
71
72         return 0;
73 }