git: 35a624c54956 - main - keyserv: Use C89 function definitions.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 18 Apr 2023 18:31:40 UTC
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=35a624c54956e5241c555ad5cf71213de02000af commit 35a624c54956e5241c555ad5cf71213de02000af Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2023-04-18 18:29:27 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2023-04-18 18:30:51 +0000 keyserv: Use C89 function definitions. Also use more accurate function pointer types, and trim some duplicate (but incomplete) function prototypes. Reviewed by: zlei Differential Revision: https://reviews.freebsd.org/D39533 --- usr.sbin/keyserv/crypt_server.c | 9 +---- usr.sbin/keyserv/keyserv.c | 90 ++++++++++++++--------------------------- usr.sbin/keyserv/setkey.c | 87 ++++++++++----------------------------- 3 files changed, 53 insertions(+), 133 deletions(-) diff --git a/usr.sbin/keyserv/crypt_server.c b/usr.sbin/keyserv/crypt_server.c index a97c2e1904b3..25f48e978781 100644 --- a/usr.sbin/keyserv/crypt_server.c +++ b/usr.sbin/keyserv/crypt_server.c @@ -143,10 +143,7 @@ static void swap_byte(unsigned char *a, unsigned char *b) } /* Dummy _des_crypt function that uses ARCFOUR with a 40 bit key */ -int _arcfour_crypt(buf, len, desp) - char *buf; - int len; - struct desparams *desp; +int _arcfour_crypt(char *buf, int len, struct desparams *desp) { struct arcfour_key arcfourk; @@ -174,9 +171,7 @@ static void *dlhandle; #define LIBCRYPTO "libcrypto.so.2" #endif -void load_des(warn, libpath) - int warn; - char *libpath; +void load_des(int warn, char *libpath) { char dlpath[MAXPATHLEN]; diff --git a/usr.sbin/keyserv/keyserv.c b/usr.sbin/keyserv/keyserv.c index 051521636ce7..7935a72941ae 100644 --- a/usr.sbin/keyserv/keyserv.c +++ b/usr.sbin/keyserv/keyserv.c @@ -83,9 +83,8 @@ static int debugging = 1; static int debugging = 0; #endif -static void keyprogram(); +static void keyprogram(struct svc_req *rqstp, SVCXPRT *transp); static des_block masterkey; -char *getenv(); static char ROOTKEY[] = "/etc/.rootkey"; /* @@ -107,9 +106,7 @@ cryptkeyres *key_decrypt_pk_2_svc_prog( uid_t, cryptkeyarg2 * ); des_block *key_gen_1_svc_prog( void *, struct svc_req * ); int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { int nflag = 0; int c; @@ -221,8 +218,7 @@ main(argc, argv) * randomize the master key the best we can */ static void -randomize(master) - des_block *master; +randomize(des_block *master) { master->key.low = arc4random(); master->key.high = arc4random(); @@ -234,9 +230,7 @@ randomize(master) * Returns 1 on success. */ static int -getrootkey(master, prompt) - des_block *master; - int prompt; +getrootkey(des_block *master, int prompt) { char *passwd; char name[MAXNETNAMELEN + 1]; @@ -306,8 +300,7 @@ getrootkey(master, prompt) * Procedures to implement RPC service */ char * -strstatus(status) - keystatus status; +strstatus(keystatus status) { switch (status) { case KEY_SUCCESS: @@ -324,9 +317,7 @@ strstatus(status) } keystatus * -key_set_1_svc_prog(uid, key) - uid_t uid; - keybuf key; +key_set_1_svc_prog(uid_t uid, keybuf key) { static keystatus status; @@ -343,9 +334,7 @@ key_set_1_svc_prog(uid, key) } cryptkeyres * -key_encrypt_pk_2_svc_prog(uid, arg) - uid_t uid; - cryptkeyarg2 *arg; +key_encrypt_pk_2_svc_prog(uid_t uid, cryptkeyarg2 *arg) { static cryptkeyres res; @@ -371,9 +360,7 @@ key_encrypt_pk_2_svc_prog(uid, arg) } cryptkeyres * -key_decrypt_pk_2_svc_prog(uid, arg) - uid_t uid; - cryptkeyarg2 *arg; +key_decrypt_pk_2_svc_prog(uid_t uid, cryptkeyarg2 *arg) { static cryptkeyres res; @@ -399,9 +386,7 @@ key_decrypt_pk_2_svc_prog(uid, arg) } keystatus * -key_net_put_2_svc_prog(uid, arg) - uid_t uid; - key_netstarg *arg; +key_net_put_2_svc_prog(uid_t uid, key_netstarg *arg) { static keystatus status; @@ -423,9 +408,7 @@ key_net_put_2_svc_prog(uid, arg) } key_netstres * -key_net_get_2_svc_prog(uid, arg) - uid_t uid; - void *arg; +key_net_get_2_svc_prog(uid_t uid, void *arg) { static key_netstres keynetname; @@ -452,9 +435,7 @@ key_net_get_2_svc_prog(uid, arg) } cryptkeyres * -key_get_conv_2_svc_prog(uid, arg) - uid_t uid; - keybuf arg; +key_get_conv_2_svc_prog(uid_t uid, keybuf arg) { static cryptkeyres res; @@ -480,9 +461,7 @@ key_get_conv_2_svc_prog(uid, arg) cryptkeyres * -key_encrypt_1_svc_prog(uid, arg) - uid_t uid; - cryptkeyarg *arg; +key_encrypt_1_svc_prog(uid_t uid, cryptkeyarg *arg) { static cryptkeyres res; @@ -508,9 +487,7 @@ key_encrypt_1_svc_prog(uid, arg) } cryptkeyres * -key_decrypt_1_svc_prog(uid, arg) - uid_t uid; - cryptkeyarg *arg; +key_decrypt_1_svc_prog(uid_t uid, cryptkeyarg *arg) { static cryptkeyres res; @@ -537,9 +514,7 @@ key_decrypt_1_svc_prog(uid, arg) /* ARGSUSED */ des_block * -key_gen_1_svc_prog(v, s) - void *v; - struct svc_req *s; +key_gen_1_svc_prog(void *v, struct svc_req *s) { struct timeval time; static des_block keygen; @@ -561,9 +536,7 @@ key_gen_1_svc_prog(v, s) } getcredres * -key_getcred_1_svc_prog(uid, name) - uid_t uid; - netnamestr *name; +key_getcred_1_svc_prog(uid_t uid, netnamestr *name) { static getcredres res; static u_int gids[NGROUPS]; @@ -594,9 +567,7 @@ key_getcred_1_svc_prog(uid, name) * RPC boilerplate */ static void -keyprogram(rqstp, transp) - struct svc_req *rqstp; - SVCXPRT *transp; +keyprogram(struct svc_req *rqstp, SVCXPRT *transp) { union { keybuf key_set_1_arg; @@ -613,7 +584,8 @@ keyprogram(rqstp, transp) } argument; char *result; xdrproc_t xdr_argument, xdr_result; - char *(*local) (); + typedef void *(svc_cb)(uid_t uid, void *arg); + svc_cb *local; uid_t uid = -1; int check_auth; @@ -625,49 +597,49 @@ keyprogram(rqstp, transp) case KEY_SET: xdr_argument = (xdrproc_t)xdr_keybuf; xdr_result = (xdrproc_t)xdr_int; - local = (char *(*)()) key_set_1_svc_prog; + local = (svc_cb *)key_set_1_svc_prog; check_auth = 1; break; case KEY_ENCRYPT: xdr_argument = (xdrproc_t)xdr_cryptkeyarg; xdr_result = (xdrproc_t)xdr_cryptkeyres; - local = (char *(*)()) key_encrypt_1_svc_prog; + local = (svc_cb *)key_encrypt_1_svc_prog; check_auth = 1; break; case KEY_DECRYPT: xdr_argument = (xdrproc_t)xdr_cryptkeyarg; xdr_result = (xdrproc_t)xdr_cryptkeyres; - local = (char *(*)()) key_decrypt_1_svc_prog; + local = (svc_cb *)key_decrypt_1_svc_prog; check_auth = 1; break; case KEY_GEN: xdr_argument = (xdrproc_t)xdr_void; xdr_result = (xdrproc_t)xdr_des_block; - local = (char *(*)()) key_gen_1_svc_prog; + local = (svc_cb *)key_gen_1_svc_prog; check_auth = 0; break; case KEY_GETCRED: xdr_argument = (xdrproc_t)xdr_netnamestr; xdr_result = (xdrproc_t)xdr_getcredres; - local = (char *(*)()) key_getcred_1_svc_prog; + local = (svc_cb *)key_getcred_1_svc_prog; check_auth = 0; break; case KEY_ENCRYPT_PK: xdr_argument = (xdrproc_t)xdr_cryptkeyarg2; xdr_result = (xdrproc_t)xdr_cryptkeyres; - local = (char *(*)()) key_encrypt_pk_2_svc_prog; + local = (svc_cb *)key_encrypt_pk_2_svc_prog; check_auth = 1; break; case KEY_DECRYPT_PK: xdr_argument = (xdrproc_t)xdr_cryptkeyarg2; xdr_result = (xdrproc_t)xdr_cryptkeyres; - local = (char *(*)()) key_decrypt_pk_2_svc_prog; + local = (svc_cb *)key_decrypt_pk_2_svc_prog; check_auth = 1; break; @@ -675,21 +647,21 @@ keyprogram(rqstp, transp) case KEY_NET_PUT: xdr_argument = (xdrproc_t)xdr_key_netstarg; xdr_result = (xdrproc_t)xdr_keystatus; - local = (char *(*)()) key_net_put_2_svc_prog; + local = (svc_cb *)key_net_put_2_svc_prog; check_auth = 1; break; case KEY_NET_GET: xdr_argument = (xdrproc_t) xdr_void; xdr_result = (xdrproc_t)xdr_key_netstres; - local = (char *(*)()) key_net_get_2_svc_prog; + local = (svc_cb *)key_net_get_2_svc_prog; check_auth = 1; break; case KEY_GET_CONV: xdr_argument = (xdrproc_t) xdr_keybuf; xdr_result = (xdrproc_t)xdr_cryptkeyres; - local = (char *(*)()) key_get_conv_2_svc_prog; + local = (svc_cb *)key_get_conv_2_svc_prog; check_auth = 1; break; @@ -738,9 +710,7 @@ keyprogram(rqstp, transp) } static int -root_auth(trans, rqstp) - SVCXPRT *trans; - struct svc_req *rqstp; +root_auth(SVCXPRT *trans, struct svc_req *rqstp) { uid_t uid; struct sockaddr *remote; @@ -782,7 +752,7 @@ root_auth(trans, rqstp) } static void -usage() +usage(void) { (void) fprintf(stderr, "usage: keyserv [-n] [-D] [-d] [-v] [-p path]\n"); diff --git a/usr.sbin/keyserv/setkey.c b/usr.sbin/keyserv/setkey.c index a11d04d4babe..d829e68937ef 100644 --- a/usr.sbin/keyserv/setkey.c +++ b/usr.sbin/keyserv/setkey.c @@ -72,7 +72,7 @@ static int nodefaultkeys = 0; * prohibit the nobody key on this machine k (the -d flag) */ void -pk_nodefaultkeys() +pk_nodefaultkeys(void) { nodefaultkeys = 1; } @@ -81,8 +81,7 @@ pk_nodefaultkeys() * Set the modulus for all our Diffie-Hellman operations */ void -setmodulus(modx) - char *modx; +setmodulus(char *modx) { MODULUS = mp_xtom(modx); } @@ -91,9 +90,7 @@ setmodulus(modx) * Set the secretkey key for this uid */ keystatus -pk_setkey(uid, skey) - uid_t uid; - keybuf skey; +pk_setkey(uid_t uid, keybuf skey) { if (!storesecretkey(uid, skey)) { return (KEY_SYSTEMERR); @@ -106,11 +103,7 @@ pk_setkey(uid, skey) * secret key associated with uid. */ keystatus -pk_encrypt(uid, remote_name, remote_key, key) - uid_t uid; - char *remote_name; - netobj *remote_key; - des_block *key; +pk_encrypt(uid_t uid, char *remote_name, netobj *remote_key, des_block *key) { return (pk_crypt(uid, remote_name, remote_key, key, DES_ENCRYPT)); } @@ -120,11 +113,7 @@ pk_encrypt(uid, remote_name, remote_key, key) * secret key associated with uid. */ keystatus -pk_decrypt(uid, remote_name, remote_key, key) - uid_t uid; - char *remote_name; - netobj *remote_key; - des_block *key; +pk_decrypt(uid_t uid, char *remote_name, netobj *remote_key, des_block *key) { return (pk_crypt(uid, remote_name, remote_key, key, DES_DECRYPT)); } @@ -133,9 +122,7 @@ static int store_netname( uid_t, key_netstarg * ); static int fetch_netname( uid_t, key_netstarg * ); keystatus -pk_netput(uid, netstore) - uid_t uid; - key_netstarg *netstore; +pk_netput(uid_t uid, key_netstarg *netstore) { if (!store_netname(uid, netstore)) { return (KEY_SYSTEMERR); @@ -144,9 +131,7 @@ pk_netput(uid, netstore) } keystatus -pk_netget(uid, netstore) - uid_t uid; - key_netstarg *netstore; +pk_netget(uid_t uid, key_netstarg *netstore) { if (!fetch_netname(uid, netstore)) { return (KEY_SYSTEMERR); @@ -159,12 +144,8 @@ pk_netget(uid, netstore) * Do the work of pk_encrypt && pk_decrypt */ static keystatus -pk_crypt(uid, remote_name, remote_key, key, mode) - uid_t uid; - char *remote_name; - netobj *remote_key; - des_block *key; - int mode; +pk_crypt(uid_t uid, char *remote_name, netobj *remote_key, des_block *key, + int mode) { char *xsecret; char xpublic[1024]; @@ -221,10 +202,7 @@ pk_crypt(uid, remote_name, remote_key, key, mode) } keystatus -pk_get_conv_key(uid, xpublic, result) - uid_t uid; - keybuf xpublic; - cryptkeyres *result; +pk_get_conv_key(uid_t uid, keybuf xpublic, cryptkeyres *result) { char *xsecret; char xsecret_hold[1024]; @@ -271,9 +249,7 @@ pk_get_conv_key(uid, xpublic, result) * overwriting the lower order bits by setting parity. */ static void -extractdeskey(ck, deskey) - MINT *ck; - des_block *deskey; +extractdeskey(MINT *ck, des_block *deskey) { MINT *a; short r; @@ -320,9 +296,7 @@ static struct secretkey_netname_list *g_secretkey_netname; * Store the keys and netname for this uid */ static int -store_netname(uid, netstore) - uid_t uid; - key_netstarg *netstore; +store_netname(uid_t uid, key_netstarg *netstore) { struct secretkey_netname_list *new; struct secretkey_netname_list **l; @@ -361,9 +335,7 @@ store_netname(uid, netstore) */ static int -fetch_netname(uid, key_netst) - uid_t uid; - struct key_netstarg *key_netst; +fetch_netname(uid_t uid, struct key_netstarg *key_netst) { struct secretkey_netname_list *l; @@ -389,8 +361,7 @@ fetch_netname(uid, key_netst) } static char * -fetchsecretkey(uid) - uid_t uid; +fetchsecretkey(uid_t uid) { struct secretkey_netname_list *l; @@ -406,9 +377,7 @@ fetchsecretkey(uid) * Store the secretkey for this uid */ static int -storesecretkey(uid, key) - uid_t uid; - keybuf key; +storesecretkey(uid_t uid, keybuf key) { struct secretkey_netname_list *new; struct secretkey_netname_list **l; @@ -437,17 +406,13 @@ storesecretkey(uid, key) } static int -hexdigit(val) - int val; +hexdigit(int val) { return ("0123456789abcdef"[val]); } void -bin2hex(bin, hex, size) - unsigned char *bin; - unsigned char *hex; - int size; +bin2hex(unsigned char *bin, unsigned char *hex, int size) { int i; @@ -458,8 +423,7 @@ bin2hex(bin, hex, size) } static int -hexval(dig) - char dig; +hexval(char dig) { if ('0' <= dig && dig <= '9') { return (dig - '0'); @@ -473,10 +437,7 @@ hexval(dig) } void -hex2bin(hex, bin, size) - unsigned char *hex; - unsigned char *bin; - int size; +hex2bin(unsigned char *hex, unsigned char *bin, int size) { int i; @@ -501,10 +462,7 @@ static struct cachekey_list *g_cachedkeys; * cache result of expensive multiple precision exponential operation */ static void -writecache(pub, sec, deskey) - char *pub; - char *sec; - des_block *deskey; +writecache(char *pub, char *sec, des_block *deskey) { struct cachekey_list *new; @@ -523,10 +481,7 @@ writecache(pub, sec, deskey) * Try to find the common key in the cache */ static int -readcache(pub, sec, deskey) - char *pub; - char *sec; - des_block *deskey; +readcache(char *pub, char *sec, des_block *deskey) { struct cachekey_list *found; register struct cachekey_list **l;