nis-util
1.0.D108
|
00001 // 00002 // nis-util - NIS Administration Utilities 00003 // Copyright (C) 2001, 2003, 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/ac/errno.h> 00020 #include <lib/ac/sys/types.h> 00021 #include <lib/ac/sys/stat.h> 00022 #include <lib/ac/unistd.h> 00023 00024 #include <lib/colon/group/slurp/check.h> 00025 #include <lib/colon/passwd/slurp.h> 00026 00027 00028 colon_group_slurp_check::~colon_group_slurp_check() 00029 { 00030 } 00031 00032 00033 colon_group_slurp_check::colon_group_slurp_check( 00034 const rcstring &a_filename, 00035 const colon_passwd_slurp::pointer &a_passwd 00036 ) : 00037 colon_group_slurp(a_filename), 00038 passwd(a_passwd) 00039 { 00040 } 00041 00042 00043 colon_group_slurp_check::pointer 00044 colon_group_slurp_check::create(const rcstring &a_filename, 00045 const colon_passwd_slurp::pointer &a_passwd) 00046 { 00047 return pointer(new colon_group_slurp_check(a_filename, a_passwd)); 00048 } 00049 00050 00051 bool 00052 colon_group_slurp_check::process(const record::pointer &rp) 00053 { 00054 if (!colon_group_slurp::process(rp)) 00055 return false; 00056 00057 // 00058 // Check the member field 00059 // 00060 const record::members_t &members = rp->get_members(); 00061 for 00062 ( 00063 record::members_t::const_iterator it = members.begin(); 00064 it != members.end(); 00065 ++it 00066 ) 00067 { 00068 colon_passwd::record::pointer pw = passwd->query_by_name(*it); 00069 if (!pw) 00070 { 00071 error 00072 ( 00073 rp->get_source_location(), 00074 "group %s: member user %s does not exist", 00075 rp->get_name().quote_c().c_str(), 00076 it->quote_c().c_str() 00077 ); 00078 return false; 00079 } 00080 00081 if (pw->get_gid() == rp->get_gid() && !rp->is_members_only()) 00082 { 00083 error 00084 ( 00085 pw->get_source_location(), 00086 "user %s has group %s as their default group...", 00087 pw->get_name().quote_c().c_str(), 00088 rp->get_name().quote_c().c_str() 00089 ); 00090 error 00091 ( 00092 rp->get_source_location(), 00093 "... remove them from the %s group member list", 00094 rp->get_name().quote_c().c_str() 00095 ); 00096 return false; 00097 } 00098 pw->append_group(rp->get_gid()); 00099 } 00100 00101 // Looks good so far. 00102 return true; 00103 } 00104 00105 00106 // vim: set ts=8 sw=4 et :