lib/config/showvconfig.cc
changeset 0 6f7a81934006
equal deleted inserted replaced
-1:000000000000 0:6f7a81934006
       
     1 #include <config.h>
       
     2 #include <limits.h>
       
     3 #include <unistd.h>
       
     4 #include "misc/pwentry.h"
       
     5 #include "vdomain/vdomain.h"
       
     6 #include "configrc.h"
       
     7 #include "fdbuf/fdbuf.h"
       
     8 
       
     9 template<class T>
       
    10 void show_val(const char* name, T value)
       
    11 {
       
    12   fout << name << ": " << value << "\n\n";
       
    13 }
       
    14 
       
    15 void show_uns(const char* name, unsigned value)
       
    16 {
       
    17   fout << name << ": ";
       
    18   if(value == UINT_MAX)
       
    19     fout << "-1\n\n";
       
    20   else
       
    21     fout << value << "\n\n";
       
    22 }
       
    23 
       
    24 void show_list(const char* name, const strlist& value)
       
    25 {
       
    26   if(!value)
       
    27     fout << name << " is empty.\n";
       
    28   else
       
    29     for(mystring_iter iter(value.str()); iter; ++iter)
       
    30       fout << name << ": " << *iter << "\n";
       
    31   fout << "\n";
       
    32 }
       
    33 
       
    34 #define show_dir show_val
       
    35 #define show_str show_val
       
    36 
       
    37 pwentry user;
       
    38 vdomain domain(user);
       
    39 
       
    40 bool go_home()
       
    41 {
       
    42   if(!user.home) {
       
    43     ferr << "showvconfig: Can't determine home directory" << endl;
       
    44     return false;
       
    45   }
       
    46   if(chdir(user.home.c_str()) == -1) {
       
    47     ferr << "showvconfig: Can't change to home directory" << endl;
       
    48     return false;
       
    49   }
       
    50   config = &domain.config;
       
    51   return true;
       
    52 }
       
    53 
       
    54 int main()
       
    55 {
       
    56   if(!go_home())
       
    57     return 1;
       
    58   show_dir("autoresponse-dir", config->autoresponse_dir());
       
    59   show_str("autoresponse-file", config->autoresponse_file());
       
    60   show_dir("bulletin-dir", config->bulletin_dir());
       
    61   show_uns("default-expiry", config->default_expiry());
       
    62   show_dir("default-maildir", config->default_maildir());
       
    63   show_uns("default-msgcount", config->default_msgcount());
       
    64   show_uns("default-msgsize", config->default_msgsize());
       
    65   show_uns("default-hardquota", config->default_hardquota());
       
    66   show_uns("default-softquota", config->default_softquota());
       
    67   show_str("default-username", config->default_username());
       
    68   show_dir("error-maildir", config->error_maildir());
       
    69   show_dir("global-bulletin-dir", config->global_bulletin_dir());
       
    70   show_str("maildir-arg-str", config->maildir_arg_str());
       
    71   show_str("password-file", config->password_file());
       
    72   show_list("postmaster-aliases", config->postmaster_aliases());
       
    73   show_str("postmaster-email", config->postmaster_email());
       
    74   show_dir("qmail-root", config->qmail_root());
       
    75   show_str("separators", config->separators());
       
    76   show_str("socket-file", config->socket_file());
       
    77   show_dir("user-dir", config->user_dir());
       
    78   show_uns("user-dir-bits", config->user_dir_bits());
       
    79   show_uns("user-dir-slices", config->user_dir_slices());
       
    80   return 0;
       
    81 }