nis-util
1.0.D108
|
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/colon/group/slurp.h> 00020 #include <lib/symtab.h> 00021 00022 00023 colon_group_slurp::~colon_group_slurp() 00024 { 00025 } 00026 00027 00028 colon_group_slurp::colon_group_slurp(const rcstring &a_filename) : 00029 colon_group(a_filename) 00030 { 00031 } 00032 00033 00034 colon_group_slurp::pointer 00035 colon_group_slurp::create(const rcstring &a_filename) 00036 { 00037 return pointer(new colon_group_slurp(a_filename)); 00038 } 00039 00040 00041 void 00042 colon_group_slurp::read_and_process(void) 00043 { 00044 for (;;) 00045 { 00046 record::pointer rp = get(); 00047 if (!rp) 00048 break; 00049 process(rp); 00050 } 00051 // close(); let derived class do it, or the destructor 00052 } 00053 00054 00055 bool 00056 colon_group_slurp::process(const record::pointer &rp) 00057 { 00058 { 00059 rcstring lc_name = rp->get_name().downcase(); 00060 by_name_t::iterator it = by_name.find(lc_name); 00061 if (it != by_name.end()) 00062 { 00063 error 00064 ( 00065 rp->get_source_location(), 00066 "duplicate %s group name...", 00067 rp->get_name().quote_c().c_str() 00068 ); 00069 error 00070 ( 00071 it->second->get_source_location(), 00072 "... here is the first %s group name", 00073 it->second->get_name().quote_c().c_str() 00074 ); 00075 // avoid cascading errors 00076 return false; 00077 } 00078 by_name.insert(by_name_t::value_type(lc_name, rp)); 00079 } 00080 00081 { 00082 by_gid_t::iterator it = by_gid.find(rp->get_gid()); 00083 if (it != by_gid.end()) 00084 { 00085 error 00086 ( 00087 rp->get_source_location(), 00088 "group %s: duplicate %s group id...", 00089 rp->get_name().quote_c().c_str(), 00090 rp->get_gid().quote_c().c_str() 00091 ); 00092 error 00093 ( 00094 it->second->get_source_location(), 00095 "group %s: ... here is the first %s group id", 00096 it->second->get_name().quote_c().c_str(), 00097 it->second->get_gid().quote_c().c_str() 00098 ); 00099 // avoid cascading errors 00100 return false; 00101 } 00102 by_gid.insert(by_gid_t::value_type(rp->get_gid(), rp)); 00103 } 00104 00105 // looks good so far 00106 return true; 00107 } 00108 00109 00110 colon_group::record::pointer 00111 colon_group_slurp::query_by_name(const rcstring &name) 00112 const 00113 { 00114 by_name_t::const_iterator it = by_name.find(name.downcase()); 00115 if (it == by_name.end()) 00116 return record::pointer(); 00117 return it->second; 00118 } 00119 00120 00121 colon_group::record::pointer 00122 colon_group_slurp::query_by_gid(const rcstring &gid) 00123 const 00124 { 00125 by_gid_t::const_iterator it = by_gid.find(gid); 00126 if (it == by_gid.end()) 00127 return record::pointer(); 00128 return it->second; 00129 } 00130 00131 00132 colon_group::record::pointer 00133 colon_group_slurp::query_by_gid(int gid) 00134 const 00135 { 00136 return query_by_gid(rcstring::format("%d", gid)); 00137 } 00138 00139 00140 // vim: set ts=8 sw=4 et :