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.
39 #include <sys/types.h>
46 #include "options_tt.h"
48 #include "db/tt_db_object.h"
49 #include "db/tt_db_object_utils.h"
50 #include "db/tt_db_key.h"
51 #include "db/tt_db_object.h"
52 #include "db/tt_db_results.h"
53 #include "db/tt_db_access.h"
54 #include "tt_db_server_consts.h"
56 #define MKERR(msg, err) fprintf(stderr, \
57 "ttdbck: error %s spec: %s\n", \
59 tt_status_message(err))
61 const char* MP_TYPE_PROP = "_NODE_TYPE";
67 // by this point all the information about the spec is collected
68 // in the Spec instance. We make any requested changes to
69 // the Spec instance, then completely replace the
70 // info on disk with the info from the Spec instance.
72 if (opts->repair_type_p()) {
73 type = opts->repair_type();
76 if (opts->repair_filename_p()) {
77 filename = opts->repair_filename();
80 _Tt_db_object_ptr oldobj = new _Tt_db_object();
81 switch(oldobj->getDBResults()) {
85 MKERR("creating", TT_ERR_INTERNAL);
89 _Tt_string objid = oldobj->create(filename, key->key()->string());
90 switch(oldobj->getDBResults()) {
94 MKERR("creating", TT_ERR_INTERNAL);
98 _Tt_db_access_ptr access = oldobj->getAccess();
99 switch(oldobj->getDBResults()) {
103 MKERR("creating", TT_ERR_INTERNAL);
107 switch(oldobj->remove()) {
109 case TT_DB_ERR_NO_SUCH_OBJECT:
110 case TT_DB_ERR_NO_SUCH_PROPERTY:
111 case TT_DB_WRN_FORWARD_POINTER:
113 case TT_DB_ERR_ACCESS_DENIED:
114 MKERR("destroying", TT_ERR_ACCESS);
117 MKERR("destroying", TT_ERR_DBAVAIL);
121 if (opts->repair_delete_p()) {
122 // don't recreate the spec.
125 // Should ensure we are running under a particular namespace
126 // for this? Like an override namespace to force into the
129 _Tt_db_object_ptr newobj = new _Tt_db_object();
130 switch(newobj->getDBResults()) {
134 MKERR("creating", TT_ERR_INTERNAL);
138 _Tt_string newobjid = newobj->create(filename,
139 key->key()->string());
140 switch(newobj->getDBResults()) {
144 MKERR("creating", TT_ERR_INTERNAL);
148 newobj->setType(type);
149 newobj->setAccess(access);
151 // Re-create the properties
153 _Tt_string_list_cursor c;
155 _Tt_string_list_cursor v;
156 _Tt_db_property_ptr dbprop = new _Tt_db_property();
160 int owner_written = 0;
161 int group_written = 0;
162 int mode_written = 0;
166 sp = props->lookup(*c);
167 v.reset(sp->_values);
169 // No values for the property. This is
170 // theoretically impossible -- delete the
172 } else if (sp->_name == TT_DB_OBJECT_TYPE_PROPERTY) {
173 // this is the special prop that holds the
174 // type name. Don't try to set it by that name.
178 TT_OBJECT_OWNER_PROPERTY) {
180 // This is the special user field
181 // Note that the access info is
182 // already written out above.
183 // Re-write it here anyway, in
184 // case it was corrupt in the
187 memcpy((char *)&euid,
188 (char *)(*v), sizeof(uid_t));
191 else if (sp->_name ==
192 TT_OBJECT_GROUP_PROPERTY) {
194 // This is the special group field
195 // See note for owner field above
197 memcpy((char *)&group,
198 (char *)(*v), sizeof(gid_t));
201 else if (sp->_name ==
202 TT_OBJECT_MODE_PROPERTY) {
204 // This is the special mode field
205 // See note for owner field above
207 memcpy((char *)&mode,
208 (char *)(*v), sizeof(mode_t));
213 // Ordinary property -- create
214 // a new _Tt_db_property record
216 dbprop->name = sp->_name;
217 dbprop->values->push(*v);
221 // Add any remaining values
223 dbprop->values->push(*v);
229 newobj->addProperty(dbprop);
232 if (owner_written && group_written && mode_written) {
234 // We have complete access info from the old prop
235 // list, so we may as well use it.
238 access->group = group;
240 newobj->setAccess(access);
243 // There\'s not much we can do if this call doesn\'t work