| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#include <err.h> |
| 35 |
#include <sys/types.h> |
| 36 |
#include <rpc/des_crypt.h> |
| 37 |
#include <rpc/des.h> |
| 38 |
#include <string.h> |
| 39 |
#include <rpcsvc/crypt.h> |
| 40 |
|
| 41 |
#include <netconfig.h> |
| 42 |
|
| 43 |
int |
| 44 |
_des_crypt_call(buf, len, dparms) |
| 45 |
char *buf; |
| 46 |
int len; |
| 47 |
struct desparams *dparms; |
| 48 |
{ |
| 49 |
CLIENT *clnt; |
| 50 |
desresp *result_1; |
| 51 |
desargs des_crypt_1_arg; |
| 52 |
struct netconfig *nconf; |
| 53 |
void *localhandle; |
| 54 |
int stat; |
| 55 |
|
| 56 |
nconf = NULL; |
| 57 |
localhandle = setnetconfig(); |
| 58 |
while ((nconf = getnetconfig(localhandle)) != NULL) { |
| 59 |
if (nconf->nc_protofmly != NULL && |
| 60 |
strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0) |
| 61 |
break; |
| 62 |
} |
| 63 |
if (nconf == NULL) { |
| 64 |
warnx("getnetconfig: %s", nc_sperror()); |
| 65 |
return(DESERR_HWERROR); |
| 66 |
} |
| 67 |
clnt = clnt_tp_create(NULL, CRYPT_PROG, CRYPT_VERS, nconf); |
| 68 |
if (clnt == (CLIENT *) NULL) { |
| 69 |
endnetconfig(localhandle); |
| 70 |
return(DESERR_HWERROR); |
| 71 |
} |
| 72 |
endnetconfig(localhandle); |
| 73 |
|
| 74 |
des_crypt_1_arg.desbuf.desbuf_len = len; |
| 75 |
des_crypt_1_arg.desbuf.desbuf_val = buf; |
| 76 |
des_crypt_1_arg.des_dir = dparms->des_dir; |
| 77 |
des_crypt_1_arg.des_mode = dparms->des_mode; |
| 78 |
memcpy(des_crypt_1_arg.des_ivec, dparms->des_ivec, 8); |
| 79 |
memcpy(des_crypt_1_arg.des_key, dparms->des_key, 8); |
| 80 |
|
| 81 |
result_1 = des_crypt_1(&des_crypt_1_arg, clnt); |
| 82 |
if (result_1 == (desresp *) NULL) { |
| 83 |
clnt_destroy(clnt); |
| 84 |
return(DESERR_HWERROR); |
| 85 |
} |
| 86 |
|
| 87 |
stat = result_1->stat; |
| 88 |
|
| 89 |
if (result_1->stat == DESERR_NONE || |
| 90 |
result_1->stat == DESERR_NOHWDEVICE) { |
| 91 |
memcpy(buf, result_1->desbuf.desbuf_val, len); |
| 92 |
memcpy(dparms->des_ivec, result_1->des_ivec, 8); |
| 93 |
} |
| 94 |
|
| 95 |
clnt_freeres(clnt, (xdrproc_t)xdr_desresp, result_1); |
| 96 |
clnt_destroy(clnt); |
| 97 |
|
| 98 |
return(stat); |
| 99 |
} |