Blame src/crypt_client.c

Packit Service 4f68e0
/*
Packit Service 4f68e0
 * Copyright (c) 1996
Packit Service 4f68e0
 *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
Packit Service 4f68e0
 *
Packit Service 4f68e0
 * Redistribution and use in source and binary forms, with or without
Packit Service 4f68e0
 * modification, are permitted provided that the following conditions
Packit Service 4f68e0
 * are met:
Packit Service 4f68e0
 * 1. Redistributions of source code must retain the above copyright
Packit Service 4f68e0
 *    notice, this list of conditions and the following disclaimer.
Packit Service 4f68e0
 * 2. Redistributions in binary form must reproduce the above copyright
Packit Service 4f68e0
 *    notice, this list of conditions and the following disclaimer in the
Packit Service 4f68e0
 *    documentation and/or other materials provided with the distribution.
Packit Service 4f68e0
 * 3. All advertising materials mentioning features or use of this software
Packit Service 4f68e0
 *    must display the following acknowledgement:
Packit Service 4f68e0
 *	This product includes software developed by Bill Paul.
Packit Service 4f68e0
 * 4. Neither the name of the author nor the names of any co-contributors
Packit Service 4f68e0
 *    may be used to endorse or promote products derived from this software
Packit Service 4f68e0
 *    without specific prior written permission.
Packit Service 4f68e0
 *
Packit Service 4f68e0
 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
Packit Service 4f68e0
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit Service 4f68e0
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit Service 4f68e0
 * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
Packit Service 4f68e0
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit Service 4f68e0
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit Service 4f68e0
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit Service 4f68e0
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit Service 4f68e0
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit Service 4f68e0
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit Service 4f68e0
 * SUCH DAMAGE.
Packit Service 4f68e0
 */
Packit Service 4f68e0
Packit Service 4f68e0
Packit Service 4f68e0
#include <err.h>
Packit Service 4f68e0
#include <sys/types.h>
Packit Service 4f68e0
#include <rpc/des_crypt.h>
Packit Service 4f68e0
#include <rpc/des.h>
Packit Service 4f68e0
#include <string.h>
Packit Service 4f68e0
#include <rpcsvc/crypt.h>
Packit Service 4f68e0
Packit Service 4f68e0
#include <netconfig.h>
Packit Service 4f68e0
Packit Service 4f68e0
int
Packit Service 4f68e0
_des_crypt_call(buf, len, dparms)
Packit Service 4f68e0
	char *buf;
Packit Service 4f68e0
	int len;
Packit Service 4f68e0
	struct desparams *dparms;
Packit Service 4f68e0
{
Packit Service 4f68e0
	CLIENT *clnt;
Packit Service 4f68e0
	desresp  *result_1;
Packit Service 4f68e0
	desargs  des_crypt_1_arg;
Packit Service 4f68e0
	struct netconfig *nconf;
Packit Service 4f68e0
	void *localhandle;
Packit Service 4f68e0
	int stat;
Packit Service 4f68e0
Packit Service 4f68e0
	nconf = NULL;
Packit Service 4f68e0
	localhandle = setnetconfig();
Packit Service 4f68e0
	while ((nconf = getnetconfig(localhandle)) != NULL) {
Packit Service 4f68e0
		if (nconf->nc_protofmly != NULL &&
Packit Service 4f68e0
		     strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0)
Packit Service 4f68e0
			break;
Packit Service 4f68e0
	}
Packit Service 4f68e0
	if (nconf == NULL) {
Packit Service 4f68e0
		warnx("getnetconfig: %s", nc_sperror());
Packit Service 4f68e0
		return(DESERR_HWERROR);
Packit Service 4f68e0
	}
Packit Service 4f68e0
	clnt = clnt_tp_create(NULL, CRYPT_PROG, CRYPT_VERS, nconf);
Packit Service 4f68e0
	if (clnt == (CLIENT *) NULL) {
Packit Service 4f68e0
		endnetconfig(localhandle);
Packit Service 4f68e0
		return(DESERR_HWERROR);
Packit Service 4f68e0
	}
Packit Service 4f68e0
	endnetconfig(localhandle);
Packit Service 4f68e0
Packit Service 4f68e0
	des_crypt_1_arg.desbuf.desbuf_len = len;
Packit Service 4f68e0
	des_crypt_1_arg.desbuf.desbuf_val = buf;
Packit Service 4f68e0
	des_crypt_1_arg.des_dir = dparms->des_dir;
Packit Service 4f68e0
	des_crypt_1_arg.des_mode = dparms->des_mode;
Packit Service 4f68e0
	bcopy(dparms->des_ivec, des_crypt_1_arg.des_ivec, 8);
Packit Service 4f68e0
	bcopy(dparms->des_key, des_crypt_1_arg.des_key, 8);
Packit Service 4f68e0
Packit Service 4f68e0
	result_1 = des_crypt_1(&des_crypt_1_arg, clnt);
Packit Service 4f68e0
	if (result_1 == (desresp *) NULL) {
Packit Service 4f68e0
		clnt_destroy(clnt);
Packit Service 4f68e0
		return(DESERR_HWERROR);
Packit Service 4f68e0
	}
Packit Service 4f68e0
Packit Service 4f68e0
	stat = result_1->stat;
Packit Service 4f68e0
Packit Service 4f68e0
	if (result_1->stat == DESERR_NONE ||
Packit Service 4f68e0
	    result_1->stat == DESERR_NOHWDEVICE) {
Packit Service 4f68e0
		bcopy(result_1->desbuf.desbuf_val, buf, len);
Packit Service 4f68e0
		bcopy(result_1->des_ivec, dparms->des_ivec, 8);
Packit Service 4f68e0
	}
Packit Service 4f68e0
Packit Service 4f68e0
	clnt_freeres(clnt, (xdrproc_t)xdr_desresp, result_1);
Packit Service 4f68e0
	clnt_destroy(clnt);
Packit Service 4f68e0
Packit Service 4f68e0
	return(stat);
Packit Service 4f68e0
}