2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
24 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
25 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
26 //%% (c) Copyright 1993, 1994 Novell, Inc.
27 //%% $XConsortium: spec_repair.C /main/3 1995/10/20 16:26:51 rswiston $
32 * Copyright (c) 1990 by Sun Microsystems, Inc.
43 #include "options_tt.h"
45 #include "db/tt_db_object.h"
46 #include "db/tt_db_object_utils.h"
47 #include "db/tt_db_key.h"
48 #include "db/tt_db_object.h"
49 #include "db/tt_db_results.h"
50 #include "db/tt_db_access.h"
51 #include "tt_db_server_consts.h"
53 #define MKERR(msg, err) fprintf(stderr, \
54 "ttdbck: error %s spec: %s\n", \
56 tt_status_message(err))
58 const char* MP_TYPE_PROP = "_NODE_TYPE";
64 // by this point all the information about the spec is collected
65 // in the Spec instance. We make any requested changes to
66 // the Spec instance, then completely replace the
67 // info on disk with the info from the Spec instance.
69 if (opts->repair_type_p()) {
70 type = opts->repair_type();
73 if (opts->repair_filename_p()) {
74 filename = opts->repair_filename();
77 _Tt_db_object_ptr oldobj = new _Tt_db_object();
78 switch(oldobj->getDBResults()) {
82 MKERR("creating", TT_ERR_INTERNAL);
86 _Tt_string objid = oldobj->create(filename, key->key()->string());
87 switch(oldobj->getDBResults()) {
91 MKERR("creating", TT_ERR_INTERNAL);
95 _Tt_db_access_ptr access = oldobj->getAccess();
96 switch(oldobj->getDBResults()) {
100 MKERR("creating", TT_ERR_INTERNAL);
104 switch(oldobj->remove()) {
106 case TT_DB_ERR_NO_SUCH_OBJECT:
107 case TT_DB_ERR_NO_SUCH_PROPERTY:
108 case TT_DB_WRN_FORWARD_POINTER:
110 case TT_DB_ERR_ACCESS_DENIED:
111 MKERR("destroying", TT_ERR_ACCESS);
114 MKERR("destroying", TT_ERR_DBAVAIL);
118 if (opts->repair_delete_p()) {
119 // don't recreate the spec.
122 // Should ensure we are running under a particular namespace
123 // for this? Like an override namespace to force into the
126 _Tt_db_object_ptr newobj = new _Tt_db_object();
127 switch(newobj->getDBResults()) {
131 MKERR("creating", TT_ERR_INTERNAL);
135 _Tt_string newobjid = newobj->create(filename,
136 key->key()->string());
137 switch(newobj->getDBResults()) {
141 MKERR("creating", TT_ERR_INTERNAL);
145 newobj->setType(type);
146 newobj->setAccess(access);
148 // Re-create the properties
150 _Tt_string_list_cursor c;
152 _Tt_string_list_cursor v;
153 _Tt_db_property_ptr dbprop = new _Tt_db_property();
157 int owner_written = 0;
158 int group_written = 0;
159 int mode_written = 0;
163 sp = props->lookup(*c);
164 v.reset(sp->_values);
166 // No values for the property. This is
167 // theoretically impossible -- delete the
169 } else if (sp->_name == TT_DB_OBJECT_TYPE_PROPERTY) {
170 // this is the special prop that holds the
171 // type name. Don't try to set it by that name.
175 TT_OBJECT_OWNER_PROPERTY) {
177 // This is the special user field
178 // Note that the access info is
179 // already written out above.
180 // Re-write it here anyway, in
181 // case it was corrupt in the
184 memcpy((char *)&euid,
185 (char *)(*v), sizeof(uid_t));
188 else if (sp->_name ==
189 TT_OBJECT_GROUP_PROPERTY) {
191 // This is the special group field
192 // See note for owner field above
194 memcpy((char *)&group,
195 (char *)(*v), sizeof(gid_t));
198 else if (sp->_name ==
199 TT_OBJECT_MODE_PROPERTY) {
201 // This is the special mode field
202 // See note for owner field above
204 memcpy((char *)&mode,
205 (char *)(*v), sizeof(mode_t));
210 // Ordinary property -- create
211 // a new _Tt_db_property record
213 dbprop->name = sp->_name;
214 dbprop->values->push(*v);
218 // Add any remaining values
220 dbprop->values->push(*v);
226 newobj->addProperty(dbprop);
229 if (owner_written && group_written && mode_written) {
231 // We have complete access info from the old prop
232 // list, so we may as well use it.
235 access->group = group;
237 newobj->setAccess(access);
240 // There\'s not much we can do if this call doesn\'t work