15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
16 |
16 |
17 #include <config.h> |
17 #include <config.h> |
18 #include "config/configrc.h" |
18 #include "config/configrc.h" |
19 #include "vpwentry/vpwentry.h" |
19 #include "vpwentry/vpwentry.h" |
20 #include "cli/cli.h" |
20 #include "cli++/cli++.h" |
21 #include "fdbuf/fdbuf.h" |
21 #include "fdbuf/fdbuf.h" |
22 #include "vcommand.h" |
22 #include "vcommand.h" |
23 |
23 |
24 const char* cli_program = "listvdomain"; |
24 const char* cli_program = "listvdomain"; |
25 const char* cli_help_prefix = "Lists the members of a virtual domain\n"; |
25 const char* cli_help_prefix = "Lists the members of a virtual domain\n"; |
32 static int o_quiet = false; |
32 static int o_quiet = false; |
33 |
33 |
34 // This program lists all the users in a domain. |
34 // This program lists all the users in a domain. |
35 // The listing consists of one user per line, |
35 // The listing consists of one user per line, |
36 // and each line has three columns: |
36 // and each line has three columns: |
37 // the virtual user name, the mailbox directory (or C<-> if none is set), |
37 // the virtual user name, C<Yes> or C<No> depending if the user has a mailbox, |
38 // and an optional list of forwarding addresses, all seperated by a space. |
38 // and an optional list of forwarding addresses, all seperated by a space. |
39 |
39 |
40 cli_option cli_options[] = { |
40 cli_option cli_options[] = { |
41 { 'a', "aliases", cli_option::flag, true, &o_nousers, |
41 { 'a', "aliases", cli_option::flag, true, &o_nousers, |
42 "Show only accounts without a mailbox", 0 }, |
42 "Show only accounts without a mailbox", 0 }, |
47 {0} |
47 {0} |
48 }; |
48 }; |
49 |
49 |
50 void show_user(const vpwentry& vpw) |
50 void show_user(const vpwentry& vpw) |
51 { |
51 { |
52 if(o_noaliases && !vpw.mailbox) |
52 if(o_noaliases && !vpw.has_mailbox) |
53 return; |
53 return; |
54 if(o_nousers && !!vpw.mailbox) |
54 if(o_nousers && vpw.has_mailbox) |
55 return; |
55 return; |
56 fout << vpw.name; |
56 fout << vpw.name << (vpw.has_mailbox ? " Yes" : " No"); |
57 if(!vpw.mailbox) |
57 if(!vpw.is_mailbox_enabled) |
58 fout << " -"; |
58 fout << "(disabled)"; |
59 else { |
|
60 fout << ' ' << vpw.mailbox; |
|
61 if(!vpw.is_mailbox_enabled) |
|
62 fout << "(disabled)"; |
|
63 } |
|
64 for(mystring_iter iter(vpw.forwards, '\0'); iter; ++iter) |
59 for(mystring_iter iter(vpw.forwards, '\0'); iter; ++iter) |
65 fout << ' ' << *iter; |
60 fout << ' ' << *iter; |
66 fout << '\n'; |
61 fout << '\n'; |
67 } |
62 } |
68 |
63 |
82 vpwtable* table = domain.table(); |
77 vpwtable* table = domain.table(); |
83 |
78 |
84 fout << "User Mailbox Aliases\n"; |
79 fout << "User Mailbox Aliases\n"; |
85 |
80 |
86 if(argc) { |
81 if(argc) { |
87 vpwentry* vpw; |
|
88 for(int i = 0; i < argc; i++) { |
82 for(int i = 0; i < argc; i++) { |
89 vpw = table->getbyname(argv[i]); |
83 vpwentry* vpw = table->getbyname(argv[i]); |
90 if(!vpw) { |
84 if(!vpw) { |
91 if(!o_quiet) |
85 if(!o_quiet) |
92 ferr << "listvdomain: unknown user '" << argv[i] << "'" << endl; |
86 ferr << "listvdomain: unknown user '" << argv[i] << "'" << endl; |
93 errors = 1; |
87 errors = 1; |
94 } |
88 } |