nis-util
1.0.D108
|
00001 // 00002 // nis-util - NIS Administration Utilities 00003 // Copyright (C) 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 along 00016 // with this program. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 #include <lib/config.h> 00020 #include <algorithm> 00021 #include <libexplain/output.h> 00022 00023 #include <lib/colon/passwd/functor/group_closure.h> 00024 #include <lib/colon/group/slurp.h> 00025 00026 00027 colon_passwd_functor_group_closure::~colon_passwd_functor_group_closure() 00028 { 00029 if (error_count > 0) 00030 { 00031 explain_output_error_and_die 00032 ( 00033 "found %d fatal error%s", 00034 error_count, 00035 (error_count == 1 ? "" : "s") 00036 ); 00037 } 00038 } 00039 00040 00041 colon_passwd_functor_group_closure::colon_passwd_functor_group_closure( 00042 const colon_group_slurp::pointer &a_groups 00043 ) : 00044 groups(a_groups), 00045 error_count(0) 00046 { 00047 } 00048 00049 00050 void 00051 colon_passwd_functor_group_closure::error(const source_location &locn, 00052 const char *fmt, ...) 00053 { 00054 va_list ap; 00055 va_start(ap, fmt); 00056 rcstring msg = rcstring::vformat(fmt, ap); 00057 va_end(ap); 00058 explain_output_error 00059 ( 00060 "%s: %s", 00061 locn.get_both().c_str(), 00062 msg.c_str() 00063 ); 00064 ++error_count; 00065 } 00066 00067 00068 void 00069 colon_passwd_functor_group_closure::operator()( 00070 const colon_passwd::record::pointer &rp) 00071 { 00072 colon_group::record::pointer grp = groups->query_by_gid(rp->get_gid()); 00073 if (!grp) 00074 { 00075 error 00076 ( 00077 rp->get_source_location(), 00078 "user %s: default group %s does not exist in groups map", 00079 rp->get_name().quote_c().c_str(), 00080 rp->get_gid().quote_c().c_str() 00081 ); 00082 } 00083 else 00084 { 00085 grp->append_member(rp->get_name()); 00086 } 00087 } 00088 00089 00090 // vim: set ts=8 sw=4 et :