4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * Portions of this source code were derived from Berkeley
31 * under license from the Regents of the University of
35 #pragma ident "%Z%%M% %I% %E% SMI"
38 * DESCRIPTION: This file contains various functions used by more than one NIS
39 * components. A lot of this code started off in ypxfr and then
40 * got used by other components. Some of it has become a little
41 * 'quirky' and should probably be re-worked.
52 #include "../ypdefs.h"
62 * DESCRIPTION : Utility functions used by everything.
64 bool check_map_existence(char *);
65 void logprintf2(char *format
, ...);
66 extern bool ypcheck_map_existence_yptol();
69 * This checks to see if the source map files exist, then renames them to the
70 * target names. This is a boolean function. The file names from.pag and
71 * from.dir will be changed to to.pag and to.dir in the success case.
73 * Note: If the second of the two renames fails, yprename_map will try to
74 * un-rename the first pair, and leave the world in the state it was on entry.
75 * This might fail, too, though...
77 * GIVEN : Name of map to copy from
78 * Name of map to copy to
79 * Flag indicating if map is secure.
82 rename_map(from
, to
, secure_map
)
87 char fromfile
[MAXNAMLEN
+ 1];
88 char tofile
[MAXNAMLEN
+ 1];
89 char savefile
[MAXNAMLEN
+ 1];
95 if (!check_map_existence(from
)) {
99 (void) strcpy(fromfile
, from
);
100 (void) strcat(fromfile
, dbm_pag
);
101 (void) strcpy(tofile
, to
);
102 (void) strcat(tofile
, dbm_pag
);
104 if (rename(fromfile
, tofile
)) {
105 logprintf2("Can't mv %s to %s.\n", fromfile
,
110 (void) strcpy(savefile
, tofile
);
111 (void) strcpy(fromfile
, from
);
112 (void) strcat(fromfile
, dbm_dir
);
113 (void) strcpy(tofile
, to
);
114 (void) strcat(tofile
, dbm_dir
);
116 if (rename(fromfile
, tofile
)) {
117 logprintf2("Can't mv %s to %s.\n", fromfile
,
119 (void) strcpy(fromfile
, from
);
120 (void) strcat(fromfile
, dbm_pag
);
121 (void) strcpy(tofile
, to
);
122 (void) strcat(tofile
, dbm_pag
);
124 if (rename(tofile
, fromfile
)) {
126 "Can't recover from rename failure.\n");
134 chmod(savefile
, 0644);
142 * Function : delete_map()
144 * Description: Deletes a map
148 * Return : TRUE = Map deleted
149 * FALSE = Map not completly deleted
155 char fromfile
[MAXNAMLEN
+ 1];
161 if (!check_map_existence(name
)) {
166 (void) strcpy(fromfile
, name
);
167 (void) strcat(fromfile
, dbm_pag
);
169 if (unlink(fromfile
)) {
170 logprintf2("Can't unlink %s.\n", fromfile
);
174 (void) strcpy(fromfile
, name
);
175 (void) strcat(fromfile
, dbm_dir
);
177 if (unlink(fromfile
)) {
178 logprintf2("Can't unlink %s.\n", fromfile
);
186 * This performs an existence check on the dbm data base files <pname>.pag and
190 check_map_existence(pname
)
193 char dbfile
[MAXNAMLEN
+ 1];
194 struct stat64 filestat
;
197 if (!pname
|| ((len
= strlen(pname
)) == 0) ||
198 (len
+ 5) > (MAXNAMLEN
+ 1)) {
203 (void) strcpy(dbfile
, pname
);
204 (void) strcat(dbfile
, dbm_dir
);
206 if (stat64(dbfile
, &filestat
) != -1) {
207 (void) strcpy(dbfile
, pname
);
208 (void) strcat(dbfile
, dbm_pag
);
210 if (stat64(dbfile
, &filestat
) != -1) {
214 if (errno
!= ENOENT
) {
216 "Stat error on map file %s.\n",
225 if (errno
!= ENOENT
) {
227 "Stat error on map file %s.\n",
236 * FUNCTION : logprintf2()
238 * DESCRIPTION: The functions in this file were oringinaly shared between
239 * ypxfr and ypserv. On error they called logprintf().
240 * Unfortunatly this had been implemented differently in the two
241 * sources and not at all in some of the NIS components required
244 * This function is simplified version of logprinf() as/when
245 * possible the other error calls should be migrated to use this
246 * common version. If a common set of functionality can be found
247 * this versions should be modified to support it.
250 logprintf2(char *format
, ...)
254 va_start(ap
, format
);
256 syslog(LOG_ERR
, format
, ap
);
262 * This performs an existence check on the dbm data base files <name>.pag and
263 * <name>.dir. pname is a ptr to the filename. This should be an absolute
265 * Returns TRUE if the map exists and is accessable; else FALSE.
267 * Note: The file name should be a "base" form, without a file "extension" of
268 * .dir or .pag appended. See ypmkfilename for a function which will generate
269 * the name correctly. Errors in the stat call will be reported at this level,
270 * however, the non-existence of a file is not considered an error, and so will
273 * Calls ypcheck_map_existence_yptol() defined in
274 * usr/src/lib/libnisdb/yptol/shim_ancil.c
277 ypcheck_map_existence(char *pname
)
279 return (ypcheck_map_existence_yptol(pname
));