|
1 // Copyright (C) 1999,2000 Bruce Guenter <bruceg@em.ca> |
|
2 // |
|
3 // This program is free software; you can redistribute it and/or modify |
|
4 // it under the terms of the GNU General Public License as published by |
|
5 // the Free Software Foundation; either version 2 of the License, or |
|
6 // (at your option) any later version. |
|
7 // |
|
8 // This program is distributed in the hope that it will be useful, |
|
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 // GNU General Public License for more details. |
|
12 // |
|
13 // You should have received a copy of the GNU General Public License |
|
14 // along with this program; if not, write to the Free Software |
|
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 #include <config.h> |
|
18 #include <limits.h> |
|
19 #include "config/configrc.h" |
|
20 #include "vpwentry/vpwentry.h" |
|
21 #include "cli++/cli++.h" |
|
22 #include "fdbuf/fdbuf.h" |
|
23 #include "vcommand.h" |
|
24 |
|
25 const char* cli_program = "dumpvuser"; |
|
26 const char* cli_help_prefix = "Dump all of a vmailmgr account's data\n"; |
|
27 const char* cli_help_suffix = ""; |
|
28 const char* cli_args_usage = "account"; |
|
29 const int cli_args_min = 1; |
|
30 const int cli_args_max = 1; |
|
31 static int o_quiet = false; |
|
32 |
|
33 // This program dumps all the contents of a vmailmgr account |
|
34 // in a format similar to a mail header. |
|
35 |
|
36 cli_option cli_options[] = { |
|
37 { 0, "quiet", cli_option::flag, true, &o_quiet, |
|
38 "Suppress all status messages", 0 }, |
|
39 {0} |
|
40 }; |
|
41 |
|
42 void show_num(const char* label, unsigned value) |
|
43 { |
|
44 fout << label << ": "; |
|
45 if (value == UINT_MAX) |
|
46 fout << "N/A"; |
|
47 else |
|
48 fout << value; |
|
49 fout << '\n'; |
|
50 } |
|
51 |
|
52 void show_flag(const char* label, bool value) |
|
53 { |
|
54 fout << label << ": " << (value ? "true" : "false") << '\n'; |
|
55 } |
|
56 |
|
57 void show_user(const vpwentry* vpw) |
|
58 { |
|
59 fout << |
|
60 "Name: " << vpw->name << "\n" |
|
61 "Encrypted-Password: " << vpw->pass << "\n" |
|
62 "Directory: " << vpw->directory << "\n"; |
|
63 for(mystring_iter iter(vpw->forwards, '\0'); iter; ++iter) |
|
64 fout << "Forward: " << *iter << '\n'; |
|
65 show_num("Hard-Quota", vpw->hardquota); |
|
66 show_num("Soft-Quota", vpw->softquota); |
|
67 show_num("Message-Size-Limit", vpw->msgsize); |
|
68 show_num("Message-Count-Limit", vpw->msgcount); |
|
69 show_num("Creation-Time", vpw->ctime); |
|
70 show_num("Expiry-Time", vpw->expiry); |
|
71 show_flag("Has-Mailbox", vpw->has_mailbox); |
|
72 show_flag("Mailbox-Enabled", vpw->is_mailbox_enabled); |
|
73 } |
|
74 |
|
75 int cli_main(int, char* argv[]) |
|
76 { |
|
77 if(!go_home()) |
|
78 return 1; |
|
79 |
|
80 vpwentry* vpw = domain.lookup(argv[0]); |
|
81 if (vpw == 0) { |
|
82 if (!o_quiet) |
|
83 ferr << "dumpvuser: No such user" << endl; |
|
84 return 1; |
|
85 } |
|
86 |
|
87 show_user(vpw); |
|
88 return 0; |
|
89 } |