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]
22 * Copyright 2005 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 * YP updater for public key map
42 #include <rpcsvc/ypclnt.h>
45 extern char *malloc();
53 char name
[MAXNETNAMELEN
+ 1];
70 tmpname
= malloc(strlen(fname
) + 4);
71 if (tmpname
== NULL
) {
74 sprintf(tmpname
, "%s.tmp", fname
);
79 if (! scanf("%s\n", name
)) {
82 if (! scanf("%u\n", &op
)) {
85 if (! scanf("%u\n", &keylen
)) {
88 if (! fread(key
, keylen
, 1, stdin
)) {
92 if (! scanf("%u\n", &datalen
)) {
95 if (! fread(data
, datalen
, 1, stdin
)) {
103 if (strcmp(name
, key
) != 0) {
106 if (strcmp(name
, "nobody") == 0) {
108 * Can't change "nobody"s key.
116 rf
= fopen(fname
, "r");
120 wf
= fopen(tmpname
, "w");
125 while (fgets(line
, sizeof (line
), rf
)) {
126 if (err
< 0 && match(line
, name
)) {
133 fprintf(wf
, "%s %s\n", key
, data
);
154 fprintf(wf
, "%s %s\n", key
, data
);
161 if (rename(tmpname
, fname
) < 0) {
165 if (unlink(tmpname
) < 0) {
170 close(0); close(1); close(2);
171 open("/dev/null", O_RDWR
, 0);
173 execl("/bin/sh", "sh", "-c", argv
[2], NULL
);
188 return (strncmp(line
, name
, len
) == 0 &&
189 (line
[len
] == ' ' || line
[len
] == '\t'));