/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley
* 4.3 BSD under license from the Regents of the University of
* California.
*/
/*
* svcauth_des.c, server-side des authentication
*
* We insure for the service the following:
* (1) The timestamp microseconds do not exceed 1 million.
* (2) The timestamp plus the window is less than the current time.
* (3) The timestamp is not less than the one previously
* seen in the current session.
*
* It is up to the server to determine if the window size is
* too small.
*
*/
#include "mt.h"
#include "rpc_mt.h"
#include <assert.h>
#include <rpc/des_crypt.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <syslog.h>
/*
* LRU cache of conversation keys and some other useful items.
*/
struct cache_entry {
};
/*
* A rwlock_t would seem to make more sense, but it turns out we always
* muck with the cache entries, so would always need a write lock (in
* which case, we might as well use a mutex).
*/
extern mutex_t authdes_lock;
static int cache_init(void); /* initialize the cache */
/* find an entry in the cache */
static void invalidate(char *); /* invalidate entry in cache */
static void __msgout(int, const char *, const char *);
static void __msgout2(const char *, const char *);
/*
* cache statistics
*/
struct {
/*
* Service side authenticator for AUTH_DES
*/
enum auth_stat
{
int status;
int cache_spot_id;
struct area {
} *area;
int fullname_rcvd = 0;
int from_cache = 0;
(void) mutex_lock(&authdes_lock);
if (_rpc_authdes_cache == NULL) {
if (ret == -1) {
(void) mutex_unlock(&authdes_lock);
return (AUTH_FAILED);
}
}
(void) mutex_unlock(&authdes_lock);
/* LINTED pointer cast */
return (AUTH_BADCRED);
/*
* Get the credential
*/
/* LINTED pointer cast */
switch (cred->adc_namekind) {
case ADN_FULLNAME:
if (namelen > MAXNETNAMELEN)
return (AUTH_BADCRED);
break;
case ADN_NICKNAME:
break;
default:
return (AUTH_BADCRED);
}
return (AUTH_BADVERF);
/*
* Get the verifier
*/
/* LINTED pointer cast */
(void) mutex_lock(&authdes_lock);
/*
* Get the conversation key
*/
if (fullname_rcvd) { /* ADN_FULLNAME */
pkey_data, &from_cache)) {
/*
* if the user has no public key, treat him as the
* unauthenticated identity - nobody. If this
* works, it means the client didn't find the
* user's keys and used nobody's secret key
* as a backup.
*/
if (!__getpublickey_cached("nobody",
pkey_data, &from_cache)) {
"_svcauth_des: no public key for nobody or ",
(void) mutex_unlock(&authdes_lock);
return (AUTH_BADCRED); /* no key */
}
/*
* found a public key for nobody. change
* the fullname id to nobody, so the caller
* thinks the client specified nobody
* as the user identity.
*/
}
sessionkey) < 0) {
if (from_cache) {
goto again;
}
"_svcauth_des: key_decryptsessionkey failed for",
(void) mutex_unlock(&authdes_lock);
return (AUTH_BADCRED); /* key not found */
}
} else { /* ADN_NICKNAME */
if (sid >= authdes_cachesz) {
(void) mutex_unlock(&authdes_lock);
return (AUTH_BADCRED); /* garbled credential */
}
/* actually check that the entry is not null */
(void) mutex_unlock(&authdes_lock);
return (AUTH_BADCRED); /* cached out */
}
}
/*
* Decrypt the timestamp
*/
if (fullname_rcvd) { /* ADN_FULLNAME */
(char *)&ivec);
} else {
}
if (DES_FAILED(status)) {
if (fullname_rcvd && from_cache) {
goto again;
}
(void) mutex_unlock(&authdes_lock);
return (AUTH_FAILED); /* system error */
}
/*
* XDR the decrypted timestamp
*/
/*
* Check for valid credentials and verifiers.
* They could be invalid because the key was flushed
* out of the cache, and so a new session should begin.
* Be sure and send AUTH_REJECTED{CRED, VERF} if this is the case.
*/
{
int nick;
int winverf;
if (fullname_rcvd) {
if (from_cache) {
goto again;
}
"_svcauth_des: corrupted window from",
(void) mutex_unlock(&authdes_lock);
/* garbled credential or invalid secret key */
return (AUTH_BADCRED);
}
×tamp);
if (cache_spot_id < 0) {
"_svcauth_des: replayed credential from",
(void) mutex_unlock(&authdes_lock);
return (AUTH_REJECTEDCRED); /* replay */
} else sid = cache_spot_id;
nick = 0;
} else { /* ADN_NICKNAME */
nick = 1;
}
if (fullname_rcvd && from_cache) {
goto again;
}
"_svcauth_des: invalid timestamp received from",
/* cached out (bad key), or garbled verifier */
(void) mutex_unlock(&authdes_lock);
}
if (fullname_rcvd && from_cache) {
goto again;
}
"_svcauth_des: timestamp is earlier than the one previously seen from",
(void) mutex_unlock(&authdes_lock);
return (AUTH_REJECTEDVERF); /* replay */
}
if (fullname_rcvd && from_cache) {
goto again;
}
"_svcauth_des: timestamp expired for",
/* replay, or garbled credential */
(void) mutex_unlock(&authdes_lock);
}
}
/*
* Set up the reply verifier
*/
/*
* xdr the timestamp before encrypting
*/
/*
* encrypt the timestamp
*/
if (DES_FAILED(status)) {
(void) mutex_unlock(&authdes_lock);
return (AUTH_FAILED); /* system error */
}
/*
* Serialize the reply verifier, and update rqst
*/
/* LINTED pointer cast */
"_svcauth_des: Authenticator length error",
(void) mutex_unlock(&authdes_lock);
return (AUTH_REJECTEDVERF);
}
/*
* We succeeded, commit the data to the cache now and
* finish cooking the credential.
*/
} else {
(void) mutex_unlock(&authdes_lock);
return (AUTH_FAILED);
}
/* mark any cached cred invalid */
} else { /* ADN_NICKNAME */
/*
* nicknames are cooked into fullnames
*/
}
(void) mutex_unlock(&authdes_lock);
return (AUTH_OK); /* we made it! */
}
/*
* Initialize the cache
*/
static int
cache_init(void)
{
int i;
/* LOCK HELD ON ENTRY: authdes_lock */
if (_rpc_authdes_cache == NULL) {
return (-1);
}
(void) memset(_rpc_authdes_cache, 0,
sizeof (struct cache_entry) * authdes_cachesz);
/*
* Initialize the lru chain (linked-list)
*/
_rpc_authdes_cache[i].index = i;
}
cache_head = &_rpc_authdes_cache[0];
/*
* These elements of the chain need special attention...
*/
cache_head->index = 0;
return (0);
}
/*
* Find the lru victim
*/
static uint32_t
cache_victim(void)
{
/* LOCK HELD ON ENTRY: authdes_lock */
}
/*
* Note that sid was referenced
*/
static void
{
/* LOCK HELD ON ENTRY: authdes_lock */
/*
* move referenced item from its place on the LRU chain
* to the tail of the chain while checking for special
* conditions (mainly for performance).
*/
/*EMPTY*/;
} else if (cache_head == curr) {
cache_tail = curr;
} else {
}
}
/*
* Find a spot in the cache for a credential containing
* the items given. Return -1 if a replay is detected, otherwise
* return the spot in the cache.
*/
static int
{
int i;
/* LOCK HELD ON ENTRY: authdes_lock */
return (-1); /* replay */
}
return (i);
/* refresh */
}
}
return (cache_victim());
}
/*
* Local credential handling stuff.
* NOTE: bsd unix dependent.
* Other operating systems should put something else here.
*/
struct bsdcred {
};
static void
{
return;
/* LINTED pointer cast */
}
/*
* Map a des credential into a unix cred.
* We cache the credential here so the application does
* not have to make an rpc call every time to interpret
* the credential.
*/
int
{
int i;
int i_grouplen;
if (sid >= authdes_cachesz) {
return (0);
}
(void) mutex_lock(&authdes_lock);
/* LINTED pointer cast */
if (bsdcred_sz == 0) {
bsdcred_sz = sizeof (struct bsdcred) +
}
(void) mutex_unlock(&authdes_lock);
return (0);
}
}
/*
* not in cache: lookup
*/
/* mark as lookup up, but not found */
(void) mutex_unlock(&authdes_lock);
return (0);
}
for (i = i_grouplen - 1; i >= 0; i--) {
}
(void) mutex_unlock(&authdes_lock);
return (1);
}
/*
* Already lookup up, but no match found
*/
(void) mutex_unlock(&authdes_lock);
return (0);
}
/*
* cached credentials
*/
}
(void) mutex_unlock(&authdes_lock);
return (1);
}
static void
{
}
static void
{
}