nis-util  1.0.D108
nis-util-netid/main.cc
Go to the documentation of this file.
00001 //
00002 // nis-util - NIS Administration Utilities
00003 // Copyright (C) 2002, 2008, 2009, 2011, 2012 Peter Miller
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or (at
00008 // your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 //
00018 
00019 #include <lib/config.h>
00020 #include <libexplain/output.h>
00021 
00022 #include <nis-util-netid/arglex/netid.h>
00023 #include <nis-util-netid/check.h>
00024 #include <nis-util-netid/map.h>
00025 
00026 
00027 int
00028 main(int argc, char **argv)
00029 {
00030     arglex_netid cmdline(argc, argv);
00031     cmdline.token_first();
00032     rcstring etc_passwd;
00033     rcstring etc_group;
00034     rcstring etc_hosts;
00035     rcstring etc_netid;
00036     rcstring domain;
00037     bool map_flag = false;
00038     bool check_flag = false;
00039     rcstring output;
00040     while (cmdline.token_cur() != arglex::token_eoln)
00041     {
00042         switch (cmdline.token_cur())
00043         {
00044         default:
00045             cmdline.generic_argument();
00046             break;
00047 
00048         case arglex_netid::token_hosts:
00049             if (!etc_hosts.empty())
00050             {
00051                 explain_output_error("too many hosts files specified");
00052                 cmdline.usage();
00053             }
00054             etc_hosts = cmdline.get_filename_or_stdin();
00055             break;
00056 
00057         case arglex_netid::token_passwd:
00058             if (!etc_passwd.empty())
00059             {
00060                 explain_output_error("too many passwd files specified");
00061                 cmdline.usage();
00062             }
00063             etc_passwd = cmdline.get_filename_or_stdin();
00064             break;
00065 
00066         case arglex_netid::token_group:
00067             if (!etc_group.empty())
00068             {
00069                 explain_output_error("too many group files specified");
00070                 cmdline.usage();
00071             }
00072             etc_group = cmdline.get_filename_or_stdin();
00073             break;
00074 
00075         case arglex_netid::token_check:
00076             if (check_flag)
00077             {
00078                 explain_output_error("too many check files specified");
00079                 cmdline.usage();
00080             }
00081             etc_netid = cmdline.get_filename_or_stdin();
00082             check_flag = true;
00083             break;
00084 
00085         case arglex_netid::token_map:
00086             if (map_flag)
00087             {
00088                 explain_output_error("too many map files specified");
00089                 cmdline.usage();
00090             }
00091             etc_netid = cmdline.get_filename_or_stdin();
00092             map_flag = true;
00093             break;
00094 
00095         case arglex_netid::token_output:
00096             if (!output.empty())
00097             {
00098                 explain_output_error("too many output files specified");
00099                 cmdline.usage();
00100             }
00101             output = cmdline.get_filename_or_stdin();
00102             break;
00103 
00104         case arglex_netid::token_domain:
00105             if (!domain.empty())
00106             {
00107                 explain_output_error("too many domain files specified");
00108                 cmdline.usage();
00109             }
00110             domain = cmdline.get_filename_or_stdin();
00111             break;
00112         }
00113         cmdline.token_next();
00114     }
00115     if (map_flag && check_flag)
00116     {
00117         explain_output_error_and_die
00118         (
00119             "you can use either --map or --check, but not both"
00120         );
00121     }
00122     if (etc_passwd.empty())
00123         explain_output_error_and_die("no passwd file specified");
00124     if (etc_group.empty())
00125         explain_output_error_and_die("no group file specified");
00126     if (etc_hosts.empty())
00127         explain_output_error_and_die("no hosts file specified");
00128     if (domain.empty())
00129         explain_output_error_and_die("no domain specified");
00130     if (map_flag)
00131         map(etc_netid, etc_passwd, etc_group, etc_hosts, domain, output);
00132     else
00133         check(etc_netid, etc_passwd, etc_group, etc_hosts, domain);
00134     return 0;
00135 }
00136 
00137 
00138 // vim: set ts=8 sw=4 et :