nis-util  1.0.D108
nis-util-netgroup/main.cc
Go to the documentation of this file.
00001 //
00002 // nis-util - NIS Administration Utilities
00003 // Copyright (C) 2001, 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-netgroup/arglex/netgroup.h>
00023 #include <nis-util-netgroup/check.h>
00024 #include <nis-util-netgroup/map.h>
00025 
00026 
00027 int
00028 main(int argc, char **argv)
00029 {
00030     arglex_netgroup cmdline(argc, argv);
00031     cmdline.token_first();
00032     rcstring etc_netgroup;
00033     rcstring etc_hosts;
00034     rcstring etc_passwd;
00035     rcstring by_name;
00036     rcstring by_user;
00037     rcstring by_host;
00038     rcstring output;
00039     while (cmdline.token_cur() != arglex::token_eoln)
00040     {
00041         switch (cmdline.token_cur())
00042         {
00043         default:
00044             cmdline.generic_argument();
00045             break;
00046 
00047         case arglex_netgroup::token_check:
00048             cmdline.get_filename_or_stdin(etc_netgroup);
00049             break;
00050 
00051         case arglex_netgroup::token_passwd:
00052             cmdline.get_filename_or_stdin(etc_passwd);
00053             break;
00054 
00055         case arglex_netgroup::token_hosts:
00056             cmdline.get_filename_or_stdin(etc_hosts);
00057             break;
00058 
00059         case arglex_netgroup::token_by_host:
00060             cmdline.get_filename_or_stdin(by_host);
00061             break;
00062 
00063         case arglex_netgroup::token_map:
00064             cmdline.get_filename_or_stdin(by_name);
00065             break;
00066 
00067         case arglex_netgroup::token_by_user:
00068             cmdline.get_filename_or_stdin(by_user);
00069             break;
00070 
00071         case arglex_netgroup::token_output:
00072             cmdline.get_filename_or_stdout(output);
00073             break;
00074         }
00075         cmdline.token_next();
00076     }
00077     if (!by_host.empty())
00078         map_by_host(by_host, output);
00079     else if (!by_name.empty())
00080         map_by_name(by_name, output);
00081     else if (!by_user.empty())
00082         map_by_user(by_user, output);
00083     else
00084     {
00085         if (etc_hosts.empty())
00086             explain_output_error_and_die("no hosts file specified");
00087         if (etc_passwd.empty())
00088             explain_output_error_and_die("no passwd file specified");
00089         check(etc_netgroup, etc_hosts, etc_passwd);
00090     }
00091     return 0;
00092 }
00093 
00094 
00095 // vim: set ts=8 sw=4 et :