/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Set secret key on local machine
*/
#include <stdio.h>
#include <rpc/key_prot.h>
#include <string.h>
#include <rpcsvc/nis_dhext.h>
/* Should last until 16384-bit DH keys */
extern int key_setnet_g();
static void logout_curr_key();
static int mkrootkey;
/*
* fgets is broken in that if it reads a NUL character it will always return
* EOF. This replacement can deal with NULs
*/
static char *
{
int i = 0;
int rs = 0;
char c;
if (fildes < 0)
return (NULL);
while (i < n - 1) {
switch (rs) {
case 1:
break;
case 0:
/* EOF */
if (i > 0)
s[i] = '\0';
return (NULL);
break;
default:
return (NULL);
}
switch (c) {
case '\0':
break;
case '\n':
s[i] = c;
s[++i] = '\0';
return (s);
default:
if (c != '\0')
s[i++] = c;
}
}
s[i] = '\0';
return (s);
}
/* write unencrypted secret key into root key file */
static void
{
perror("Could not create /etc/.rootkey.bak");
goto rootkey_err;
}
}
perror("Could not open /etc/.rootkey for writing");
"Attempting to restore original /etc/.rootkey\n");
goto rootkey_err;
}
perror("Could not open /etc/.rootkey for writing");
"Attempting to restore original /etc/.rootkey\n");
goto rootkey_err;
}
perror("Could not open /etc/.rootkey.bak for reading");
"Attempting to restore original /etc/.rootkey\n");
goto rootkey_err;
}
/*
* No encryption algorithm found in the file
* (atent) so default to DES.
*/
}
/*
* 192-bit keys always go on the first line
*/
if (lineone) {
if (keylen == 192) {
} else
} else {
/*
* Silently remove lines with the same
*/
if (gotit)
continue;
else
} else
}
}
/* Append key to rootkey file */
if (!gotit) {
if (keylen == 192)
else {
if (lineone)
}
}
if (keylen == 192)
else
return;
flavor);
}
/* Perform AUTH_DES keylogin */
static int
{
fullname);
if (sec_domain && *sec_domain &&
"The system default domain '%s' is different from the Secure RPC\n\
domain %s where the key is stored. The Secure RPC domainname is\n\
defined by the directory object stored in the /var/nis/NIS_COLD_START file.\n\
If you need to change this Secure RPC domainname, please use the nisinit(1M)\n\
} else {
"Make sure the secret key is stored in domain %s\n",
}
return (1);
}
if (secret[0] == 0) {
fullname);
return (1);
}
/* revoke any existing (lingering) credentials... */
netst.st_pub_key[0] = 0;
/* do actual key login */
if (key_setnet(&netst) < 0) {
fullname);
if (mkrootkey == 0) /* nothing else to do */
return (1);
}
/* write unencrypted secret key into root key file */
if (mkrootkey)
return (0);
}
/*
* Revokes the existing credentials for Secure-RPC and Secure-NFS.
* This should only be called if the user entered the correct password;
* sorta like the way "su" doesn't force a login if you enter the wrong
* password.
*/
static void
{
/*
* try to revoke the existing key/credentials, assuming
* one exists. this will effectively mark "stale" any
* cached credientials...
*/
if (key_setsecret(secret) < 0) {
return;
}
/*
* it looks like a credential already existed, so try and
* revoke any lingering Secure-NFS privledges.
*/
}
void
char *cmd;
{
exit(1);
}
int
{
char *getpass();
char *pass;
int i = 0;
if (argc == 1)
mkrootkey = 0;
if (geteuid() != 0) {
exit(1);
}
mkrootkey = 1;
} else
if (getnetname(fullname) == 0) {
exit(1);
}
exit(1);
while (mechlist[i]) {
char *alias;
if (AUTH_DES_COMPAT_CHK(mechlist[i])) {
i++;
continue;
}
else
alias = "";
"WARNING: Could not find %s's %s secret key\n",
i++;
continue;
}
if (secret[0] == 0) {
"Password incorrect for %s's %s key.\n",
i++;
continue;
}
"Could not set %s's %s secret key\n",
"May be the keyserv is down?\n");
exit(1);
}
if (mkrootkey)
i++;
}
} else
return (0);
}