/*-1* SPDX-License-Identifier: BSD-4-Clause2*3* Copyright (c) 19964* Bill Paul <[email protected]>. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. All advertising materials mentioning features or use of this software15* must display the following acknowledgement:16* This product includes software developed by Bill Paul.17* 4. Neither the name of the author nor the names of any co-contributors18* may be used to endorse or promote products derived from this software19* without specific prior written permission.20*21* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND22* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE23* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE24* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE25* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL26* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS27* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)28* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT29* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY30* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF31* SUCH DAMAGE.32*/3334#include "namespace.h"35#include <err.h>36#include <sys/types.h>37#include <rpc/des_crypt.h>38#include <rpc/des.h>39#include <string.h>40#include <rpcsvc/crypt.h>41#include "un-namespace.h"4243int44_des_crypt_call(char *buf, int len, struct desparams *dparms)45{46CLIENT *clnt;47desresp *result_1;48desargs des_crypt_1_arg;49struct netconfig *nconf;50void *localhandle;51int stat;5253nconf = NULL;54localhandle = setnetconfig();55while ((nconf = getnetconfig(localhandle)) != NULL) {56if (nconf->nc_protofmly != NULL &&57strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0)58break;59}60if (nconf == NULL) {61warnx("getnetconfig: %s", nc_sperror());62endnetconfig(localhandle);63return(DESERR_HWERROR);64}65clnt = clnt_tp_create(NULL, CRYPT_PROG, CRYPT_VERS, nconf);66if (clnt == (CLIENT *) NULL) {67endnetconfig(localhandle);68return(DESERR_HWERROR);69}70endnetconfig(localhandle);7172des_crypt_1_arg.desbuf.desbuf_len = len;73des_crypt_1_arg.desbuf.desbuf_val = buf;74des_crypt_1_arg.des_dir = (dparms->des_dir == ENCRYPT) ? ENCRYPT_DES : DECRYPT_DES;75des_crypt_1_arg.des_mode = (dparms->des_mode == CBC) ? CBC_DES : ECB_DES;76bcopy(dparms->des_ivec, des_crypt_1_arg.des_ivec, 8);77bcopy(dparms->des_key, des_crypt_1_arg.des_key, 8);7879result_1 = des_crypt_1(&des_crypt_1_arg, clnt);80if (result_1 == (desresp *) NULL) {81clnt_destroy(clnt);82return(DESERR_HWERROR);83}8485stat = result_1->stat;8687if (result_1->stat == DESERR_NONE ||88result_1->stat == DESERR_NOHWDEVICE) {89bcopy(result_1->desbuf.desbuf_val, buf, len);90bcopy(result_1->des_ivec, dparms->des_ivec, 8);91}9293clnt_freeres(clnt, (xdrproc_t)xdr_desresp, result_1);94clnt_destroy(clnt);9596return(stat);97}9899100