nis-util  1.0.D108
nis-util-group/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-group/arglex/group.h>
00023 #include <nis-util-group/byname.h>
00024 #include <nis-util-group/check.h>
00025 
00026 
00027 int
00028 main(int argc, char **argv)
00029 {
00030     arglex_group cmdline(argc, argv);
00031     cmdline.token_first();
00032     rcstring passwd;
00033     rcstring group;
00034     rcstring by_name;
00035     rcstring by_gid;
00036     rcstring output;
00037     while (cmdline.token_cur() != arglex::token_eoln)
00038     {
00039         switch (cmdline.token_cur())
00040         {
00041         default:
00042             cmdline.generic_argument();
00043             break;
00044 
00045         case arglex_group::token_group:
00046             if (!group.empty())
00047             {
00048                 explain_output_error("too many group files specified");
00049                 cmdline.usage();
00050             }
00051             group = cmdline.get_filename_or_stdin();
00052             break;
00053 
00054         case arglex_group::token_passwd:
00055             if (!passwd.empty())
00056             {
00057                 explain_output_error("too many passwd files specified");
00058                 cmdline.usage();
00059             }
00060             passwd = cmdline.get_filename_or_stdin();
00061             break;
00062 
00063         case arglex_group::token_by_name:
00064             if (!by_name.empty())
00065             {
00066                 explain_output_error("too many by_name files specified");
00067                 cmdline.usage();
00068             }
00069             by_name = cmdline.get_filename_or_stdin();
00070             break;
00071 
00072         case arglex_group::token_by_gid:
00073             if (!by_gid.empty())
00074             {
00075                 explain_output_error("too many by_gid files specified");
00076                 cmdline.usage();
00077             }
00078             by_gid = cmdline.get_filename_or_stdin();
00079             break;
00080 
00081         case arglex_group::token_output:
00082             if (!output.empty())
00083             {
00084                 explain_output_error("too many output files specified");
00085                 cmdline.usage();
00086             }
00087             output = cmdline.get_filename_or_stdout();
00088             break;
00089         }
00090         cmdline.token_next();
00091     }
00092     if (!by_name.empty())
00093         group_by_name(by_name, output);
00094     else if (!by_gid.empty())
00095         group_by_gid(by_gid, output);
00096     else
00097     {
00098         if (passwd.empty())
00099             explain_output_error_and_die("no password file specified");
00100         if (group.empty())
00101             explain_output_error_and_die("no group file specified");
00102         check(group, passwd);
00103     }
00104     return 0;
00105 }
00106 
00107 
00108 // vim: set ts=8 sw=4 et :