cmd-inet/usr.sbin: remove -Wno-implicit-function-declaration
[unleashed.git] / usr / src / cmd / ypcmd / ypserv_ancil.c
blob92e04e7f8bb09ad30cac4efbaf228f13f23f260a
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
35 #pragma ident "%Z%%M% %I% %E% SMI"
37 static char sccsid[] = "@(#)ypserv_ancil.c 1.13 88/02/08 Copyr 1984 Sun Micro";
39 #include <dirent.h>
40 #include <syslog.h>
41 #include "ypsym.h"
42 #include "ypdefs.h"
43 USE_YPDBPATH
44 USE_DBM
45 #include "shim_hooks.h"
46 #include "shim.h"
47 #include "yptol.h"
49 extern unsigned int strlen();
50 extern int strcmp();
51 extern int isvar_sysv();
52 extern char *strncpy();
53 extern int yp_getkey();
56 * This generates a list of the maps in a domain.
58 int
59 yplist_maps(domain, list)
60 char *domain;
61 struct ypmaplist **list;
63 DIR *dirp;
64 struct dirent *dp;
65 char domdir[MAXNAMLEN + 1];
66 char path[MAXNAMLEN + 1];
67 char map_key[YPMAXMAP + 1];
68 int error;
69 char *ext;
70 struct ypmaplist *map;
71 int namesz;
72 char *mapname;
74 *list = NULL;
76 if (!ypcheck_domain(domain)) {
77 return (YP_NODOM);
80 (void) strcpy(domdir, ypdbpath);
81 (void) strcat(domdir, "/");
82 (void) strcat(domdir, domain);
84 if ((dirp = opendir(domdir)) == NULL) {
85 return (YP_YPERR);
88 error = YP_TRUE;
90 for (dp = readdir(dirp); error == YP_TRUE && dp != NULL;
91 dp = readdir(dirp)) {
93 * If it's possible that the file name is one of the two files
94 * implementing a map, remove the extension (dbm_pag or dbm_dir)
96 namesz = (int)strlen(dp->d_name);
98 if (namesz < sizeof (dbm_pag) - 1)
99 continue; /* Too Short */
101 ext = &(dp->d_name[namesz - (sizeof (dbm_pag) - 1)]);
103 if (strcmp(ext, dbm_pag) != 0)
104 continue; /* No dbm file extension */
106 *ext = '\0';
110 * In yptol mode look at LDAP_ prefixed maps. In non yptol mode
111 * ignore them.
113 if (yptol_mode) {
114 if (0 != strncmp(dp->d_name, NTOL_PREFIX,
115 strlen(NTOL_PREFIX)))
116 continue;
119 * Already have an LDAP_ prefix. Don't want to add it
120 * twice.
122 mapname = dp->d_name + strlen(NTOL_PREFIX);
123 } else {
124 if (0 == strncmp(dp->d_name, NTOL_PREFIX,
125 strlen(NTOL_PREFIX)))
126 continue;
127 mapname = dp->d_name;
130 ypmkfilename(domain, mapname, path);
133 * At this point, path holds the map file base name (no dbm
134 * file extension), and mapname holds the map name.
136 if (ypcheck_map_existence(path) &&
137 !onmaplist(mapname, *list)) {
139 if ((map = (struct ypmaplist *)malloc(
140 sizeof (struct ypmaplist))) == NULL) {
141 error = YP_YPERR;
142 break;
145 map->ypml_next = *list;
146 *list = map;
147 namesz = (int)strlen(mapname);
149 if (namesz <= YPMAXMAP) {
150 if (yp_getkey(mapname, map_key,
151 MAXALIASLEN) < 0) {
153 fprintf(stderr,
154 "yplist_maps: getkey failed for %s\n",
155 mapname);
156 error = YP_YPERR;
157 break;
158 } else
159 (void) strcpy(map->ypml_name, map_key);
160 } else {
161 if (yp_getkey(mapname, map_key,
162 MAXALIASLEN) < 0) {
163 fprintf(stderr,
164 "yplist_maps: getkey failed for %s\n",
165 mapname);
166 error = YP_YPERR;
167 break;
168 } else if (strcmp(mapname, map_key) == 0) {
169 (void) strncpy(map->ypml_name,
170 mapname,
171 (unsigned int) namesz);
172 map->ypml_name[YPMAXMAP] = '\0';
173 } else {
174 (void) strcpy(map->ypml_name, map_key);
180 closedir(dirp);
181 return (error);