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
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]
23 * Copyright 2000 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
43 * Administrative tool to add a new user to the publickey database
49 #include <rpc/key_prot.h>
50 #include <rpcsvc/ypclnt.h>
57 #define MAXMAPNAMELEN 256
59 extern char *program_name
;
61 static char *basename(char *path
);
62 static int match(char *line
, char *name
);
63 static int _openchild(char *command
, FILE **fto
, FILE **ffrom
);
64 static char SHELL
[] = "/bin/sh";
65 static char UPDATEFILE
[] = "updaters";
66 static char MAKE
[] = "/usr/ccs/bin/make";
69 * Determine if requester is allowed to update the given map,
70 * and update it if so. Returns the yp status, which is zero
71 * if there is no access violation.
74 mapupdate(char *name
, char *mapname
, uint_t op
, char *data
)
76 char updater
[MAXMAPNAMELEN
+ 40];
90 (void) fprintf(stderr
, "%s %s\n", name
, data
);
92 namelen
= strlen(name
);
93 datalen
= strlen(data
);
95 if (stat(MAKE
, &stbuf
) < 0)
98 (void) fprintf(stderr
,
99 "%s: %s not found, please install on the system\n",
103 (void) fprintf(stderr
,
104 "%s: cannot access %s, errno=%d.\n",
105 program_name
, MAKE
, errno
);
108 (void) sprintf(updater
, "%s -s -f %s %s",
109 MAKE
, UPDATEFILE
, mapname
);
110 pid
= _openchild(updater
, &childargs
, &childrslt
);
112 return (YPERR_YPERR
);
117 (void) fprintf(childargs
, "%s\n", name
);
118 (void) fprintf(childargs
, "%u\n", op
);
119 (void) fprintf(childargs
, "%u\n", namelen
);
120 (void) fwrite(name
, namelen
, 1, childargs
);
121 (void) fprintf(childargs
, "\n");
122 (void) fprintf(childargs
, "%u\n", datalen
);
123 (void) fwrite(data
, datalen
, 1, childargs
);
124 (void) fprintf(childargs
, "\n");
125 (void) fclose(childargs
);
130 (void) fscanf(childrslt
, "%d", &yperrno
);
131 (void) fclose(childrslt
);
133 (void) wait(&status
);
135 if (WEXITSTATUS(status
) != 0) {
137 if (status
.w_retcode
!= 0) {
139 return (YPERR_YPERR
);
145 * returns pid, or -1 for failure
148 _openchild(char *command
, FILE **fto
, FILE **ffrom
)
156 if (pipe(pdto
) < 0) {
159 if (pipe(pdfrom
) < 0) {
163 switch (pid
= vfork()) {
165 switch (pid
= fork()) {
172 * child: read from pdto[0], write into pdfrom[1]
177 (void) dup(pdfrom
[1]);
179 com
= malloc((unsigned)strlen(command
) + 6);
183 (void) sprintf(com
, "exec %s", command
);
184 execl(SHELL
, basename(SHELL
), "-c", com
, NULL
);
189 * parent: write into pdto[1], read from pdfrom[0]
191 *fto
= fdopen(pdto
[1], "w");
192 (void) close(pdto
[0]);
193 *ffrom
= fdopen(pdfrom
[0], "r");
194 (void) close(pdfrom
[1]);
200 * error cleanup and return
203 (void) close(pdfrom
[0]);
204 (void) close(pdfrom
[1]);
206 (void) close(pdto
[0]);
207 (void) close(pdto
[1]);
217 p
= strrchr(path
, '/');
224 * Determine if requester is allowed to update the given map,
225 * and update it if so. Returns the status, which is zero
226 * if there is no access violation, 1 otherwise.
227 * This function updates the local file.
230 localupdate(char *name
, char *filename
, uint_t op
, char *data
)
242 if (strcmp(name
, "nobody") == 0) {
243 /* cannot change keys for nobody */
244 (void) fprintf(stderr
,
245 "%s: cannot change key-pair for %s\n",
253 (void) memset(tmpname
, 0, 80);
254 (void) sprintf(tmpname
, "%s.tmp", filename
);
255 rf
= fopen(filename
, "r");
257 (void) fprintf(stderr
,
258 "%s: cannot read %s\n", program_name
, filename
);
265 * Create the new file with the correct permissions
267 wfd
= open(tmpname
, O_CREAT
|O_RDWR
|O_TRUNC
,
268 S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IROTH
);
270 (void) fprintf(stderr
, "%s: cannot create '%s' to write to.\n",
271 program_name
, tmpname
);
275 wf
= fdopen(wfd
, "w");
277 (void) fprintf(stderr
, "%s: cannot fdopen '%s'.\n",
278 program_name
, tmpname
);
285 while (fgets(line
, sizeof (line
), rf
)) {
286 if (err
< 0 && match(line
, name
)) {
293 (void) fprintf(wf
, "%s\t%s\n", name
, data
);
314 (void) fprintf(wf
, "%s\t%s\n", name
, data
);
321 if (rename(tmpname
, filename
) < 0) {
322 (void) fprintf(stderr
,
323 "%s: cannot rename %s to %s\n",
324 program_name
, tmpname
, filename
);
328 if (unlink(tmpname
) < 0) {
329 (void) fprintf(stderr
,
330 "%s: cannot delete %s\n",
331 program_name
, tmpname
);
339 match(char *line
, char *name
)
344 return (strncmp(line
, name
, len
) == 0 &&
345 (line
[len
] == ' ' || line
[len
] == '\t'));