nis-util
1.0.D108
|
00001 // 00002 // nis-util - NIS Administration Utilities 00003 // Copyright (C) 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/ac/string.h> 00020 00021 #include <lib/output.h> 00022 #include <lib/space/auto_master/row/direct.h> 00023 #include <lib/space/automap/functor/direct.h> 00024 00025 00026 space_auto_master_row_direct::~space_auto_master_row_direct() 00027 { 00028 } 00029 00030 00031 space_auto_master_row_direct::space_auto_master_row_direct( 00032 const mount_point &a_mount_point, 00033 const rcstring &field2, 00034 const rcstring &a_options 00035 ) : 00036 space_auto_master_row(a_mount_point, a_options), 00037 maptype(extract_maptype(field2)), 00038 mapname(extract_mapname(field2)) 00039 { 00040 // The file has three fields separated by an arbitrary number 00041 // of blanks or tabs. Lines beginning with # are comments. 00042 // 1. The first field is the mount point. 00043 // 2. Second field is the map file to be consulted for this mount point. 00044 // This field is of the form maptype:mapname, where maptype is one of 00045 // the supported map types (file, program, yp, nisplus, hesiod, userdir, 00046 // ldap), and mapname is the name of the map. 00047 // 3. The third field is optional and can contain options to be 00048 // applied to all entries in the map. 00049 // 00050 // The format of the map file and the options are described in autofs(5). 00051 } 00052 00053 00054 space_auto_master_row_direct::pointer 00055 space_auto_master_row_direct::create(const mount_point &a_mount_point, 00056 const rcstring &field2, const rcstring &a_options) 00057 { 00058 return 00059 pointer 00060 ( 00061 new space_auto_master_row_direct 00062 ( 00063 a_mount_point, 00064 field2, 00065 a_options 00066 ) 00067 ); 00068 } 00069 00070 00071 void 00072 space_auto_master_row_direct::print(const output::pointer &op) 00073 const 00074 { 00075 op->put("/- "); 00076 if (maptype != "yp" && maptype != "nisplus") 00077 { 00078 op->put(maptype); 00079 op->put(':'); 00080 } 00081 op->put(mapname); 00082 if (!get_options().empty()) 00083 { 00084 op->put(' '); 00085 op->put(get_options()); 00086 } 00087 op->put('\n'); 00088 } 00089 00090 00091 void 00092 space_auto_master_row_direct::load_map(const rcstring &filename, 00093 const space_hosts_slurp::pointer &hosts) 00094 { 00095 map = space_automap::create(filename); 00096 space_automap_functor_direct inspector(map.get()); 00097 map->read_and_process(inspector, hosts.get()); 00098 //map->close(); 00099 } 00100 00101 00102 bool 00103 space_auto_master_row_direct::has_associated_file(void) 00104 const 00105 { 00106 // Note: the maptype "file" means a file 00107 // on the *client*, not the server. 00108 return (maptype == "yp" || maptype == "nisplus"); 00109 } 00110 00111 00112 rcstring 00113 space_auto_master_row_direct::get_filename(void) 00114 const 00115 { 00116 return mapname; 00117 } 00118 00119 00120 space_auto_master_row::keys_t 00121 space_auto_master_row_direct::get_keys(void) 00122 const 00123 { 00124 return map->get_keys(); 00125 } 00126 00127 00128 // vim: set ts=8 sw=4 et :