nis-util  1.0.D108
lib/space/netid/slurp.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/colon/group/slurp.h>
00020 #include <lib/colon/passwd/slurp.h>
00021 #include <lib/space/hosts/slurp.h>
00022 #include <lib/space/netid/slurp.h>
00023 
00024 
00025 space_netid_slurp::~space_netid_slurp()
00026 {
00027 }
00028 
00029 
00030 space_netid_slurp::space_netid_slurp(
00031     const rcstring &a_filename,
00032     const colon_passwd_slurp::pointer &a_passwd,
00033     const colon_group_slurp::pointer &a_group,
00034     const space_hosts_slurp::pointer &a_hosts,
00035     const rcstring &a_domain
00036 ) :
00037     space_netid(a_filename),
00038     passwd(a_passwd),
00039     group(a_group),
00040     hosts(a_hosts),
00041     domain(a_domain)
00042 {
00043 }
00044 
00045 
00046 space_netid_slurp::pointer
00047 space_netid_slurp::create(const rcstring &a_filename,
00048     const colon_passwd_slurp::pointer &a_passwd,
00049     const colon_group_slurp::pointer &a_group,
00050     const space_hosts_slurp::pointer &a_hosts, const rcstring &a_domain)
00051 {
00052     return
00053         pointer
00054         (
00055             new space_netid_slurp
00056             (
00057                 a_filename,
00058                 a_passwd,
00059                 a_group,
00060                 a_hosts,
00061                 a_domain
00062             )
00063         );
00064 }
00065 
00066 
00067 void
00068 space_netid_slurp::process(const record::pointer &rp)
00069 {
00070     //
00071     // check for duplicates
00072     //
00073     {
00074         rcstring name = rp->name();
00075         by_name_t::iterator it = by_name.find(name);
00076         if (it != by_name.end())
00077         {
00078             error
00079             (
00080                 rp->get_source_location(),
00081                 "duplicate %s netid name...",
00082                 name.quote_c().c_str()
00083             );
00084             error
00085             (
00086                 it->second->get_source_location(),
00087                 "... here is the first %s netid name",
00088                 it->second->name().quote_c().c_str()
00089             );
00090         }
00091         else
00092         {
00093             by_name.insert(by_name_t::value_type(name, rp));
00094         }
00095     }
00096 
00097     //
00098     // Check the the domain *doesn't* match.
00099     // The idea is that records in the netid file are permission for
00100     // users in other domains to enter this one.  Thus, they do not have
00101     // this domain as their domain.
00102     //
00103     if (rp->get_domain() == domain)
00104     {
00105         error
00106         (
00107             rp->get_source_location(),
00108             "should be a foreign domain"
00109         );
00110     }
00111 
00112     //
00113     // The UID is meant to be local (the record maps an external netid
00114     // to a local UID).  Check that the UID exists.
00115     //
00116     {
00117         if (!passwd->query_by_uid(rp->get_uid2()))
00118         {
00119             error
00120             (
00121                 rp->get_source_location(),
00122                 "user id %s does no exist in the passwd map",
00123                 rp->get_uid2().quote_c().c_str()
00124             );
00125         }
00126     }
00127 
00128     //
00129     // The GIDs are meant to be local (the record maps an external netid
00130     // to local UIDs).  Check that the GIDs exist.
00131     //
00132     const record::gids_t &gids = rp->get_gids();
00133     for
00134     (
00135         record::gids_t::const_iterator it = gids.begin();
00136         it != gids.end();
00137         ++it
00138     )
00139     {
00140         if (rp->is_host_kind())
00141         {
00142             if (!hosts->query_by_name(*it))
00143             {
00144                 error
00145                 (
00146                     rp->get_source_location(),
00147                     "host name %s does not exist in the hosts map",
00148                     it->quote_c().c_str()
00149                 );
00150             }
00151         }
00152         else
00153         {
00154             if (!group->query_by_gid(*it))
00155             {
00156                 error
00157                 (
00158                     rp->get_source_location(),
00159                     "group id %s does not exist in the groups map",
00160                     it->quote_c().c_str()
00161                 );
00162             }
00163         }
00164     }
00165 }
00166 
00167 
00168 void
00169 space_netid_slurp::read_and_process(void)
00170 {
00171     for (;;)
00172     {
00173         record::pointer rp = get();
00174         if (!rp)
00175             break;
00176         process(rp);
00177     }
00178     close();
00179 }
00180 
00181 
00182 // vim: set ts=8 sw=4 et :