diff options
author | Artur Grabowski <art@cvs.openbsd.org> | 1997-12-15 17:56:27 +0000 |
---|---|---|
committer | Artur Grabowski <art@cvs.openbsd.org> | 1997-12-15 17:56:27 +0000 |
commit | 25c94af0a2af23c8819b403339139ef6830411e3 (patch) | |
tree | 246f15545816d748649c2ddea2abe6c37f7af0a8 /kerberosIV | |
parent | 30f07e43453293dd26c2959326bb99a7afc0020e (diff) |
Upgrades, sanity checks, cleanup, etc.
Diffstat (limited to 'kerberosIV')
-rw-r--r-- | kerberosIV/Makefile | 8 | ||||
-rw-r--r-- | kerberosIV/include/kadm_locl.h | 93 | ||||
-rw-r--r-- | kerberosIV/include/kerberosIV/site.h | 3 | ||||
-rw-r--r-- | kerberosIV/include/ksrvutil.h | 53 | ||||
-rw-r--r-- | kerberosIV/include/pw_check.h | 44 | ||||
-rw-r--r-- | kerberosIV/include/sl.h | 60 | ||||
-rw-r--r-- | kerberosIV/include/sl_locl.h | 48 | ||||
-rw-r--r-- | kerberosIV/kadm/kadm_cli_wrap.c | 13 | ||||
-rw-r--r-- | kerberosIV/kadm/kadm_local.h | 32 | ||||
-rw-r--r-- | kerberosIV/kadmin/Makefile | 12 | ||||
-rw-r--r-- | kerberosIV/kadmin/kadmin.c | 698 | ||||
-rw-r--r-- | kerberosIV/kadmin/kadmin_cmds.ct | 52 | ||||
-rw-r--r-- | kerberosIV/kadmin/new_pwd.c | 146 | ||||
-rw-r--r-- | kerberosIV/kadmind/Makefile | 4 | ||||
-rw-r--r-- | kerberosIV/kadmind/admin_server.c | 254 | ||||
-rw-r--r-- | kerberosIV/kadmind/kadm_funcs.c | 669 | ||||
-rw-r--r-- | kerberosIV/kadmind/kadm_ser_wrap.c | 122 | ||||
-rw-r--r-- | kerberosIV/kadmind/kadm_server.c | 139 | ||||
-rw-r--r-- | kerberosIV/kadmind/pw_check.c | 88 | ||||
-rw-r--r-- | kerberosIV/kdb/krb_cache.c | 8 | ||||
-rw-r--r-- | kerberosIV/krb/kntoln.c | 4 | ||||
-rw-r--r-- | kerberosIV/sl/Makefile | 8 | ||||
-rw-r--r-- | kerberosIV/sl/sl.c | 200 |
23 files changed, 1776 insertions, 982 deletions
diff --git a/kerberosIV/Makefile b/kerberosIV/Makefile index 2868f4cc819..5d5eebf7b71 100644 --- a/kerberosIV/Makefile +++ b/kerberosIV/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.11 1997/11/28 12:48:37 art Exp $ +# $OpenBSD: Makefile,v 1.12 1997/12/15 17:56:12 art Exp $ # from @(#)Makefile 5.1 (Berkeley) 6/25/90 SUBDIR= @@ -7,14 +7,12 @@ SUBDIR= SUBDIR+=include .endif -SUBDIR+=acl krb kadm kafs kdb +SUBDIR+=acl krb kadm kafs kdb sl -SUBDIR+=ext_srvtab kadmin kdb_destroy kdb_edit kdb_init kdb_util \ +SUBDIR+=ext_srvtab kadmin kadmind kdb_destroy kdb_edit kdb_init kdb_util \ kdestroy kerberos kinit klist kprop kpropd ksrvtgt ksrvutil \ kstash make_keypair register registerd -#removed: kpasswdd kadmind - SUBDIR+=man build: diff --git a/kerberosIV/include/kadm_locl.h b/kerberosIV/include/kadm_locl.h index efabd709945..bd5193a5bab 100644 --- a/kerberosIV/include/kadm_locl.h +++ b/kerberosIV/include/kadm_locl.h @@ -1,27 +1,46 @@ -/* $Id: kadm_locl.h,v 1.3 1997/06/29 10:48:34 provos Exp $ */ - -/*- - * Copyright 1987, 1988 by the Student Information Processing Board - * of the Massachusetts Institute of Technology - * - * Permission to use, copy, modify, and distribute this software - * and its documentation for any purpose and without fee is - * hereby granted, provided that the above copyright notice - * appear in all copies and that both that copyright notice and - * this permission notice appear in supporting documentation, - * and that the names of M.I.T. and the M.I.T. S.I.P.B. not be - * used in advertising or publicity pertaining to distribution - * of the software without specific, written prior permission. - * M.I.T. and the M.I.T. S.I.P.B. make no representations about - * the suitability of this software for any purpose. It is - * provided "as is" without express or implied warranty. +/* $KTH: kadm_locl.h,v 1.26 1997/09/02 18:13:26 assar Exp $ */ + +/* + * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ -#include <sys/cdefs.h> -#include "kerberosIV/site.h" - #include <stdio.h> #include <stdlib.h> +#include <ctype.h> #include <string.h> #include <sys/types.h> @@ -30,12 +49,14 @@ #include <time.h> #include <sys/stat.h> +#include <sys/select.h> #include <fcntl.h> #include <errno.h> #include <signal.h> #include <unistd.h> +#include <sys/resource.h> #include <sys/wait.h> #include <pwd.h> @@ -45,18 +66,26 @@ #include <syslog.h> -#include "kerberosIV/com_err.h" -#include <ss/ss.h> +#include <err.h> + +#include <com_err.h> +#include <sl.h> #include <des.h> #include <kerberosIV/krb.h> -#include <kerberosIV/krb_err.h> +#include <krb_err.h> #include <kerberosIV/krb_db.h> #include <kerberosIV/kadm.h> -#include <kerberosIV/kadm_err.h> -#include "kerberosIV/acl.h" +#include <kadm_err.h> +#include <kerberosIV/acl.h> + +#include <krb_log.h> #include "kadm_server.h" +#include "pw_check.h" + +/* from libacl */ +/* int acl_check(char *acl, char *principal); */ /* GLOBALS */ extern char *acldir; @@ -67,20 +96,16 @@ int kadm_change __P((char *, char *, char *, des_cblock)); int kadm_add_entry __P((char *, char *, char *, Kadm_vals *, Kadm_vals *)); int kadm_mod_entry __P((char *, char *, char *, Kadm_vals *, Kadm_vals *, Kadm_vals *)); int kadm_get_entry __P((char *, char *, char *, Kadm_vals *, u_char *, Kadm_vals *)); +int kadm_delete_entry __P((char *, char *, char *, Kadm_vals *)); int kadm_ser_cpw __P((u_char *, int, AUTH_DAT *, u_char **, int *)); int kadm_ser_add __P((u_char *, int, AUTH_DAT *, u_char **, int *)); int kadm_ser_mod __P((u_char *, int, AUTH_DAT *, u_char **, int *)); int kadm_ser_get __P((u_char *, int, AUTH_DAT *, u_char **, int *)); +int kadm_ser_delete __P((u_char *, int, AUTH_DAT *, u_char **, int *)); int kadm_ser_init __P((int inter, char realm[])); int kadm_ser_in __P((u_char **, int *)); -long maketime __P((struct tm *, int)); +int get_pw_new_pwd __P((char *pword, int pwlen, krb_principal *pr, int print_realm)); -void change_password __P((int argc, char *argv[])); -void change_admin_password __P((int argc, char *argv[])); -void add_new_key __P((int argc, char *argv[])); -void get_entry __P((int argc, char *argv[])); -void mod_entry __P((int argc, char *argv[])); -void help __P((int argc, char *argv[])); -void clean_up __P((void)); -void quit __P((void)); +/* cracklib */ +char *FascistCheck __P((char *password, char *path, char **strings)); diff --git a/kerberosIV/include/kerberosIV/site.h b/kerberosIV/include/kerberosIV/site.h index 834777a19b3..4af53a30172 100644 --- a/kerberosIV/include/kerberosIV/site.h +++ b/kerberosIV/include/kerberosIV/site.h @@ -1,4 +1,4 @@ -/* $Id: site.h,v 1.3 1996/01/29 19:18:40 tholo Exp $ */ +/* $Id: site.h,v 1.4 1997/12/15 17:56:16 art Exp $ */ /* * Site-specific definitions. @@ -31,6 +31,7 @@ #define ADD_ACL_FILE "admin_acl.add" #define GET_ACL_FILE "admin_acl.get" #define MOD_ACL_FILE "admin_acl.mod" +#define DEL_ACL_FILE "admin_acl.del" /* * Set ORGANIZATION to be the desired organization string printed diff --git a/kerberosIV/include/ksrvutil.h b/kerberosIV/include/ksrvutil.h new file mode 100644 index 00000000000..674692ce551 --- /dev/null +++ b/kerberosIV/include/ksrvutil.h @@ -0,0 +1,53 @@ +/* $OpenBSD: ksrvutil.h,v 1.1 1997/12/15 17:56:14 art Exp $ */ +/* $KTH: ksrvutil.h,v 1.8 1997/04/01 03:58:55 assar Exp $ */ + +/* + * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + +extern char u_name[], u_inst[], u_realm[]; +extern int destroyp; + +void leave(char *str, int x); +void safe_read_stdin(char *prompt, char *buf, size_t size); +void safe_write(char *filename, int fd, void *buf, size_t len); + +int yn(char *string); +int ny(char *string); + +void ksrvutil_get(int fd, char *filename, int argc, char **argv); diff --git a/kerberosIV/include/pw_check.h b/kerberosIV/include/pw_check.h new file mode 100644 index 00000000000..c2fa873fbec --- /dev/null +++ b/kerberosIV/include/pw_check.h @@ -0,0 +1,44 @@ +/* $OpenBSD: pw_check.h,v 1.1 1997/12/15 17:56:14 art Exp $ */ +/* $KTH: pw_check.h,v 1.6 1997/04/01 08:17:50 joda Exp $ */ + +/* + * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +int kadm_pw_check(char *pw, des_cblock *newkey, + char **pw_msg, char **strings); + diff --git a/kerberosIV/include/sl.h b/kerberosIV/include/sl.h new file mode 100644 index 00000000000..5c9d7c3f1b3 --- /dev/null +++ b/kerberosIV/include/sl.h @@ -0,0 +1,60 @@ +/* $KTH: sl.h,v 1.4 1997/08/15 21:40:10 joda Exp $ */ + +/* + * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _SL_H +#define _SL_H + +typedef int (*cmd_func)(int, char **); + +struct sl_cmd { + char *name; + cmd_func func; + char *usage; + char *help; +}; + +typedef struct sl_cmd SL_cmd; + +void sl_help (SL_cmd *, int argc, char **argv); +int sl_loop (SL_cmd *, char *prompt); +int sl_command (SL_cmd *cmds, int argc, char **argv); + + +#endif /* _SL_H */ diff --git a/kerberosIV/include/sl_locl.h b/kerberosIV/include/sl_locl.h new file mode 100644 index 00000000000..99c9b0f4365 --- /dev/null +++ b/kerberosIV/include/sl_locl.h @@ -0,0 +1,48 @@ +/* $KTH: sl_locl.h,v 1.4 1997/06/08 01:51:38 assar Exp $ */ + +/* + * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <sl.h> + +#include <kerberosIV/krb.h> /* this wouldn't be necessary if strtok_r was + somewhere else. */ diff --git a/kerberosIV/kadm/kadm_cli_wrap.c b/kerberosIV/kadm/kadm_cli_wrap.c index a470fab7c4f..d76f50a620e 100644 --- a/kerberosIV/kadm/kadm_cli_wrap.c +++ b/kerberosIV/kadm/kadm_cli_wrap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kadm_cli_wrap.c,v 1.4 1997/12/12 10:48:17 art Exp $ */ +/* $OpenBSD: kadm_cli_wrap.c,v 1.5 1997/12/15 17:56:17 art Exp $ */ /* $KTH: kadm_cli_wrap.c,v 1.22 1997/08/17 07:30:04 assar Exp $ */ /* @@ -39,7 +39,7 @@ or implied warranty. static Kadm_Client client_parm; /* Macros for use in returning data... used in kadm_cli_send */ -#define RET_N_FREE(r) {clear_secrets(); free((char *)act_st); free((char *)priv_pak); return r;} +#define RET_N_FREE(r) {clear_secrets(); free((char *)act_st); act_st = NULL; free((char *)priv_pak); priv_pak = NULL; return r;} /* Keys for use in the transactions */ static des_cblock sess_key; /* to be filled in by kadm_cli_keyd */ @@ -81,7 +81,7 @@ kadm_init_link(char *n, char *i, char *r) strncpy(client_parm.sname, n, ANAME_SZ - 1); client_parm.sname[ANAME_SZ - 1] = '\0'; strncpy(client_parm.sinst, i, INST_SZ - 1); - client_parm.sname[ANAME_SZ - 1] = '\0'; + client_parm.sinst[INST_SZ - 1] = '\0'; strncpy(client_parm.krbrlm, r, REALM_SZ - 1); client_parm.krbrlm[REALM_SZ - 1] = '\0'; client_parm.admin_fd = -1; @@ -251,8 +251,7 @@ kadm_cli_send(u_char *st_dat, int st_siz, u_char **ret_dat, int *ret_siz) return KADM_NOMEM; } - strncpy((char *)act_st, KADM_VERSTR, KADM_VERSIZE - 1); - act_st[KADM_VERSIZE - 1] = '\0'; + strncpy((char *)act_st, KADM_VERSTR, KADM_VERSIZE); act_len = KADM_VERSIZE; if ((retdat = kadm_cli_keyd(&sess_key, sess_sched)) != KADM_SUCCESS) { @@ -313,7 +312,7 @@ kadm_cli_send(u_char *st_dat, int st_siz, u_char **ret_dat, int *ret_siz) RET_N_FREE(retdat); free(act_st); act_st = NULL; -#define RET_N_FREE2(r) {free(*ret_dat); clear_secrets(); return(r);} +#define RET_N_FREE2(r) {free(*ret_dat); *ret_dat = NULL; clear_secrets(); return(r);} /* first see if it's a YOULOUSE */ if ((*ret_siz >= KADM_VERSIZE) && @@ -351,7 +350,7 @@ kadm_cli_send(u_char *st_dat, int st_siz, u_char **ret_dat, int *ret_siz) (char *) mdat.app_data + KADM_VERSIZE + 4, mdat.app_length - KADM_VERSIZE - 4); free(*ret_dat); - ret_dat = NULL; + *ret_dat = NULL; clear_secrets(); *ret_dat = return_dat; *ret_siz = mdat.app_length - KADM_VERSIZE - 4; diff --git a/kerberosIV/kadm/kadm_local.h b/kerberosIV/kadm/kadm_local.h deleted file mode 100644 index 829f43c5444..00000000000 --- a/kerberosIV/kadm/kadm_local.h +++ /dev/null @@ -1,32 +0,0 @@ -/* $Id: kadm_local.h,v 1.3 1997/12/01 04:46:59 art Exp $ */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <signal.h> -#include <time.h> -#include <errno.h> - -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/param.h> -#include <netinet/in.h> -#include <netdb.h> - -#include <des.h> -#include <kerberosIV/krb.h> -#include "krb_err.h" -#include <kerberosIV/krb_db.h> -#include <kerberosIV/kadm.h> -#include "kadm_err.h" - -int vts_long __P((u_int32_t, u_char **, int)); -int vals_to_stream __P((Kadm_vals *, u_char **)); -int stream_to_vals __P((u_char *, Kadm_vals *, int)); - -int kadm_init_link __P((char n[], char i[], char r[])); -int kadm_change_pw __P((des_cblock)); -int kadm_add __P((Kadm_vals *)); -int kadm_mod __P((Kadm_vals *, Kadm_vals *)); -int kadm_get __P((Kadm_vals *, u_char fl[4])); diff --git a/kerberosIV/kadmin/Makefile b/kerberosIV/kadmin/Makefile index 832f9bff04e..d750b8a6c32 100644 --- a/kerberosIV/kadmin/Makefile +++ b/kerberosIV/kadmin/Makefile @@ -1,9 +1,9 @@ -# $Id: Makefile,v 1.4 1997/02/11 04:40:37 tholo Exp $ +# $Id: Makefile,v 1.5 1997/12/15 17:56:18 art Exp $ .include <bsd.obj.mk> PROG= kadmin -SRCS= kadmin.c kadmin_cmds.c maketime.c +SRCS= kadmin.c new_pwd.c .PATH: ${.CURDIR}/../kdb_edit .if exists(${.CURDIR}/../kadm/${__objdir}) CFLAGS+=-I${.CURDIR}/../kadm/${__objdir} @@ -15,15 +15,9 @@ CFLAGS+=-I${.CURDIR}/../krb/${__objdir} .else CFLAGS+=-I${.CURDIR}/../krb .endif -CFLAGS+=-I${.CURDIR}/../../lib/libss -LDADD+= -lkadm -lkrb -ldes -lss -lcom_err +LDADD+= -lkadm -lkrb -ldes -lcom_err -lsl DPADD+= ${LIBKADM} ${LIBKRB} ${LIBDES} ${LIBSS} ${LIBCOM_ERR} CLEANFILES+= kadmin_cmds.c MAN= kadmin.8 -kadmin_cmds.c: kadmin_cmds.ct - test -e kadmin_cmds.ct || ln -s ${.CURDIR}/kadmin_cmds.ct . - mk_cmds kadmin_cmds.ct - -test -h kadmin_cmds.ct && rm kadmin_cmds.ct - .include <bsd.prog.mk> diff --git a/kerberosIV/kadmin/kadmin.c b/kerberosIV/kadmin/kadmin.c index 09e52f8e3f7..8a7aad5eaba 100644 --- a/kerberosIV/kadmin/kadmin.c +++ b/kerberosIV/kadmin/kadmin.c @@ -1,7 +1,7 @@ -/* $Id: kadmin.c,v 1.5 1997/02/19 09:03:40 tholo Exp $ */ +/* $KTH: kadmin.c,v 1.50 1997/11/03 19:51:46 assar Exp $ */ /* - * Copyright (C) 1989 by the Massachusetts Institute of Technology + * Copyright (C) 1989 by the Massachusetts Institute of Technology * * Export of this software from the United States of America is assumed * to require a specific license from the United States Government. @@ -18,6 +18,7 @@ * permission. M.I.T. makes no representations about the suitability of * this software for any purpose. It is provided "as is" without express * or implied warranty. + * */ /* @@ -26,12 +27,44 @@ * The default behavior of kadmin is if the -m option is given * on the commandline, multiple requests are allowed to be given * with one entry of the admin password (until the tickets expire). - * If you do not want this to be an available option, compile with - * NO_MULTIPLE defined. */ -#include <kadm_locl.h> -#include <sys/param.h> +#include "kadm_locl.h" + +static int change_password(int argc, char **argv); +static int change_key(int argc, char **argv); +static int change_admin_password(int argc, char **argv); +static int add_new_key(int argc, char **argv); +static int del_entry(int argc, char **argv); +static int get_entry(int argc, char **argv); +static int mod_entry(int argc, char **argv); +static int help(int argc, char **argv); +static int clean_up_cmd(int argc, char **argv); +static int quit_cmd(int argc, char **argv); + +static SL_cmd cmds[] = { + {"change_password", change_password, "Change a user's password"}, + {"cpw"}, + {"passwd"}, + {"change_key", change_key, "Change a user's password as a DES binary key"}, + {"ckey"}, + {"change_admin_password", change_admin_password, + "Change your admin password"}, + {"cap"}, + {"add_new_key", add_new_key, "Add new user to kerberos database"}, + {"ank"}, + {"del_entry", del_entry, "Delete entry from database"}, + {"del"}, + {"delete"}, + {"get_entry", get_entry, "Get entry from kerberos database"}, + {"mod_entry", mod_entry, "Modify entry in kerberos database"}, + {"destroy_tickets", clean_up_cmd, "Destroy admin tickets"}, + {"exit", quit_cmd, "Exit program"}, + {"quit"}, + {"help", help, "Help"}, + {"?"}, + {NULL} +}; #define BAD_PW 1 #define GOOD_PW 0 @@ -45,9 +78,7 @@ #define DONTSWAP 0 #define SWAP 1 -extern ss_request_table admin_cmds; - -static char myname[ANAME_SZ]; +static krb_principal pr; static char default_realm[REALM_SZ]; /* default kerberos realm */ static char krbrlm[REALM_SZ]; /* current realm being administered */ static int multiple = 0; /* Allow multiple requests per ticket */ @@ -58,6 +89,20 @@ static int multiple = 0; /* Allow multiple requests per ticket */ #define read_long_pw_string des_read_pw_string #endif +time_t +tm2time (struct tm tm, int local) +{ + time_t t; + + tm.tm_isdst = -1; + + t = mktime (&tm); + + if (!local) + t += t - mktime (gmtime (&t)); + return t; +} + static void get_maxlife(Kadm_vals *vals) { @@ -112,10 +157,9 @@ static void get_expdate(Kadm_vals *vals) { char buff[BUFSIZ]; - time_t when; struct tm edate; - bzero(&edate, sizeof(edate)); + memset(&edate, 0, sizeof(edate)); do { printf("Expiration date (enter yyyy-mm-dd) ? [%.24s] ", asctime(k_localtime(&vals->exp_date))); @@ -129,11 +173,11 @@ get_expdate(Kadm_vals *vals) edate.tm_mon--; /* January is 0, not 1 */ edate.tm_hour = 23; /* nearly midnight at the end of the */ edate.tm_min = 59; /* specified day */ - when = maketime(&edate, 1); } - } while (when <= 0); + } while (krb_check_tm (edate)); - vals->exp_date = when; + edate.tm_year -= 1900; + vals->exp_date = tm2time (edate, 1); SET_FIELD(KADM_EXPDATE,vals->fields); } @@ -142,7 +186,11 @@ princ_exists(char *name, char *instance, char *realm) { int status; - status = krb_get_pw_in_tkt(name, instance, realm, "krbtgt", realm, 1, ""); + int old = krb_use_admin_server(1); + status = krb_get_pw_in_tkt(name, instance, realm, + KRB_TICKET_GRANTING_TICKET, + realm, 1, ""); + krb_use_admin_server(old); if ((status == KSUCCESS) || (status == INTK_BADPW)) return(PE_YES); @@ -163,23 +211,23 @@ get_password(u_int32_t *low, u_int32_t *high, char *prompt, int byteswap) if (strlen(new_passwd) == 0) { printf("Using random password.\n"); #ifdef NOENCRYPTION - bzero((char *) newkey, sizeof(newkey)); + memset(newkey, 0, sizeof(newkey)); #else des_new_random_key(&newkey); #endif } else { #ifdef NOENCRYPTION - bzero((char *) newkey, sizeof(newkey)); + memset(newkey, 0, sizeof(newkey)); #else des_string_to_key(new_passwd, &newkey); #endif - bzero(new_passwd, sizeof(new_passwd)); + memset(new_passwd, 0, sizeof(new_passwd)); } - bcopy((char *) newkey,(char *)low,4); - bcopy((char *)(((int32_t *) newkey) + 1), (char *)high,4); + memcpy(low, newkey, 4); + memcpy(high, ((char *)newkey) + 4, 4); - bzero((char *) newkey, sizeof(newkey)); + memset(newkey, 0, sizeof(newkey)); #ifdef NOENCRYPTION *low = 1; @@ -202,7 +250,7 @@ get_admin_password(void) if (multiple) { /* If admin tickets exist and are valid, just exit. */ - bzero(&c, sizeof(c)); + memset(&c, 0, sizeof(c)); if (krb_get_cred(PWSERV_NAME, KADM_SINST, krbrlm, &c) == KSUCCESS) /* * If time is less than lifetime - FUDGE_VALUE after issue date, @@ -214,18 +262,22 @@ get_admin_password(void) ticket_life = DEFAULT_TKT_LIFE; } - if (princ_exists(myname, "admin", krbrlm) != PE_NO) { - if (read_long_pw_string(admin_passwd, sizeof(admin_passwd)-1, - "Admin password:", 0)) { - fprintf(stderr, "Error reading admin password.\n"); + if (princ_exists(pr.name, pr.instance, pr.realm) != PE_NO) { + char prompt[256]; + snprintf(prompt, sizeof(prompt), "%s's Password: ", krb_unparse_name(&pr)); + if (read_long_pw_string(admin_passwd, + sizeof(admin_passwd)-1, + prompt, 0)) { + warnx ("Error reading admin password."); goto bad; } - status = krb_get_pw_in_tkt(myname, "admin", krbrlm, PWSERV_NAME, - KADM_SINST, ticket_life, admin_passwd); - bzero(admin_passwd, sizeof(admin_passwd)); + status = krb_get_pw_in_tkt(pr.name, pr.instance, pr.realm, + PWSERV_NAME, KADM_SINST, + ticket_life, admin_passwd); + memset(admin_passwd, 0, sizeof(admin_passwd)); /* Initialize non shared random sequence from session key. */ - bzero(&c, sizeof(c)); + memset(&c, 0, sizeof(c)); krb_get_cred(PWSERV_NAME, KADM_SINST, krbrlm, &c); des_init_random_number_generator(&c.session); } @@ -236,7 +288,7 @@ get_admin_password(void) case GT_PW_OK: return(GOOD_PW); case KDC_PR_UNKNOWN: - printf("Principal %s.admin@%s does not exist.\n", myname, krbrlm); + printf("Principal %s does not exist.\n", krb_unparse_name(&pr)); goto bad; case GT_PW_BADPW: printf("Incorrect admin password.\n"); @@ -248,125 +300,108 @@ get_admin_password(void) } bad: - bzero(admin_passwd, sizeof(admin_passwd)); - (void) dest_tkt(); + memset(admin_passwd, 0, sizeof(admin_passwd)); + dest_tkt(); return(BAD_PW); } static void usage(void) { - fprintf(stderr, "Usage: kadmin [-u admin_name] [-r default_realm]"); - fprintf(stderr, " [-m]"); - fprintf(stderr, "\n"); - fprintf(stderr, " -m allows multiple admin requests to be "); - fprintf(stderr, "serviced with one entry of admin\n"); - fprintf(stderr, " password.\n"); - exit(1); + fprintf (stderr, "Usage: kadmin [[-u|-p] admin_name] [-r default_realm]" + " [-m]\n" + " -m allows multiple admin requests to be " + "serviced with one entry of admin\n" + " password.\n"); + exit (1); } /* GLOBAL */ -void -clean_up(void) +static void +clean_up() { - (void) dest_tkt(); - return; + dest_tkt(); } -/* GLOBAL */ -void -quit(void) +static int +clean_up_cmd (int argc, char **argv) { - printf("Cleaning up and exiting.\n"); clean_up(); - exit(0); + return 0; } -static int inited = 0; +static int +quit_cmd (int argc, char **argv) +{ + return 1; +} static void do_init(int argc, char **argv) { - struct passwd *pw; int c; -#define OPTION_STRING "u:r:m" + int tflag = 0; + char tktstring[MAXPATHLEN]; + int k_errno; - bzero(myname, sizeof(myname)); - - if (!inited) { - /* - * This is only as a default/initial realm; we don't care - * about failure. - */ - if (krb_get_lrealm(default_realm, 1) != KSUCCESS) { - fprintf(stderr, - "Could not determine local realm name.\n"); - } - - /* - * If we can reach the local realm, initialize to it. Otherwise, - * don't initialize. - */ - if (kadm_init_link(PWSERV_NAME, KADM_SINST, default_realm) != KADM_SUCCESS) - bzero(krbrlm, sizeof(krbrlm)); - else - strcpy(krbrlm, default_realm); - - while ((c = getopt(argc, argv, OPTION_STRING)) != -1) - switch (c) { - case 'u': - strncpy(myname, optarg, sizeof(myname) - 1); - break; - case 'r': - bzero(default_realm, sizeof(default_realm)); - strncpy(default_realm, optarg, sizeof(default_realm) - 1); - break; - case 'm': - multiple++; - break; - default: - usage(); - break; - } - if (optind < argc) + memset(&pr, 0, sizeof(pr)); + if (krb_get_default_principal(pr.name, pr.instance, default_realm) < 0) + errx (1, "I could not even guess who you might be"); + while ((c = getopt(argc, argv, "p:u:r:mt")) != EOF) + switch (c) { + case 'p': + case 'u': + if((k_errno = krb_parse_name(optarg, &pr)) != KSUCCESS) + errx (1, "%s", krb_get_err_text(k_errno)); + break; + case 'r': + memset(default_realm, 0, sizeof(default_realm)); + strncpy(default_realm, optarg, sizeof(default_realm) - 1); + break; + case 'm': + multiple++; + break; + case 't': + tflag++; + break; + default: usage(); - if (!myname[0]) { - pw = getpwuid((int) getuid()); - if (!pw) { - fprintf(stderr, - "You aren't in the password file. Who are you?\n"); - exit(1); - } - (void) strcpy(myname, pw->pw_name); + break; } - inited = 1; + if (optind < argc) + usage(); + + strncpy(krbrlm, default_realm, REALM_SZ - 1); + krbrlm[REALM_SZ - 1] = '\0'; + + if (kadm_init_link(PWSERV_NAME, KRB_MASTER, krbrlm) != KADM_SUCCESS) + krbrlm[0] = '\0'; + if (pr.realm[0] == '\0') { + strncpy (pr.realm, krbrlm, REALM_SZ - 1); + pr.realm[REALM_SZ - 1] = '\0'; + } + if (pr.instance[0] == '\0') { + strncpy(pr.instance, "admin", INST_SZ - 1); + pr.instance[INST_SZ - 1] = '\0'; } + + if (!tflag) { + snprintf(tktstring, sizeof(tktstring), TKT_ROOT "_adm_%d",(int)getpid()); + krb_set_tkt_string(tktstring); + } + } int main(int argc, char **argv) { - int sci_idx; - int code; - char tktstring[MAXPATHLEN]; - - sci_idx = ss_create_invocation("admin", "2.0", (char *) NULL, - &admin_cmds, &code); - if (code) { - ss_perror(sci_idx, code, "creating invocation"); - exit(1); - } - (void) snprintf(tktstring, sizeof(tktstring), "/tmp/tkt_adm_%d", - (int)getpid()); - krb_set_tkt_string(tktstring); - do_init(argc, argv); printf("Welcome to the Kerberos Administration Program, version 2\n"); printf("Type \"help\" if you need it.\n"); - code = ss_listen(sci_idx); - printf("\n"); - quit(); + sl_loop (cmds, "kadmin: "); + printf("\nCleaning up and exiting.\n"); + clean_up(); exit(0); } @@ -376,20 +411,23 @@ setvals(Kadm_vals *vals, char *string) char realm[REALM_SZ]; int status = KADM_SUCCESS; - bzero(vals, sizeof(*vals)); - bzero(realm, sizeof(realm)); + memset(vals, 0, sizeof(*vals)); + memset(realm, 0, sizeof(realm)); SET_FIELD(KADM_NAME,vals->fields); SET_FIELD(KADM_INST,vals->fields); if ((status = kname_parse(vals->name, vals->instance, realm, string))) { - printf("kerberos error: %s\n", krb_err_txt[status]); + printf("kerberos error: %s\n", krb_get_err_text(status)); return status; } - if (!realm[0]) - strcpy(realm, default_realm); + if (realm[0] == '\0') { + strncpy(realm, default_realm, REALM_SZ - 1); + realm[REALM_SZ - 1] = '\0'; + } if (strcmp(realm, krbrlm)) { - strcpy(krbrlm, realm); - if ((status = kadm_init_link(PWSERV_NAME, KADM_SINST, krbrlm)) + strncpy(krbrlm, realm, REALM_SZ - 1); + krbrlm[REALM_SZ - 1] = '\0'; + if ((status = kadm_init_link(PWSERV_NAME, KRB_MASTER, krbrlm)) != KADM_SUCCESS) printf("kadm error for realm %s: %s\n", krbrlm, error_message(status)); @@ -400,7 +438,7 @@ setvals(Kadm_vals *vals, char *string) return KADM_SUCCESS; } -void +static int change_password(int argc, char **argv) { Kadm_vals old, new; @@ -409,11 +447,11 @@ change_password(int argc, char **argv) if (argc != 2) { printf("Usage: change_password loginname\n"); - return; + return 0; } if (setvals(&old, argv[1]) != KADM_SUCCESS) - return; + return 0; new = old; @@ -422,11 +460,10 @@ change_password(int argc, char **argv) if (princ_exists(old.name, old.instance, krbrlm) != PE_NO) { /* get the admin's password */ if (get_admin_password() != GOOD_PW) - return; + return 0; /* get the new password */ - (void) snprintf(pw_prompt, sizeof(pw_prompt), "New password for %s:", - argv[1]); + snprintf(pw_prompt, sizeof(pw_prompt), "New password for %s:", argv[1]); if (get_password(&new.key_low, &new.key_high, pw_prompt, SWAP) == GOOD_PW) { @@ -439,51 +476,139 @@ change_password(int argc, char **argv) } } else printf("Error reading password; password unchanged\n"); - bzero((char *)&new, sizeof(new)); + memset(&new, 0, sizeof(new)); + if (!multiple) + clean_up(); + } + else + printf("kadmin: Principal %s does not exist.\n", + krb_unparse_name_long (old.name, old.instance, krbrlm)); + return 0; +} + +static int +getkey(unsigned char *k) +{ + int i, c; + for (i = 0; i < 8; i++) + { + c = getchar(); + if (c == EOF) + return 0; + else if (c == '\\') + { + int oct = -1; + scanf("%03o", &oct); + if (oct < 0 || oct > 255) + return 0; + k[i] = oct; + } + else if (!isalpha(c)) + return 0; + else + k[i] = c; + } + c = getchar(); + if (c != '\n') + return 0; + return 1; /* Success */ +} + +static void +printkey(unsigned char *tkey) +{ + int j; + for(j = 0; j < 8; j++) + if(tkey[j] != '\\' && isalpha(tkey[j]) != 0) + printf("%c", tkey[j]); + else + printf("\\%03o",(unsigned char)tkey[j]); + printf("\n"); +} + +static int +change_key(int argc, char **argv) +{ + Kadm_vals old, new; + unsigned char newkey[8]; + int status; + + if (argc != 2) { + printf("Usage: change_key principal-name\n"); + return 0; + } + + if (setvals(&old, argv[1]) != KADM_SUCCESS) + return 0; + + new = old; + + SET_FIELD(KADM_DESKEY,new.fields); + + if (princ_exists(old.name, old.instance, krbrlm) != PE_NO) { + /* get the admin's password */ + if (get_admin_password() != GOOD_PW) + return 0; + + /* get the new password */ + printf("New DES key for %s: ", argv[1]); + + if (getkey(newkey)) { + memcpy(&new.key_low, newkey, 4); + memcpy(&new.key_high, ((char *)newkey) + 4, 4); + printf("Entered key for %s: ", argv[1]); + printkey(newkey); + memset(newkey, 0, sizeof(newkey)); + + status = kadm_mod(&old, &new); + if (status == KADM_SUCCESS) { + printf("Key changed for %s.\n", argv[1]); + } else { + printf("kadmin: %s\nwhile changing key for %s", + error_message(status), argv[1]); + } + } else + printf("Error reading key; key unchanged\n"); + memset(&new, 0, sizeof(new)); if (!multiple) clean_up(); } else - printf("kadmin: Principal does not exist.\n"); - return; + printf("kadmin: Principal %s does not exist.\n", + krb_unparse_name_long (old.name, old.instance, krbrlm)); + return 0; } -/*ARGSUSED*/ -void +static int change_admin_password(int argc, char **argv) { des_cblock newkey; - u_int32_t low, high; int status; - char prompt_pw[BUFSIZ]; + char pword[MAX_KPW_LEN]; + char *pw_msg; if (argc != 1) { printf("Usage: change_admin_password\n"); - return; + return 0; + } + if (get_pw_new_pwd(pword, sizeof(pword), &pr, 1) == 0) { + des_string_to_key(pword, &newkey); + status = kadm_change_pw_plain(newkey, pword, &pw_msg); + if(status == KADM_INSECURE_PW) + printf("Insecure password: %s\n", pw_msg); + else if (status == KADM_SUCCESS) + printf("Admin password changed\n"); + else + printf("kadm error: %s\n",error_message(status)); + memset(newkey, 0, sizeof(newkey)); + memset(pword, 0, sizeof(pword)); } - /* get the admin's password */ - if (get_admin_password() != GOOD_PW) - return; - - (void) snprintf(prompt_pw, sizeof(prompt_pw), "New password for %s.admin:", - myname); - if (get_password(&low, &high, prompt_pw, DONTSWAP) == GOOD_PW) { - bcopy((char *)&low,(char *) newkey,4); - bcopy((char *)&high, (char *)(((int32_t *) newkey) + 1),4); - low = high = 0L; - if ((status = kadm_change_pw(newkey)) == KADM_SUCCESS) - printf("Admin password changed\n"); - else - printf("kadm error: %s\n",error_message(status)); - bzero((char *)newkey, sizeof(newkey)); - } else - printf("Error reading password; password unchanged\n"); if (!multiple) clean_up(); - return; + return 0; } -void +static int add_new_key(int argc, char **argv) { Kadm_vals new; @@ -492,32 +617,71 @@ add_new_key(int argc, char **argv) if (argc != 2) { printf("Usage: add_new_key user_name.\n"); - return; + return 0; } if (setvals(&new, argv[1]) != KADM_SUCCESS) - return; + return 0; + SET_FIELD(KADM_EXPDATE,new.fields); + SET_FIELD(KADM_ATTR,new.fields); + SET_FIELD(KADM_MAXLIFE,new.fields); SET_FIELD(KADM_DESKEY,new.fields); if (princ_exists(new.name, new.instance, krbrlm) != PE_YES) { + Kadm_vals vals; + u_char fields[4]; + char n[ANAME_SZ + INST_SZ + 1]; + /* get the admin's password */ if (get_admin_password() != GOOD_PW) - return; + return 0; - /* This is the default maximum lifetime for new principals. */ - if (krb_life_to_time(0, 162) >= 24*60*60) - new.max_life = 162; /* ca 100 hours */ - else - new.max_life = 255; /* ca 21 hours (maximum) */ - new.exp_date = time(0) + 2*(365*24*60*60); /* + ca 2 years */ - new.attributes = 0; + memset(fields, 0, sizeof(fields)); + SET_FIELD(KADM_NAME,fields); + SET_FIELD(KADM_INST,fields); + SET_FIELD(KADM_EXPDATE,fields); + SET_FIELD(KADM_ATTR,fields); + SET_FIELD(KADM_MAXLIFE,fields); + snprintf (n, sizeof(n), "default.%s", new.instance); + if (setvals(&vals, n) != KADM_SUCCESS) + return 0; + + if (kadm_get(&vals, fields) != KADM_SUCCESS) { + if (setvals(&vals, "default") != KADM_SUCCESS) + return 0; + if ((status = kadm_get(&vals, fields)) != KADM_SUCCESS) { + printf ("kadm error: %s\n", error_message(status)); + return 0; + } + } + + if (vals.max_life == 255) /* Defaults not set! */ { + /* This is the default maximum lifetime for new principals. */ + if (strcmp(new.instance, "admin") == 0) + vals.max_life = 1 + (CLOCK_SKEW/(5*60)); /* 5+5 minutes */ + else if (strcmp(new.instance, "root") == 0) + vals.max_life = 96; /* 8 hours */ + else if (krb_life_to_time(0, 162) >= 24*60*60) + vals.max_life = 162; /* ca 100 hours */ + else + vals.max_life = 255; /* ca 21 hours (maximum) */ + + /* Also fix expiration date. */ + if (strcmp(new.name, "rcmd") == 0) + vals.exp_date = 1104814999; /* Tue Jan 4 06:03:19 2005 */ + else + vals.exp_date = time(0) + 2*(365*24*60*60); /* + ca 2 years */ + } + + new.max_life = vals.max_life; + new.exp_date = vals.exp_date; + new.attributes = vals.attributes; get_maxlife(&new); get_attr(&new); get_expdate(&new); /* get the new password */ - (void) snprintf(pw_prompt, sizeof(pw_prompt), "Password for %s:", - argv[1]); + snprintf(pw_prompt, sizeof(pw_prompt), "Password for %s:", argv[1]); if (get_password(&new.key_low, &new.key_high, pw_prompt, SWAP) == GOOD_PW) { @@ -529,16 +693,50 @@ add_new_key(int argc, char **argv) } } else printf("Error reading password; %s not added\n",argv[1]); - bzero((char *)&new, sizeof(new)); + memset(&new, 0, sizeof(new)); if (!multiple) clean_up(); } else printf("kadmin: Principal already exists.\n"); - return; + return 0; } -void +static int +del_entry(int argc, char **argv) +{ + int status; + Kadm_vals vals; + + if (argc != 2) { + printf("Usage: del_entry username\n"); + return 0; + } + + if (setvals(&vals, argv[1]) != KADM_SUCCESS) + return 0; + + if (princ_exists(vals.name, vals.instance, krbrlm) != PE_NO) { + /* get the admin's password */ + if (get_admin_password() != GOOD_PW) + return 0; + + if ((status = kadm_del(&vals)) == KADM_SUCCESS){ + printf("%s removed from database.\n", argv[1]); + } else { + printf("kadm error: %s\n",error_message(status)); + } + + if (!multiple) + clean_up(); + } + else + printf("kadmin: Principal %s does not exist.\n", + krb_unparse_name_long (vals.name, vals.instance, krbrlm)); + return 0; +} + +static int get_entry(int argc, char **argv) { int status; @@ -547,25 +745,28 @@ get_entry(int argc, char **argv) if (argc != 2) { printf("Usage: get_entry username\n"); - return; + return 0; } - bzero(fields, sizeof(fields)); + memset(fields, 0, sizeof(fields)); SET_FIELD(KADM_NAME,fields); SET_FIELD(KADM_INST,fields); SET_FIELD(KADM_EXPDATE,fields); SET_FIELD(KADM_ATTR,fields); SET_FIELD(KADM_MAXLIFE,fields); +#if 0 + SET_FIELD(KADM_DESKEY,fields); +#endif if (setvals(&vals, argv[1]) != KADM_SUCCESS) - return; + return 0; if (princ_exists(vals.name, vals.instance, krbrlm) != PE_NO) { /* get the admin's password */ if (get_admin_password() != GOOD_PW) - return; + return 0; if ((status = kadm_get(&vals, fields)) == KADM_SUCCESS) prin_vals(&vals); @@ -576,11 +777,12 @@ get_entry(int argc, char **argv) clean_up(); } else - printf("kadmin: Principal does not exist.\n"); - return; + printf("kadmin: Principal %s does not exist.\n", + krb_unparse_name_long (vals.name, vals.instance, krbrlm)); + return 0; } -void +static int mod_entry(int argc, char **argv) { int status; @@ -589,10 +791,10 @@ mod_entry(int argc, char **argv) if (argc != 2) { printf("Usage: mod_entry username\n"); - return; + return 0; } - bzero(fields, sizeof(fields)); + memset(fields, 0, sizeof(fields)); SET_FIELD(KADM_NAME,fields); SET_FIELD(KADM_INST,fields); @@ -601,18 +803,19 @@ mod_entry(int argc, char **argv) SET_FIELD(KADM_MAXLIFE,fields); if (setvals(&ovals, argv[1]) != KADM_SUCCESS) - return; + return 0; nvals = ovals; if (princ_exists(ovals.name, ovals.instance, krbrlm) == PE_NO) { - printf("kadmin: Principal does not exist.\n"); - return; + printf("kadmin: Principal %s does not exist.\n", + krb_unparse_name_long (ovals.name, ovals.instance, krbrlm)); + return 0; } /* get the admin's password */ if (get_admin_password() != GOOD_PW) - return; + return 0; if ((status = kadm_get(&ovals, fields)) != KADM_SUCCESS) { printf("[ unable to retrieve current settings: %s ]\n", @@ -630,7 +833,9 @@ mod_entry(int argc, char **argv) get_attr(&nvals); get_expdate(&nvals); - if (IS_FIELD(KADM_MAXLIFE, nvals.fields) || IS_FIELD(KADM_ATTR, nvals.fields) || IS_FIELD(KADM_EXPDATE, nvals.fields)) { + if (IS_FIELD(KADM_MAXLIFE, nvals.fields) || + IS_FIELD(KADM_ATTR, nvals.fields) || + IS_FIELD(KADM_EXPDATE, nvals.fields)) { if ((status = kadm_mod(&ovals, &nvals)) != KADM_SUCCESS) { printf("kadm error: %s\n",error_message(status)); goto out; @@ -645,127 +850,12 @@ mod_entry(int argc, char **argv) out: if (!multiple) clean_up(); - return; + return 0; } -void +static int help(int argc, char **argv) { - if (argc == 1) { - printf("Welcome to the Kerberos administration program."); - printf("Type \"?\" to get\n"); - printf("a list of requests that are available. You can"); - printf(" get help on each of\n"); - printf("the commands by typing \"help command_name\"."); - printf(" Some functions of this\n"); - printf("program will require an \"admin\" password"); - printf(" from you. This is a password\n"); - printf("private to you, that is used to authenticate"); - printf(" requests from this\n"); - printf("program. You can change this password with"); - printf(" the \"change_admin_password\"\n"); - printf("(or short form \"cap\") command. Good Luck! \n"); - } else if (!strcmp(argv[1], "change_password") || - !strcmp(argv[1], "cpw")) { - printf("Usage: change_password user_name.\n"); - printf("\n"); - printf("user_name is the name of the user whose password"); - printf(" you wish to change. \n"); - printf("His/her password is changed in the kerberos database\n"); - printf("When this command is issued, first the \"Admin\""); - printf(" password will be prompted\n"); - printf("for and if correct the user's new password will"); - printf(" be prompted for (twice with\n"); - printf("appropriate comparison). Note: No minimum password"); - printf(" length restrictions apply, but\n"); - printf("longer passwords are more secure.\n"); - } else if (!strcmp(argv[1], "change_admin_password") || - !strcmp(argv[1], "cap")) { - printf("Usage: change_admin_password.\n"); - printf("\n"); - printf("This command takes no arguments and is used"); - printf(" to change your private\n"); - printf("\"Admin\" password. It will first prompt for"); - printf(" the (current) \"Admin\"\n"); - printf("password and then ask for the new password"); - printf(" by prompting:\n"); - printf("\n"); - printf("New password for <Your User Name>.admin:\n"); - printf("\n"); - printf("Enter the new admin password that you desire"); - printf(" (it will be asked for\n"); - printf("twice to avoid errors).\n"); - } else if (!strcmp(argv[1], "add_new_key") || - !strcmp(argv[1], "ank")) { - printf("Usage: add_new_key user_name.\n"); - printf("\n"); - printf("user_name is the name of a new user to put"); - printf(" in the kerberos database. Your\n"); - printf("\"Admin\" password and the user's password"); - printf(" are prompted for. The user's\n"); - printf("password will be asked for"); - printf(" twice to avoid errors.\n"); - printf("You are also prompted for the default ticket"); - printf(" lifetime, attributes\n"); - printf("and expiration date (see the 'mod_entry' command).\n"); - } else if (!strcmp(argv[1], "get_entry") || - !strcmp(argv[1], "get")) { - printf("Usage: get_entry user_name.\n"); - printf("\n"); - printf("user_name is the name of a user whose"); - printf(" entry you wish to review. Your\n"); - printf("\"Admin\" password is prompted for. "); - printf(" The key field is not filled in, for\n"); - printf("security reasons.\n"); - } else if (!strcmp(argv[1], "mod_entry") || - !strcmp(argv[1], "mod")) { - printf("Usage: mod_entry user_name.\n"); - printf("\n"); - printf("user_name is the name of a user whose"); - printf(" entry you wish to modify. Your\n"); - printf("\"Admin\" password is prompted for."); - printf(" You will also be prompted for the new\n"); - printf("default ticket lifetime, attributes"); - printf(" and expiration date. Attributes may\n"); - printf("be entered in decimal by default,"); - printf(" octal if begun with '0', or hexadecimal\n"); - printf("if begun with '0x'. End the lifetime"); - printf(" with 'm' to specify minutes, 'h'\n"); - printf("to specify hours.\n"); - } else if (!strcmp(argv[1], "destroy_tickets") || - !strcmp(argv[1], "dest")) { - printf("Usage: destroy_tickets\n"); - printf("\n"); - printf("Destroy your admin tickets. This will"); - printf(" cause you to be prompted for your\n"); - printf("admin password on your next request.\n"); - } else if (!strcmp(argv[1], "list_requests") || - !strcmp(argv[1], "lr") || - !strcmp(argv[1], "?")) { - printf("Usage: list_requests\n"); - printf("\n"); - printf("This command lists what other commands are"); - printf(" currently available.\n"); - } else if (!strcmp(argv[1], "exit") || - !strcmp(argv[1], "quit") || - !strcmp(argv[1], "q")) { - printf("Usage: quit\n"); - printf("\n"); - printf("This command exits this program.\n"); - } else { - printf("Sorry there is no such command as %s.", argv[1]); - printf(" Type \"help\" for more information. \n"); - } - return; + sl_help (cmds, argc, argv); + return 0; } -#if 0 -static void -go_home(str,x) -char *str; -int x; -{ - fprintf(stderr, "%s: %s\n", str, error_message(x)); - clean_up(); - exit(1); -} -#endif diff --git a/kerberosIV/kadmin/kadmin_cmds.ct b/kerberosIV/kadmin/kadmin_cmds.ct deleted file mode 100644 index a1f12e26c79..00000000000 --- a/kerberosIV/kadmin/kadmin_cmds.ct +++ /dev/null @@ -1,52 +0,0 @@ -# $Id: kadmin_cmds.ct,v 1.1 1995/12/14 06:52:48 tholo Exp $ - -#- -# Copyright 1988 by the Massachusetts Institute of Technology. -# -# Permission to use, copy, modify, and distribute this software -# and its documentation for any purpose and without fee is -# hereby granted, provided that the above copyright notice -# appear in all copies and that both that copyright notice and -# this permission notice appear in supporting documentation, -# and that the names of M.I.T. and the M.I.T. S.I.P.B. not be -# used in advertising or publicity pertaining to distribution -# of the software without specific, written prior permission. -# M.I.T. and the M.I.T. S.I.P.B. make no representations about -# the suitability of this software for any purpose. It is -# provided "as is" without express or implied warranty. - -# Command table for Kerberos administration tool - - command_table admin_cmds; - - request change_password, - "Change a user's password", - change_password, cpw; - - request change_admin_password, "Change your admin password", - change_admin_password, cap; - - request add_new_key, "Add new user to kerberos database", - add_new_key, ank; - - request get_entry, "Get entry from kerberos database", - get_entry, get; - - request mod_entry, "Modify entry in kerberos database", - mod_entry, mod; - - request clean_up, "Destroy admin tickets", - destroy_tickets, dest; - - request help,"Request help with this program", - help; - -# list_requests is generic -- unrelated to Kerberos - - request ss_list_requests, "List available requests.", - list_requests, lr, "?"; - - request quit, "Exit program.", - quit, exit, q; - - end; diff --git a/kerberosIV/kadmin/new_pwd.c b/kerberosIV/kadmin/new_pwd.c new file mode 100644 index 00000000000..a57232dbf83 --- /dev/null +++ b/kerberosIV/kadmin/new_pwd.c @@ -0,0 +1,146 @@ +/* $KTH: new_pwd.c,v 1.11 1997/05/02 14:28:54 assar Exp $ */ + +/* + * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "kadm_locl.h" + +#ifdef NOENCRYPTION +#define read_long_pw_string placebo_read_pw_string +#else +#define read_long_pw_string des_read_pw_string +#endif + +static char * +check_pw (char *pword) +{ + if (strlen(pword) == 0) + return "Null passwords are not allowed - Please enter a longer password."; + + if (strlen(pword) < MIN_KPW_LEN) + return "Password is to short - Please enter a longer password."; + + /* Don't allow all lower case passwords regardless of length */ + { + char *t; + for (t = pword; *t && islower(*t); t++) + ; + if (*t == 0) + return "Please don't use an all-lower case password.\n" + "\tUnusual capitalization, delimiter characters or " + "digits are suggested."; + } + + return NULL; +} + +int +get_pw_new_pwd(char *pword, int pwlen, krb_principal *pr, int print_realm) +{ + char ppromp[40+ANAME_SZ+INST_SZ+REALM_SZ]; /* for the password prompt */ + char npromp[40+ANAME_SZ+INST_SZ+REALM_SZ]; /* for the password prompt */ + + char p[MAX_K_NAME_SZ]; + + char local_realm[REALM_SZ]; + int status; + char *expl; + + /* + * We don't care about failure; this is to determine whether or + * not to print the realm in the prompt for a new password. + */ + krb_get_lrealm(local_realm, 1); + + if (strcmp(local_realm, pr->realm)) + print_realm++; + + { + char *q; + krb_unparse_name_r(pr, p); + if(print_realm == 0 && (q = strrchr(p, '@'))) + *q = 0; + } + + snprintf(ppromp, sizeof(ppromp), "Old password for %s:", p); + if (read_long_pw_string(pword, pwlen-1, ppromp, 0)) { + fprintf(stderr, "Error reading old password.\n"); + return -1; + } + + status = krb_get_pw_in_tkt(pr->name, pr->instance, pr->realm, + PWSERV_NAME, KADM_SINST, 1, pword); + if (status != KSUCCESS) { + if (status == INTK_BADPW) { + printf("Incorrect old password.\n"); + return -1; + } + else { + fprintf(stderr, "Kerberos error: %s\n", krb_get_err_text(status)); + return -1; + } + } + memset(pword, 0, pwlen); + + do { + char verify[MAX_KPW_LEN]; + snprintf(npromp, sizeof(npromp), "New Password for %s:",p); + if (read_long_pw_string(pword, pwlen-1, npromp, 0)) { + fprintf(stderr, + "Error reading new password, password unchanged.\n"); + return -1; + } + expl = check_pw (pword); + if (expl) { + printf("\n\t%s\n\n", expl); + continue; + } + /* Now we got an ok password, verify it. */ + snprintf(npromp, sizeof(npromp), "Verifying New Password for %s:", p); + if (read_long_pw_string(verify, MAX_KPW_LEN-1, npromp, 0)) { + fprintf(stderr, + "Error reading new password, password unchanged.\n"); + return -1; + } + if (strcmp(pword, verify) != 0) { + printf("Verify failure - try again\n"); + expl = ""; /* continue */ + } + } while (expl); + return 0; +} diff --git a/kerberosIV/kadmind/Makefile b/kerberosIV/kadmind/Makefile index f0aef6a9ff7..867b2bc7fad 100644 --- a/kerberosIV/kadmind/Makefile +++ b/kerberosIV/kadmind/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.5 1997/02/19 04:02:20 tholo Exp $ +# $OpenBSD: Makefile,v 1.6 1997/12/15 17:56:20 art Exp $ .include <bsd.obj.mk> PROG= kadmind -SRCS= admin_server.c kadm_funcs.c kadm_ser_wrap.c kadm_server.c +SRCS= admin_server.c kadm_funcs.c kadm_ser_wrap.c kadm_server.c pw_check.c .if exists(${.CURDIR}/../kadm/${__objdir}) CFLAGS+=-I${.CURDIR}/../kadm/${__objdir} .else diff --git a/kerberosIV/kadmind/admin_server.c b/kerberosIV/kadmind/admin_server.c index 0990eaa57fb..9532edbb26b 100644 --- a/kerberosIV/kadmind/admin_server.c +++ b/kerberosIV/kadmind/admin_server.c @@ -1,6 +1,7 @@ -/* $Id: admin_server.c,v 1.2 1997/01/15 23:40:51 millert Exp $ */ +/* $OpenBSD: admin_server.c,v 1.3 1997/12/15 17:56:21 art Exp $ */ +/* $KTH: admin_server.c,v 1.42 1997/12/04 19:31:39 assar Exp $ */ -/*- +/* * Copyright (C) 1989 by the Massachusetts Institute of Technology * * Export of this software from the United States of America is assumed @@ -18,6 +19,7 @@ * permission. M.I.T. makes no representations about the suitability of * this software for any purpose. It is provided "as is" without express * or implied warranty. + * */ /* @@ -29,13 +31,11 @@ this holds the main loop and initialization and cleanup code for the server */ -#include <kadm_locl.h> +#include "kadm_locl.h" /* Almost all procs and such need this, so it is global */ admin_params prm; /* The command line parameters struct */ -static char prog[32]; /* WHY IS THIS NEEDED??????? */ -char *progname = prog; /* GLOBAL */ char *acldir = DEFAULT_ACL_DIR; static char krbrlm[REALM_SZ]; @@ -43,28 +43,28 @@ static char krbrlm[REALM_SZ]; static unsigned pidarraysize = 0; static int *pidarray = (int *)0; -static exit_now = 0; +static int exit_now = 0; -static void -doexit() +void +doexit(int sig) { exit_now = 1; -#ifndef sgi /* Sigh -- sgi cc balks at this... */ - return (void)(0); -#endif + return; } -static void -do_child() +void +do_child(int sig) { - /* SIGCHLD brings us here */ int pid; - register int i, j; + int i, j; int status; pid = wait(&status); + /* Reinstall signal handlers for SysV. Must be done *after* wait */ + signal(SIGCHLD, do_child); + for (i = 0; i < pidarraysize; i++) if (pidarray[i] == pid) { /* found it */ @@ -72,57 +72,32 @@ do_child() /* copy others down */ pidarray[j] = pidarray[j+1]; pidarraysize--; - if (WIFEXITED(status) || WIFSIGNALED(status)) - log("child %d: termsig %d, retcode %d", pid, - WTERMSIG(status), WEXITSTATUS(status)); -#ifndef sgi - return (void)(0); -#endif + if ((WIFEXITED(status) && WEXITSTATUS(status) != 0) + || WIFSIGNALED(status)) + krb_log("child %d: termsig %d, retcode %d", pid, + WTERMSIG(status), WEXITSTATUS(status)); + return; } - log("child %d not in list: termsig %d, retcode %d", pid, + krb_log("child %d not in list: termsig %d, retcode %d", pid, WTERMSIG(status), WEXITSTATUS(status)); -#ifndef sgi - return (void)(0); -#endif -} - -static int nSIGCHLD = 0; - -static void -count_SIGCHLD() -{ - nSIGCHLD++; -#ifndef sgi - return (void)(0); -#endif } static void kill_children(void) { int i; - void (*ofunc)(); - - ofunc = signal(SIGCHLD, count_SIGCHLD); for (i = 0; i < pidarraysize; i++) { kill(pidarray[i], SIGINT); - log("killing child %d", pidarray[i]); + krb_log("killing child %d", pidarray[i]); } - - (void) signal(SIGCHLD, ofunc); - - for (; nSIGCHLD != 0; nSIGCHLD--) - do_child(); - - return; } /* close the system log file */ static void close_syslog(void) { - log("Shutting down admin server"); + krb_log("Shutting down admin server"); } static void @@ -134,11 +109,10 @@ byebye(void) /* say goodnight gracie */ static void clear_secrets(void) { - bzero((char *)server_parm.master_key, sizeof(server_parm.master_key)); - bzero((char *)server_parm.master_key_schedule, + memset(server_parm.master_key, 0, sizeof(server_parm.master_key)); + memset(server_parm.master_key_schedule, 0, sizeof(server_parm.master_key_schedule)); server_parm.master_key_version = 0L; - return; } #ifdef DEBUG @@ -168,13 +142,13 @@ process_client(int fd, struct sockaddr_in *who) int more; int status; - if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)) < 0) - log("setsockopt keepalive: %d",errno); + if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)) < 0) + krb_log("setsockopt keepalive: %d",errno); server_parm.recv_addr = *who; if (kerb_init()) { /* Open as client */ - log("can't open krb db"); + krb_log("can't open krb db"); cleanexit(1); } /* need to set service key to changepw.KRB_MASTER */ @@ -183,88 +157,81 @@ process_client(int fd, struct sockaddr_in *who) 1, &more); if (status == -1) { /* db locked */ - u_long retcode = KADM_DB_INUSE; + int32_t retcode = KADM_DB_INUSE; char *pdat; - dat_len = KADM_VERSIZE + sizeof(u_long); + dat_len = KADM_VERSIZE + sizeof(retcode); dat = (u_char *) malloc((unsigned)dat_len); pdat = (char *) dat; - retcode = htonl((u_long) KADM_DB_INUSE); - (void) strncpy(pdat, KADM_ULOSE, KADM_VERSIZE); - bcopy((char *)&retcode, &pdat[KADM_VERSIZE], sizeof(u_long)); + retcode = htonl((u_int32_t) KADM_DB_INUSE); + strncpy(pdat, KADM_ULOSE, KADM_VERSIZE); + memcpy(pdat+KADM_VERSIZE, &retcode, sizeof(retcode)); goto out; } else if (!status) { - log("no service %s.%s",server_parm.sname, server_parm.sinst); + krb_log("no service %s.%s",server_parm.sname, server_parm.sinst); cleanexit(2); } - bcopy((char *)&service.key_low, (char *)skey, 4); - bcopy((char *)&service.key_high, (char *)(((long *) skey) + 1), 4); - bzero((char *)&service, sizeof(service)); + copy_to_key(&service.key_low, &service.key_high, skey); + memset(&service, 0, sizeof(service)); kdb_encrypt_key (&skey, &skey, &server_parm.master_key, server_parm.master_key_schedule, DES_DECRYPT); - (void) krb_set_key((char *)skey, 0); /* if error, will show up when + krb_set_key(skey, 0); /* if error, will show up when rd_req fails */ - bzero((char *)skey, sizeof(skey)); + memset(skey, 0, sizeof(skey)); while (1) { - if ((retval = krb_net_read(fd, (char *)&dlen, sizeof(u_short))) != + if ((retval = krb_net_read(fd, &dlen, sizeof(u_short))) != sizeof(u_short)) { if (retval < 0) - log("dlen read: %s",error_message(errno)); + krb_log("dlen read: %s",error_message(errno)); else if (retval) - log("short dlen read: %d",retval); - (void) close(fd); + krb_log("short dlen read: %d",retval); + close(fd); cleanexit(retval ? 3 : 0); } if (exit_now) { cleanexit(0); } - dat_len = (int) ntohs(dlen); - dat = (u_char *) malloc((unsigned)dat_len); + dat_len = ntohs(dlen); + dat = (u_char *) malloc(dat_len); if (!dat) { - log("malloc: No memory"); - (void) close(fd); + krb_log("malloc: No memory"); + close(fd); cleanexit(4); } - if ((retval = krb_net_read(fd, (char *)dat, dat_len)) != dat_len) { + if ((retval = krb_net_read(fd, dat, dat_len)) != dat_len) { if (retval < 0) - log("data read: %s",error_message(errno)); + krb_log("data read: %s",error_message(errno)); else - log("short read: %d vs. %d", dat_len, retval); - (void) close(fd); + krb_log("short read: %d vs. %d", dat_len, retval); + close(fd); cleanexit(5); } if (exit_now) { cleanexit(0); } if ((retval = kadm_ser_in(&dat,&dat_len)) != KADM_SUCCESS) - log("processing request: %s", error_message(retval)); + krb_log("processing request: %s", error_message(retval)); /* kadm_ser_in did the processing and returned stuff in dat & dat_len , return the appropriate data */ out: - dlen = (u_short) dat_len; - - if (dat_len != (int)dlen) { - clear_secrets(); - abort(); /* XXX */ - } - dlen = htons(dlen); + dlen = htons(dat_len); - if (krb_net_write(fd, (char *)&dlen, sizeof(u_short)) < 0) { - log("writing dlen to client: %s",error_message(errno)); - (void) close(fd); + if (krb_net_write(fd, &dlen, sizeof(u_short)) < 0) { + krb_log("writing dlen to client: %s",error_message(errno)); + close(fd); cleanexit(6); } - if (krb_net_write(fd, (char *)dat, dat_len) < 0) { - log(LOG_ERR, "writing to client: %s",error_message(errno)); - (void) close(fd); + if (krb_net_write(fd, dat, dat_len) < 0) { + krb_log("writing to client: %s", error_message(errno)); + close(fd); cleanexit(7); } - free((char *)dat); + free(dat); } /*NOTREACHED*/ } @@ -284,20 +251,27 @@ kadm_listen(void) int addrlen; int pid; - (void) signal(SIGINT, doexit); - (void) signal(SIGTERM, doexit); - (void) signal(SIGHUP, doexit); - (void) signal(SIGQUIT, doexit); - (void) signal(SIGPIPE, SIG_IGN); /* get errors on write() */ - (void) signal(SIGALRM, doexit); - (void) signal(SIGCHLD, do_child); + signal(SIGINT, doexit); + signal(SIGTERM, doexit); + signal(SIGHUP, doexit); + signal(SIGQUIT, doexit); + signal(SIGPIPE, SIG_IGN); /* get errors on write() */ + signal(SIGALRM, doexit); + signal(SIGCHLD, do_child); + if (setsid() < 0) + krb_log("setsid() failed"); if ((admin_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) return KADM_NO_SOCK; + { + int one=1; + setsockopt(admin_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, + sizeof(one)); + } if (bind(admin_fd, (struct sockaddr *)&server_parm.admin_addr, sizeof(struct sockaddr_in)) < 0) return KADM_NO_BIND; - (void) listen(admin_fd, 1); + listen(admin_fd, 1); FD_ZERO(&mask); FD_SET(admin_fd, &mask); @@ -308,12 +282,12 @@ kadm_listen(void) return(0); } readfds = mask; - if ((found = select(admin_fd+1,&readfds,(fd_set *)0, - (fd_set *)0, (struct timeval *)0)) == 0) + if ((found = select(admin_fd+1, &readfds, 0, + 0, (struct timeval *)0)) == 0) continue; /* no things read */ if (found < 0) { if (errno != EINTR) - log("select: %s",error_message(errno)); + krb_log("select: %s",error_message(errno)); continue; } if (FD_ISSET(admin_fd, &readfds)) { @@ -321,7 +295,7 @@ kadm_listen(void) addrlen = sizeof(peer); if ((peer_fd = accept(admin_fd, (struct sockaddr *)&peer, &addrlen)) < 0) { - log("accept: %s",error_message(errno)); + krb_log("accept: %s",error_message(errno)); continue; } #ifndef DEBUG @@ -329,30 +303,33 @@ kadm_listen(void) if ((pid = fork())) { /* parent */ if (pid < 0) { - log("fork: %s",error_message(errno)); - (void) close(peer_fd); + krb_log("fork: %s",error_message(errno)); + close(peer_fd); continue; } /* fork succeded: keep tabs on child */ - (void) close(peer_fd); - if (pidarray) { - pidarray = (int *)realloc((char *)pidarray, ++pidarraysize); - pidarray[pidarraysize-1] = pid; - } else { - pidarray = (int *)malloc(pidarraysize = 1); - pidarray[0] = pid; - } + close(peer_fd); + pidarray = realloc(pidarray, ++pidarraysize); + pidarray[pidarraysize-1] = pid; } else { /* child */ - (void) close(admin_fd); + close(admin_fd); #endif /* DEBUG */ + /* + * If we are multihomed we need to figure out which + * local address that is used this time since it is + * used in "direction" comparison. + */ + getsockname(peer_fd, + (struct sockaddr *)&server_parm.admin_addr, + &addrlen); /* do stuff */ process_client (peer_fd, &peer); #ifndef DEBUG } #endif } else { - log("something else woke me up!"); + krb_log("something else woke me up!"); return(0); } } @@ -365,22 +342,19 @@ kadm_listen(void) */ int main(int argc, char **argv) /* admin_server main routine */ - - { int errval; int c; - prog[sizeof(prog)-1]='\0'; /* Terminate... */ - (void) strncpy(prog, argv[0], sizeof(prog)-1); + umask(077); /* Create protected files */ /* initialize the admin_params structure */ prm.sysfile = KADM_SYSLOG; /* default file name */ - prm.inter = 1; + prm.inter = 0; - bzero(krbrlm, sizeof(krbrlm)); + memset(krbrlm, 0, sizeof(krbrlm)); - while ((c = getopt(argc, argv, "f:hnd:a:r:")) != -1) + while ((c = getopt(argc, argv, "f:hmnd:a:r:")) != EOF) switch(c) { case 'f': /* Syslog file name change */ prm.sysfile = optarg; @@ -388,44 +362,42 @@ main(int argc, char **argv) /* admin_server main routine */ case 'n': prm.inter = 0; break; + case 'm': + prm.inter = 1; + break; case 'a': /* new acl directory */ acldir = optarg; break; case 'd': /* put code to deal with alt database place */ - if ((errval = kerb_db_set_name(optarg))) { - fprintf(stderr, "opening database %s: %s", - optarg, error_message(errval)); - exit(1); - } + if ((errval = kerb_db_set_name(optarg))) + errx (1, "opening database %s: %s", + optarg, error_message(errval)); break; case 'r': - (void) strncpy(krbrlm, optarg, sizeof(krbrlm) - 1); + strncpy(krbrlm, optarg, sizeof(krbrlm) - 1); + krbrlm[sizeof(krbrlm) - 1] = '\0'; break; case 'h': /* get help on using admin_server */ default: - printf("Usage: admin_server [-h] [-n] [-r realm] [-d dbname] [-f filename] [-a acldir]\n"); - exit(-1); /* failure */ + errx(1, "Usage: kadmind [-h] [-n] [-m] [-r realm] [-d dbname] [-f filename] [-a acldir]"); } if (krbrlm[0] == 0) - if (krb_get_lrealm(krbrlm, 0) != KSUCCESS) { - fprintf(stderr, - "Unable to get local realm. Fix krb.conf or use -r.\n"); - exit(1); - } + if (krb_get_lrealm(krbrlm, 0) != KSUCCESS) + errx (1, "Unable to get local realm. Fix krb.conf or use -r."); printf("KADM Server %s initializing\n",KADM_VERSTR); printf("Please do not use 'kill -9' to kill this job, use a\n"); printf("regular kill instead\n\n"); - set_logfile(prm.sysfile); - log("Admin server starting"); + kset_logfile(prm.sysfile); + krb_log("Admin server starting"); - (void) kerb_db_set_lockmode(KERB_DBL_NONBLOCKING); + kerb_db_set_lockmode(KERB_DBL_NONBLOCKING); errval = kerb_init(); /* Open the Kerberos database */ if (errval) { - fprintf(stderr, "error: kerb_init() failed"); + warnx ("error: kerb_init() failed"); close_syslog(); byebye(); } @@ -437,7 +409,7 @@ main(int argc, char **argv) /* admin_server main routine */ clients */ } if (errval != KADM_SUCCESS) { - fprintf(stderr,"error: %s\n",error_message(errval)); + warnx("error: %s",error_message(errval)); kerb_fini(); /* Close if error */ } close_syslog(); /* Close syslog file, print diff --git a/kerberosIV/kadmind/kadm_funcs.c b/kerberosIV/kadmind/kadm_funcs.c index 0768b2d4069..3e1c45c1bda 100644 --- a/kerberosIV/kadmind/kadm_funcs.c +++ b/kerberosIV/kadmind/kadm_funcs.c @@ -1,36 +1,37 @@ -/* $Id: kadm_funcs.c,v 1.2 1996/09/16 18:48:49 millert Exp $ */ - -/*- - * Copyright (C) 1989 by the Massachusetts Institute of Technology - * - * Export of this software from the United States of America is assumed - * to require a specific license from the United States Government. - * It is the responsibility of any person or organization contemplating - * export to obtain such a license before exporting. - * - * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and - * distribute this software and its documentation for any purpose and - * without fee is hereby granted, provided that the above copyright - * notice appear in all copies and that both that copyright notice and - * this permission notice appear in supporting documentation, and that - * the name of M.I.T. not be used in advertising or publicity pertaining - * to distribution of the software without specific, written prior - * permission. M.I.T. makes no representations about the suitability of - * this software for any purpose. It is provided "as is" without express - * or implied warranty. - */ +/* $OpenBSD: kadm_funcs.c,v 1.3 1997/12/15 17:56:21 art Exp $ */ +/* $KTH: kadm_funcs.c,v 1.16 1997/05/02 14:28:49 assar Exp $ */ + +/* + Copyright (C) 1989 by the Massachusetts Institute of Technology + + Export of this software from the United States of America is assumed + to require a specific license from the United States Government. + It is the responsibility of any person or organization contemplating + export to obtain such a license before exporting. + +WITHIN THAT CONSTRAINT, permission to use, copy, modify, and +distribute this software and its documentation for any purpose and +without fee is hereby granted, provided that the above copyright +notice appear in all copies and that both that copyright notice and +this permission notice appear in supporting documentation, and that +the name of M.I.T. not be used in advertising or publicity pertaining +to distribution of the software without specific, written prior +permission. M.I.T. makes no representations about the suitability of +this software for any purpose. It is provided "as is" without express +or implied warranty. + +*/ /* * Kerberos administration server-side database manipulation routines */ /* -kadm_funcs.c -the actual database manipulation code -*/ + * kadm_funcs.c + * the actual database manipulation code + */ -#include <kadm_locl.h> -#include <sys/param.h> +#include "kadm_locl.h" static int check_access(char *pname, char *pinst, char *prealm, enum acl_types acltype) @@ -38,19 +39,24 @@ check_access(char *pname, char *pinst, char *prealm, enum acl_types acltype) char checkname[MAX_K_NAME_SZ]; char filename[MAXPATHLEN]; - (void) snprintf(checkname, sizeof(checkname), "%s.%s@%s", pname, pinst, - prealm); + snprintf(checkname, sizeof(checkname), "%s.%s@%s", pname, pinst, prealm); switch (acltype) { case ADDACL: - (void) snprintf(filename, sizeof(filename), "%s%s", acldir, ADD_ACL_FILE); + snprintf(filename, sizeof(filename), "%s%s", acldir, ADD_ACL_FILE); break; case GETACL: - (void) snprintf(filename, sizeof(filename), "%s%s", acldir, GET_ACL_FILE); + snprintf(filename, sizeof(filename), "%s%s", acldir, GET_ACL_FILE); break; case MODACL: - (void) snprintf(filename, sizeof(filename), "%s%s", acldir, MOD_ACL_FILE); + snprintf(filename, sizeof(filename), "%s%s", acldir, MOD_ACL_FILE); break; + case DELACL: + snprintf(filename, sizeof(filename), "%s%s", acldir, DEL_ACL_FILE); + break; + default: + krb_log("WARNING in check_access: default case in switch"); + return 0; } return(acl_check(filename, checkname)); } @@ -63,310 +69,383 @@ wildcard(char *str) return(0); } -#define failadd(code) { (void) log("FAILED addding '%s.%s' (%s)", valsin->name, valsin->instance, error_message(code)); return code; } +static int +fail(int code, char *oper, char *princ) +{ + krb_log("ERROR: %s: %s (%s)", oper, princ, error_message(code)); + return code; +} + +#define failadd(code) { fail(code, "ADD", victim); return code; } +#define faildelete(code) { fail(code, "DELETE", victim); return code; } +#define failget(code) { fail(code, "GET", victim); return code; } +#define failmod(code) { fail(code, "MOD", victim); return code; } +#define failchange(code) { fail(code, "CHANGE", admin); return code; } int -kadm_add_entry (char *rname, char *rinstance, char *rrealm, Kadm_vals *valsin, Kadm_vals *valsout) - /* requestors name */ - /* requestors instance */ - /* requestors realm */ - - +kadm_add_entry (char *rname, char *rinstance, char *rrealm, + Kadm_vals *valsin, Kadm_vals *valsout) { - long numfound; /* check how many we get written */ - int more; /* pointer to more grabbed records */ - Principal data_i, data_o; /* temporary principal */ - u_char flags[4]; - des_cblock newpw; - Principal default_princ; - - if (!check_access(rname, rinstance, rrealm, ADDACL)) { - (void) log("WARNING: '%s.%s@%s' tried to add an entry for '%s.%s'", - rname, rinstance, rrealm, valsin->name, valsin->instance); - return KADM_UNAUTH; - } + long numfound; /* check how many we get written */ + int more; /* pointer to more grabbed records */ + Principal data_i, data_o; /* temporary principal */ + u_char flags[4]; + des_cblock newpw; + Principal default_princ; - /* Need to check here for "legal" name and instance */ - if (wildcard(valsin->name) || wildcard(valsin->instance)) { - failadd(KADM_ILL_WILDCARD); - } + char admin[MAX_K_NAME_SZ], victim[MAX_K_NAME_SZ]; + + strncpy(admin, + krb_unparse_name_long(rname, rinstance, rrealm), + MAX_K_NAME_SZ -1); + admin[MAX_K_NAME_SZ -1] = '\0'; + + strncpy(victim, + krb_unparse_name_long(valsin->name, valsin->instance, NULL), + MAX_K_NAME_SZ -1); + victim[MAX_K_NAME_SZ -1] = '\0'; - (void) log("request to add an entry for '%s.%s' from '%s.%s@%s'", - valsin->name, valsin->instance, rname, rinstance, rrealm); + krb_log("ADD: %s by %s", victim, admin); + + if (!check_access(rname, rinstance, rrealm, ADDACL)) { + krb_log("WARNING: ADD: %s permission denied", admin); + return KADM_UNAUTH; + } - numfound = kerb_get_principal(KERB_DEFAULT_NAME, KERB_DEFAULT_INST, - &default_princ, 1, &more); - if (numfound == -1) { - failadd(KADM_DB_INUSE); - } else if (numfound != 1) { - failadd(KADM_UK_RERROR); - } + /* Need to check here for "legal" name and instance */ + if (wildcard(valsin->name) || wildcard(valsin->instance)) { + failadd(KADM_ILL_WILDCARD); + } - kadm_vals_to_prin(valsin->fields, &data_i, valsin); - (void) strncpy(data_i.name, valsin->name, ANAME_SZ); - (void) strncpy(data_i.instance, valsin->instance, INST_SZ); + numfound = kerb_get_principal(KERB_DEFAULT_NAME, KERB_DEFAULT_INST, + &default_princ, 1, &more); + if (numfound == -1) { + failadd(KADM_DB_INUSE); + } else if (numfound != 1) { + failadd(KADM_UK_RERROR); + } - if (!IS_FIELD(KADM_EXPDATE,valsin->fields)) - data_i.exp_date = default_princ.exp_date; - if (!IS_FIELD(KADM_ATTR,valsin->fields)) - data_i.attributes = default_princ.attributes; - if (!IS_FIELD(KADM_MAXLIFE,valsin->fields)) - data_i.max_life = default_princ.max_life; + kadm_vals_to_prin(valsin->fields, &data_i, valsin); + strncpy(data_i.name, valsin->name, ANAME_SZ - 1); + data_i.name[ANAME_SZ - 1] = '\0'; + strncpy(data_i.instance, valsin->instance, INST_SZ - 1); + data_i.instance[INST_SZ - 1] = '\0'; - bzero((char *)&default_princ, sizeof(default_princ)); + if (!IS_FIELD(KADM_EXPDATE,valsin->fields)) + data_i.exp_date = default_princ.exp_date; + if (!IS_FIELD(KADM_ATTR,valsin->fields)) + data_i.attributes = default_princ.attributes; + if (!IS_FIELD(KADM_MAXLIFE,valsin->fields)) + data_i.max_life = default_princ.max_life; - /* convert to host order */ - data_i.key_low = ntohl(data_i.key_low); - data_i.key_high = ntohl(data_i.key_high); + memset(&default_princ, 0, sizeof(default_princ)); + /* convert to host order */ + data_i.key_low = ntohl(data_i.key_low); + data_i.key_high = ntohl(data_i.key_high); - bcopy(&data_i.key_low,newpw,4); - bcopy(&data_i.key_high,(char *)(((long *) newpw) + 1),4); - /* encrypt new key in master key */ - kdb_encrypt_key (&newpw, &newpw, &server_parm.master_key, + copy_to_key(&data_i.key_low, &data_i.key_high, newpw); + + /* encrypt new key in master key */ + kdb_encrypt_key (&newpw, &newpw, &server_parm.master_key, server_parm.master_key_schedule, DES_ENCRYPT); - bcopy(newpw,&data_i.key_low,4); - bcopy((char *)(((long *) newpw) + 1), &data_i.key_high,4); - bzero((char *)newpw, sizeof(newpw)); - - data_o = data_i; - numfound = kerb_get_principal(valsin->name, valsin->instance, - &data_o, 1, &more); - if (numfound == -1) { - failadd(KADM_DB_INUSE); - } else if (numfound) { - failadd(KADM_INUSE); - } else { - data_i.key_version++; - data_i.kdc_key_ver = server_parm.master_key_version; - (void) strncpy(data_i.mod_name, rname, sizeof(data_i.mod_name)-1); - (void) strncpy(data_i.mod_instance, rinstance, - sizeof(data_i.mod_instance)-1); - - numfound = kerb_put_principal(&data_i, 1); + copy_from_key(newpw, &data_i.key_low, &data_i.key_high); + memset(newpw, 0, sizeof(newpw)); + + data_o = data_i; + numfound = kerb_get_principal(valsin->name, valsin->instance, + &data_o, 1, &more); if (numfound == -1) { failadd(KADM_DB_INUSE); } else if (numfound) { - failadd(KADM_UK_SERROR); + failadd(KADM_INUSE); } else { - numfound = kerb_get_principal(valsin->name, valsin->instance, - &data_o, 1, &more); - if ((numfound!=1) || (more!=0)) { - failadd(KADM_UK_RERROR); - } - bzero((char *)flags, sizeof(flags)); - SET_FIELD(KADM_NAME,flags); - SET_FIELD(KADM_INST,flags); - SET_FIELD(KADM_EXPDATE,flags); - SET_FIELD(KADM_ATTR,flags); - SET_FIELD(KADM_MAXLIFE,flags); - kadm_prin_to_vals(flags, valsout, &data_o); - (void) log("'%s.%s' added.", valsin->name, valsin->instance); - return KADM_DATA; /* Set all the appropriate fields */ + data_i.key_version++; + data_i.kdc_key_ver = server_parm.master_key_version; + strncpy(data_i.mod_name, rname, sizeof(data_i.mod_name) - 1); + data_i.mod_name[sizeof(data_i.mod_name) - 1] = '\0'; + strncpy(data_i.mod_instance, rinstance, + sizeof(data_i.mod_instance) - 1); + data_i.mod_instance[sizeof(data_i.mod_instance - 1)] = '\0'; + + numfound = kerb_put_principal(&data_i, 1); + if (numfound == -1) { + failadd(KADM_DB_INUSE); + } else if (numfound) { + failadd(KADM_UK_SERROR); + } else { + numfound = kerb_get_principal(valsin->name, valsin->instance, + &data_o, 1, &more); + if ((numfound!=1) || (more!=0)) { + failadd(KADM_UK_RERROR); + } + memset(flags, 0, sizeof(flags)); + SET_FIELD(KADM_NAME,flags); + SET_FIELD(KADM_INST,flags); + SET_FIELD(KADM_EXPDATE,flags); + SET_FIELD(KADM_ATTR,flags); + SET_FIELD(KADM_MAXLIFE,flags); + kadm_prin_to_vals(flags, valsout, &data_o); + krb_log("ADD: %s added", victim); + return KADM_DATA; /* Set all the appropriate fields */ + } } - } } -#undef failadd - -#define failget(code) { (void) log("FAILED retrieving '%s.%s' (%s)", valsin->name, valsin->instance, error_message(code)); return code; } int -kadm_get_entry (char *rname, char *rinstance, char *rrealm, Kadm_vals *valsin, u_char *flags, Kadm_vals *valsout) - /* requestors name */ - /* requestors instance */ - /* requestors realm */ - /* what they wannt to get */ - /* which fields we want */ - /* what data is there */ +kadm_delete_entry (char *rname, char *rinstance, char *rrealm, + Kadm_vals *valsin) { - long numfound; /* check how many were returned */ - int more; /* To point to more name.instances */ - Principal data_o; /* Data object to hold Principal */ + int ret; + char admin[MAX_K_NAME_SZ], victim[MAX_K_NAME_SZ]; + + strncpy(admin, + krb_unparse_name_long(rname, rinstance, rrealm), + MAX_K_NAME_SZ - 1); + admin[MAX_K_NAME_SZ - 1] = '\0'; + strncpy(victim, + krb_unparse_name_long(valsin->name, valsin->instance, NULL), + MAX_K_NAME_SZ - 1); + victim[MAX_K_NAME_SZ - 1] = '\0'; + + krb_log("DELETE: %s by %s", victim, admin); + + if (!check_access(rname, rinstance, rrealm, DELACL)) { + krb_log("WARNING: DELETE: %s permission denied", admin); + return KADM_UNAUTH; + } + + /* Need to check here for "legal" name and instance */ + if (wildcard(valsin->name) || wildcard(valsin->instance)) { + faildelete(KADM_ILL_WILDCARD); + } - if (!check_access(rname, rinstance, rrealm, GETACL)) { - (void) log("WARNING: '%s.%s@%s' tried to get '%s.%s's entry", - rname, rinstance, rrealm, valsin->name, valsin->instance); - return KADM_UNAUTH; - } - - if (wildcard(valsin->name) || wildcard(valsin->instance)) { - failget(KADM_ILL_WILDCARD); - } - - (void) log("retrieve '%s.%s's entry for '%s.%s@%s'", - valsin->name, valsin->instance, rname, rinstance, rrealm); - - /* Look up the record in the database */ - numfound = kerb_get_principal(valsin->name, valsin->instance, - &data_o, 1, &more); - if (numfound == -1) { - failget(KADM_DB_INUSE); - } else if (numfound) { /* We got the record, let's return it */ - kadm_prin_to_vals(flags, valsout, &data_o); - (void) log("'%s.%s' retrieved.", valsin->name, valsin->instance); - return KADM_DATA; /* Set all the appropriate fields */ - } else { - failget(KADM_NOENTRY); /* Else whimper and moan */ - } +#define EQ(V,N,I) (strcmp((V)->name, (N)) == 0 && strcmp((V)->instance, (I)) == 0) + + if(EQ(valsin, PWSERV_NAME, KRB_MASTER) || + EQ(valsin, "K", "M") || + EQ(valsin, "default", "") || + EQ(valsin, KRB_TICKET_GRANTING_TICKET, server_parm.krbrlm)){ + krb_log("WARNING: DELETE: %s is immutable", victim); + return KADM_IMMUTABLE; /* XXX */ + } + + ret = kerb_delete_principal(valsin->name, valsin->instance); + if(ret == -1) + return KADM_DB_INUSE; /* XXX */ + krb_log("DELETE: %s removed.", victim); + return KADM_SUCCESS; } -#undef failget -#define failmod(code) { (void) log("FAILED modifying '%s.%s' (%s)", valsin1->name, valsin1->instance, error_message(code)); return code; } int -kadm_mod_entry (char *rname, char *rinstance, char *rrealm, Kadm_vals *valsin1, Kadm_vals *valsin2, Kadm_vals *valsout) - /* requestors name */ - /* requestors instance */ - /* requestors realm */ - /* holds the parameters being - passed in */ - /* the actual record which is returned */ +kadm_get_entry (char *rname, char *rinstance, char *rrealm, + Kadm_vals *valsin, u_char *flags, Kadm_vals *valsout) { - long numfound; - int more; - Principal data_o, temp_key; - u_char fields[4]; - des_cblock newpw; - - if (wildcard(valsin1->name) || wildcard(valsin1->instance)) { - failmod(KADM_ILL_WILDCARD); - } - - if (!check_access(rname, rinstance, rrealm, MODACL)) { - (void) log("WARNING: '%s.%s@%s' tried to change '%s.%s's entry", - rname, rinstance, rrealm, valsin1->name, valsin1->instance); - return KADM_UNAUTH; - } - - (void) log("request to modify '%s.%s's entry from '%s.%s@%s' ", - valsin1->name, valsin1->instance, rname, rinstance, rrealm); + long numfound; /* check how many were returned */ + int more; /* To point to more name.instances */ + Principal data_o; /* Data object to hold Principal */ + + char admin[MAX_K_NAME_SZ], victim[MAX_K_NAME_SZ]; + + strncpy(admin, + krb_unparse_name_long(rname, rinstance, rrealm), + MAX_K_NAME_SZ - 1); + admin[MAX_K_NAME_SZ - 1] = '\0'; + strncpy(victim, + krb_unparse_name_long(valsin->name, valsin->instance, NULL), + MAX_K_NAME_SZ - 1); + victim[MAX_K_NAME_SZ - 1] = '\0'; + + krb_log("GET: %s by %s", victim, admin); + + if (!check_access(rname, rinstance, rrealm, GETACL)) { + krb_log("WARNING: GET: %s permission denied", admin); + return KADM_UNAUTH; + } - numfound = kerb_get_principal(valsin1->name, valsin1->instance, - &data_o, 1, &more); - if (numfound == -1) { - failmod(KADM_DB_INUSE); - } else if (numfound) { - kadm_vals_to_prin(valsin2->fields, &temp_key, valsin2); - (void) strncpy(data_o.name, valsin1->name, ANAME_SZ); - (void) strncpy(data_o.instance, valsin1->instance, INST_SZ); - if (IS_FIELD(KADM_EXPDATE,valsin2->fields)) - data_o.exp_date = temp_key.exp_date; - if (IS_FIELD(KADM_ATTR,valsin2->fields)) - data_o.attributes = temp_key.attributes; - if (IS_FIELD(KADM_MAXLIFE,valsin2->fields)) - data_o.max_life = temp_key.max_life; - if (IS_FIELD(KADM_DESKEY,valsin2->fields)) { - data_o.key_version++; - data_o.kdc_key_ver = server_parm.master_key_version; - - - /* convert to host order */ - temp_key.key_low = ntohl(temp_key.key_low); - temp_key.key_high = ntohl(temp_key.key_high); - - - bcopy(&temp_key.key_low,newpw,4); - bcopy(&temp_key.key_high,(char *)(((long *) newpw) + 1),4); - - /* encrypt new key in master key */ - kdb_encrypt_key (&newpw, &newpw, &server_parm.master_key, - server_parm.master_key_schedule, DES_ENCRYPT); - bcopy(newpw,&data_o.key_low,4); - bcopy((char *)(((long *) newpw) + 1), &data_o.key_high,4); - bzero((char *)newpw, sizeof(newpw)); - } - bzero((char *)&temp_key, sizeof(temp_key)); - - (void) strncpy(data_o.mod_name, rname, sizeof(data_o.mod_name)-1); - (void) strncpy(data_o.mod_instance, rinstance, - sizeof(data_o.mod_instance)-1); - more = kerb_put_principal(&data_o, 1); - - bzero((char *)&data_o, sizeof(data_o)); - - if (more == -1) { - failmod(KADM_DB_INUSE); - } else if (more) { - failmod(KADM_UK_SERROR); - } else { - numfound = kerb_get_principal(valsin1->name, valsin1->instance, - &data_o, 1, &more); - if ((more!=0)||(numfound!=1)) { - failmod(KADM_UK_RERROR); - } - bzero((char *) fields, sizeof(fields)); - SET_FIELD(KADM_NAME,fields); - SET_FIELD(KADM_INST,fields); - SET_FIELD(KADM_EXPDATE,fields); - SET_FIELD(KADM_ATTR,fields); - SET_FIELD(KADM_MAXLIFE,fields); - kadm_prin_to_vals(fields, valsout, &data_o); - (void) log("'%s.%s' modified.", valsin1->name, valsin1->instance); - return KADM_DATA; /* Set all the appropriate fields */ - } - } - else { - failmod(KADM_NOENTRY); - } + if (wildcard(valsin->name) || wildcard(valsin->instance)) { + failget(KADM_ILL_WILDCARD); + } + + /* Look up the record in the database */ + numfound = kerb_get_principal(valsin->name, valsin->instance, + &data_o, 1, &more); + if (numfound == -1) { + failget(KADM_DB_INUSE); + } else if (numfound) { /* We got the record, let's return it */ + kadm_prin_to_vals(flags, valsout, &data_o); + krb_log("GET: %s retrieved", victim); + return KADM_DATA; /* Set all the appropriate fields */ + } else { + failget(KADM_NOENTRY); /* Else whimper and moan */ + } } -#undef failmod -#define failchange(code) { (void) log("FAILED changing key for '%s.%s@%s' (%s)", rname, rinstance, rrealm, error_message(code)); return code; } +int +kadm_mod_entry (char *rname, char *rinstance, char *rrealm, + Kadm_vals *valsin, Kadm_vals *valsin2, Kadm_vals *valsout) +{ + long numfound; + int more; + Principal data_o, temp_key; + u_char fields[4]; + des_cblock newpw; + + char admin[MAX_K_NAME_SZ], victim[MAX_K_NAME_SZ]; + + strncpy(admin, + krb_unparse_name_long(rname, rinstance, rrealm), + MAX_K_NAME_SZ - 1); + admin[MAX_K_NAME_SZ - 1] = '\0'; + strncpy(victim, + krb_unparse_name_long(valsin->name, valsin->instance, NULL), + MAX_K_NAME_SZ - 1); + victim[MAX_K_NAME_SZ - 1] = '\0'; + + + krb_log("MOD: %s by %s", victim, admin); + + if (wildcard(valsin->name) || wildcard(valsin->instance)) { + failmod(KADM_ILL_WILDCARD); + } + + if (!check_access(rname, rinstance, rrealm, MODACL)) { + krb_log("WARNING: MOD: %s permission denied", admin); + return KADM_UNAUTH; + } + + numfound = kerb_get_principal(valsin->name, valsin->instance, + &data_o, 1, &more); + if (numfound == -1) { + failmod(KADM_DB_INUSE); + } else if (numfound) { + kadm_vals_to_prin(valsin2->fields, &temp_key, valsin2); + strncpy(data_o.name, valsin->name, ANAME_SZ - 1); + data_o.name[ANAME_SZ - 1] = '\0'; + strncpy(data_o.instance, valsin->instance, INST_SZ - 1); + data_o.instance[INST_SZ - 1] = '\0'; + if (IS_FIELD(KADM_EXPDATE,valsin2->fields)) + data_o.exp_date = temp_key.exp_date; + if (IS_FIELD(KADM_ATTR,valsin2->fields)) + data_o.attributes = temp_key.attributes; + if (IS_FIELD(KADM_MAXLIFE,valsin2->fields)) + data_o.max_life = temp_key.max_life; + if (IS_FIELD(KADM_DESKEY,valsin2->fields)) { + data_o.key_version++; + data_o.kdc_key_ver = server_parm.master_key_version; + + + /* convert to host order */ + temp_key.key_low = ntohl(temp_key.key_low); + temp_key.key_high = ntohl(temp_key.key_high); + + + copy_to_key(&temp_key.key_low, &temp_key.key_high, newpw); + + /* encrypt new key in master key */ + kdb_encrypt_key (&newpw, &newpw, &server_parm.master_key, + server_parm.master_key_schedule, DES_ENCRYPT); + copy_from_key(newpw, &data_o.key_low, &data_o.key_high); + memset(newpw, 0, sizeof(newpw)); + } + memset(&temp_key, 0, sizeof(temp_key)); + + strncpy(data_o.mod_name, rname, sizeof(data_o.mod_name)-1); + data_o.mod_name[sizeof(data_o.mod_name) - 1] = '\0'; + strncpy(data_o.mod_instance, rinstance, + sizeof(data_o.mod_instance)-1); + data_o.mod_instance[sizeof(data_o.mod_instance) - 1] = '\0'; + more = kerb_put_principal(&data_o, 1); + + memset(&data_o, 0, sizeof(data_o)); + + if (more == -1) { + failmod(KADM_DB_INUSE); + } else if (more) { + failmod(KADM_UK_SERROR); + } else { + numfound = kerb_get_principal(valsin->name, valsin->instance, + &data_o, 1, &more); + if ((more!=0)||(numfound!=1)) { + failmod(KADM_UK_RERROR); + } + memset(fields, 0, sizeof(fields)); + SET_FIELD(KADM_NAME,fields); + SET_FIELD(KADM_INST,fields); + SET_FIELD(KADM_EXPDATE,fields); + SET_FIELD(KADM_ATTR,fields); + SET_FIELD(KADM_MAXLIFE,fields); + kadm_prin_to_vals(fields, valsout, &data_o); + krb_log("MOD: %s modified", victim); + return KADM_DATA; /* Set all the appropriate fields */ + } + } + else { + failmod(KADM_NOENTRY); + } +} int kadm_change (char *rname, char *rinstance, char *rrealm, unsigned char *newpw) { - long numfound; - int more; - Principal data_o; - des_cblock local_pw; - - if (strcmp(server_parm.krbrlm, rrealm)) { - (void) log("change key request from wrong realm, '%s.%s@%s'!\n", - rname, rinstance, rrealm); - return(KADM_WRONG_REALM); - } - - if (wildcard(rname) || wildcard(rinstance)) { - failchange(KADM_ILL_WILDCARD); - } - (void) log("'%s.%s@%s' wants to change its password", - rname, rinstance, rrealm); - - bcopy(newpw, local_pw, sizeof(local_pw)); + long numfound; + int more; + Principal data_o; + des_cblock local_pw; + + char admin[MAX_K_NAME_SZ]; + + strncpy(admin, + krb_unparse_name_long(rname, rinstance, rrealm), + MAX_K_NAME_SZ - 1); + admin[MAX_K_NAME_SZ - 1] = '\0'; + + krb_log("CHANGE: %s", admin); + + if (strcmp(server_parm.krbrlm, rrealm)) { + krb_log("ERROR: CHANGE: request from wrong realm %s", rrealm); + return(KADM_WRONG_REALM); + } + + if (wildcard(rname) || wildcard(rinstance)) { + failchange(KADM_ILL_WILDCARD); + } + + memcpy(local_pw, newpw, sizeof(local_pw)); - /* encrypt new key in master key */ - kdb_encrypt_key (&local_pw, &local_pw, &server_parm.master_key, + /* encrypt new key in master key */ + kdb_encrypt_key (&local_pw, &local_pw, &server_parm.master_key, server_parm.master_key_schedule, DES_ENCRYPT); - numfound = kerb_get_principal(rname, rinstance, - &data_o, 1, &more); - if (numfound == -1) { - failchange(KADM_DB_INUSE); - } else if (numfound) { - bcopy(local_pw,&data_o.key_low,4); - bcopy((char *)(((long *) local_pw) + 1), &data_o.key_high,4); - data_o.key_version++; - data_o.kdc_key_ver = server_parm.master_key_version; - (void) strncpy(data_o.mod_name, rname, sizeof(data_o.mod_name)-1); - (void) strncpy(data_o.mod_instance, rinstance, - sizeof(data_o.mod_instance)-1); - more = kerb_put_principal(&data_o, 1); - bzero((char *) local_pw, sizeof(local_pw)); - bzero((char *) &data_o, sizeof(data_o)); - if (more == -1) { + numfound = kerb_get_principal(rname, rinstance, + &data_o, 1, &more); + if (numfound == -1) { failchange(KADM_DB_INUSE); - } else if (more) { - failchange(KADM_UK_SERROR); - } else { - (void) log("'%s.%s@%s' password changed.", rname, rinstance, rrealm); - return KADM_SUCCESS; + } else if (numfound) { + copy_from_key(local_pw, &data_o.key_low, &data_o.key_high); + data_o.key_version++; + data_o.kdc_key_ver = server_parm.master_key_version; + strncpy(data_o.mod_name, rname, sizeof(data_o.mod_name)-1); + data_o.mod_name[sizeof(data_o.mod_name) - 1] = '\0'; + strncpy(data_o.mod_instance, rinstance, + sizeof(data_o.mod_instance)-1); + data_o.mod_instance[sizeof(data_o.mod_instance) - 1] = '\0'; + more = kerb_put_principal(&data_o, 1); + memset(local_pw, 0, sizeof(local_pw)); + memset(&data_o, 0, sizeof(data_o)); + if (more == -1) { + failchange(KADM_DB_INUSE); + } else if (more) { + failchange(KADM_UK_SERROR); + } else { + krb_log("CHANGE: %s's password changed", admin); + return KADM_SUCCESS; + } + } + else { + failchange(KADM_NOENTRY); } - } - else { - failchange(KADM_NOENTRY); - } } -#undef failchange diff --git a/kerberosIV/kadmind/kadm_ser_wrap.c b/kerberosIV/kadmind/kadm_ser_wrap.c index 2f3f35e810d..62064699dc8 100644 --- a/kerberosIV/kadmind/kadm_ser_wrap.c +++ b/kerberosIV/kadmind/kadm_ser_wrap.c @@ -1,7 +1,8 @@ -/* $Id: kadm_ser_wrap.c,v 1.4 1997/02/19 09:03:42 tholo Exp $ */ +/* $OpenBSD: kadm_ser_wrap.c,v 1.5 1997/12/15 17:56:22 art Exp $ */ +/* $KTH: kadm_ser_wrap.c,v 1.21 1997/12/05 01:27:29 assar Exp $ */ -/*- - * Copyright (C) 1989 by the Massachusetts Institute of Technology +/* + * Copyright (C) 1989 by the Massachusetts Institute of Technology * * Export of this software from the United States of America is assumed * to require a specific license from the United States Government. @@ -18,6 +19,7 @@ * permission. M.I.T. makes no representations about the suitability of * this software for any purpose. It is provided "as is" without express * or implied warranty. + * */ /* @@ -25,49 +27,50 @@ */ /* -kadm_ser_wrap.c -unwraps wrapped packets and calls the appropriate server subroutine -*/ + * kadm_ser_wrap.c + * unwraps wrapped packets and calls the appropriate server subroutine + */ -#include <kadm_locl.h> -#include <sys/param.h> +#include "kadm_locl.h" /* GLOBAL */ Kadm_Server server_parm; /* -kadm_ser_init -set up the server_parm structure -*/ + * kadm_ser_init + * set up the server_parm structure + */ int kadm_ser_init(int inter, char *realm) /* interactive or from file */ { - struct servent *sep; struct hostent *hp; char hostname[MAXHOSTNAMELEN]; - (void) init_kadm_err_tbl(); - (void) init_krb_err_tbl(); + init_kadm_err_tbl(); + init_krb_err_tbl(); if (gethostname(hostname, sizeof(hostname))) return KADM_NO_HOSTNAME; - (void) strcpy(server_parm.sname, PWSERV_NAME); - (void) strcpy(server_parm.sinst, KADM_SINST); - (void) strcpy(server_parm.krbrlm, realm); + strncpy(server_parm.sname, PWSERV_NAME, ANAME_SZ - 1); + server_parm.sname[ANAME_SZ - 1] = '\0'; + strncpy(server_parm.sinst, KRB_MASTER, INST_SZ - 1); + server_parm.sinst[INST_SZ - 1] = '\0'; + strncpy(server_parm.krbrlm, realm, REALM_SZ - 1); + server_parm.krbrlm[REALM_SZ - 1] = '\0'; server_parm.admin_fd = -1; - /* setting up the addrs */ - if ((sep = getservbyname(KADM_SNAME, "tcp")) == NULL) - return KADM_NO_SERV; - bzero((char *)&server_parm.admin_addr,sizeof(server_parm.admin_addr)); + /* setting up the addrs */ + memset(&server_parm.admin_addr,0, sizeof(server_parm.admin_addr)); + + server_parm.admin_addr.sin_port = k_getportbyname (KADM_SNAME, + "tcp", + htons(751)); server_parm.admin_addr.sin_family = AF_INET; if ((hp = gethostbyname(hostname)) == NULL) return KADM_NO_HOSTNAME; - bcopy(hp->h_addr, (char *) &server_parm.admin_addr.sin_addr.s_addr, - hp->h_length); - server_parm.admin_addr.sin_port = sep->s_port; + server_parm.admin_addr.sin_addr.s_addr = INADDR_ANY; /* setting up the database */ if (kdb_get_master_key((inter==1), &server_parm.master_key, server_parm.master_key_schedule) != 0) @@ -84,20 +87,23 @@ static void errpkt(u_char **dat, int *dat_len, int code) u_int32_t retcode; char *pdat; - free((char *)*dat); /* free up req */ + free(*dat); /* free up req */ *dat_len = KADM_VERSIZE + sizeof(u_int32_t); *dat = (u_char *) malloc((unsigned)*dat_len); + if (dat == NULL) + return; pdat = (char *) *dat; retcode = htonl((u_int32_t) code); - (void) strncpy(pdat, KADM_ULOSE, KADM_VERSIZE); - bcopy((char *)&retcode, &pdat[KADM_VERSIZE], sizeof(u_int32_t)); + strncpy(pdat, KADM_ULOSE, KADM_VERSIZE); + memcpy(&pdat[KADM_VERSIZE], &retcode, sizeof(u_int32_t)); return; } /* -kadm_ser_in -unwrap the data stored in dat, process, and return it. -*/ + * kadm_ser_in + * unwrap the data stored in dat, process, and return it. + */ + int kadm_ser_in(u_char **dat, int *dat_len) { @@ -123,17 +129,18 @@ kadm_ser_in(u_char **dat, int *dat_len) return KADM_LENGTH_ERROR; in_len += retc; authent.length = *dat_len - r_len - KADM_VERSIZE - sizeof(u_int32_t); - bcopy((char *)(*dat) + in_len, (char *)authent.dat, authent.length); + authent.length = MIN( authent.length, MAX_KTXT_LEN ); + memcpy(authent.dat, (char *)(*dat) + in_len, authent.length); authent.mbz = 0; /* service key should be set before here */ if ((retc = krb_rd_req(&authent, server_parm.sname, server_parm.sinst, - server_parm.recv_addr.sin_addr.s_addr, &ad, (char *)0))) + server_parm.recv_addr.sin_addr.s_addr, &ad, NULL))) { errpkt(dat, dat_len,retc + krb_err_base); return retc + krb_err_base; } -#define clr_cli_secrets() {bzero((char *)sess_sched, sizeof(sess_sched)); bzero((char *)ad.session, sizeof(ad.session));} +#define clr_cli_secrets() {memset(sess_sched, 0, sizeof(sess_sched)); memset(ad.session, 0,sizeof(ad.session));} in_st = *dat + *dat_len - r_len; #ifdef NOENCRYPTION @@ -147,7 +154,7 @@ kadm_ser_in(u_char **dat, int *dat_len) return KADM_BAD_CHK; } #ifdef NOENCRYPTION - bzero(sess_sched, sizeof(sess_sched)); + memset(sess_sched, 0, sizeof(sess_sched)); #else des_key_sched(&ad.session, sess_sched); #endif @@ -160,20 +167,24 @@ kadm_ser_in(u_char **dat, int *dat_len) } switch (msg_st.app_data[0]) { case CHANGE_PW: - retval = kadm_ser_cpw(msg_st.app_data+1,(int) msg_st.app_length,&ad, - &retdat, &retlen); + retval = kadm_ser_cpw(msg_st.app_data+1,(int) msg_st.app_length - 1, + &ad, &retdat, &retlen); break; case ADD_ENT: - retval = kadm_ser_add(msg_st.app_data+1,(int) msg_st.app_length,&ad, - &retdat, &retlen); + retval = kadm_ser_add(msg_st.app_data+1,(int) msg_st.app_length - 1, + &ad, &retdat, &retlen); break; case GET_ENT: - retval = kadm_ser_get(msg_st.app_data+1,(int) msg_st.app_length,&ad, - &retdat, &retlen); + retval = kadm_ser_get(msg_st.app_data+1,(int) msg_st.app_length - 1, + &ad, &retdat, &retlen); break; case MOD_ENT: - retval = kadm_ser_mod(msg_st.app_data+1,(int) msg_st.app_length,&ad, - &retdat, &retlen); + retval = kadm_ser_mod(msg_st.app_data+1,(int) msg_st.app_length - 1, + &ad, &retdat, &retlen); + break; + case DEL_ENT: + retval = kadm_ser_delete(msg_st.app_data + 1, msg_st.app_length - 1, + &ad, &retdat, &retlen); break; default: clr_cli_secrets(); @@ -181,20 +192,35 @@ kadm_ser_in(u_char **dat, int *dat_len) return KADM_NO_OPCODE; } /* Now seal the response back into a priv msg */ - free((char *)*dat); + free(*dat); + *dat = NULL; + tmpdat = (u_char *) malloc((unsigned)(retlen + KADM_VERSIZE + sizeof(u_int32_t))); - (void) strncpy((char *)tmpdat, KADM_VERSTR, KADM_VERSIZE); + if (tmpdat == NULL) { + clr_cli_secrets(); + return KADM_NOMEM; + } + + strncpy((char *)tmpdat, KADM_VERSTR, KADM_VERSIZE); retval = htonl((u_int32_t)retval); - bcopy((char *)&retval, (char *)tmpdat + KADM_VERSIZE, sizeof(u_int32_t)); + memcpy((char *)tmpdat + KADM_VERSIZE, &retval, sizeof(u_int32_t)); if (retlen) { - bcopy((char *)retdat, (char *)tmpdat + KADM_VERSIZE + sizeof(u_int32_t), - retlen); - free((char *)retdat); + memcpy((char *)tmpdat + KADM_VERSIZE + sizeof(u_int32_t), retdat, + retlen); + free(retdat); + retdat = NULL; } /* slop for mk_priv stuff */ *dat = (u_char *) malloc((unsigned) (retlen + KADM_VERSIZE + sizeof(u_int32_t) + 200)); + if (*dat == NULL) { + free(tmpdat); + tmpdat = NULL; + clr_cli_secrets(); + return KADM_NOMEM; + } + if ((*dat_len = krb_mk_priv(tmpdat, *dat, (u_int32_t) (retlen + KADM_VERSIZE + sizeof(u_int32_t)), diff --git a/kerberosIV/kadmind/kadm_server.c b/kerberosIV/kadmind/kadm_server.c index 7412b607c06..a18c2398a39 100644 --- a/kerberosIV/kadmind/kadm_server.c +++ b/kerberosIV/kadmind/kadm_server.c @@ -1,7 +1,8 @@ -/* $Id: kadm_server.c,v 1.1 1995/12/14 06:52:48 tholo Exp $ */ +/* $OpenBSD: kadm_server.c,v 1.2 1997/12/15 17:56:22 art Exp $ */ +/* $KTH: kadm_server.c,v 1.9 1997/05/02 10:29:08 joda Exp $ */ -/*- - * Copyright (C) 1989 by the Massachusetts Institute of Technology +/* + * Copyright (C) 1989 by the Massachusetts Institute of Technology * * Export of this software from the United States of America is assumed * to require a specific license from the United States Government. @@ -18,57 +19,85 @@ * permission. M.I.T. makes no representations about the suitability of * this software for any purpose. It is provided "as is" without express * or implied warranty. + * */ /* * Kerberos administration server-side subroutines */ -#include <kadm_locl.h> +#include "kadm_locl.h" /* -kadm_ser_cpw - the server side of the change_password routine - recieves : KTEXT, {key} - returns : CKSUM, RETCODE - acl : caller can change only own password - -Replaces the password (i.e. des key) of the caller with that specified in key. -Returns no actual data from the master server, since this is called by a user -*/ + *kadm_ser_cpw - the server side of the change_password routine + * recieves : KTEXT, {key} + * returns : CKSUM, RETCODE + * acl : caller can change only own password + * + * Replaces the password (i.e. des key) of the caller with that specified in + * key. Returns no actual data from the master server, since this is called + * by a user + */ int kadm_ser_cpw(u_char *dat, int len, AUTH_DAT *ad, u_char **datout, int *outlen) { u_int32_t keylow, keyhigh; des_cblock newkey; - int stvlen; + int status; + int stvlen=0; + char *pw_msg; + char pword[MAX_KPW_LEN]; + char *strings[4]; /* take key off the stream, and change the database */ - if ((stvlen = stv_long(dat, &keyhigh, 0, len)) < 0) + if ((status = stv_long(dat, &keyhigh, 0, len)) < 0) return(KADM_LENGTH_ERROR); - if (stv_long(dat, &keylow, stvlen, len) < 0) + stvlen=status; + if ((status = stv_long(dat, &keylow, stvlen, len)) < 0) return(KADM_LENGTH_ERROR); + stvlen+=status; + + if((status = stv_string(dat, pword, stvlen, sizeof(pword), len))<0) + pword[0]=0; keylow = ntohl(keylow); keyhigh = ntohl(keyhigh); - bcopy((char *)&keyhigh, (char *)(((int32_t *)newkey) + 1), 4); - bcopy((char *)&keylow, (char *)newkey, 4); - *datout = 0; - *outlen = 0; + memcpy(((char *)newkey) + 4, &keyhigh, 4); + memcpy(newkey, &keylow, 4); + + strings[0] = ad->pname; + strings[1] = ad->pinst; + strings[2] = ad->prealm; + strings[3] = NULL; + status = kadm_pw_check(pword, &newkey, &pw_msg, strings); + + memset(pword, 0, sizeof(pword)); + memset(dat, 0, len); + + if(status != KADM_SUCCESS){ + *datout=malloc(0); + *outlen=vts_string(pw_msg, datout, 0); + return status; + } + *datout=0; + *outlen=0; return(kadm_change(ad->pname, ad->pinst, ad->prealm, newkey)); } + /* -kadm_ser_add - the server side of the add_entry routine - recieves : KTEXT, {values} - returns : CKSUM, RETCODE, {values} - acl : su, sms (as alloc) - -Adds and entry containing values to the database -returns the values of the entry, so if you leave certain fields blank you will - be able to determine the default values they are set to -*/ + * kadm_ser_add - the server side of the add_entry routine + * recieves : KTEXT, {values} + * returns : CKSUM, RETCODE, {values} + * acl : su, sms (as alloc) + * + * Adds and entry containing values to the database + * returns the values of the entry, so if you leave certain fields blank + * you will be able to determine the default values they are set to + * + */ int kadm_ser_add(u_char *dat, int len, AUTH_DAT *ad, u_char **datout, int *outlen) { @@ -88,15 +117,15 @@ kadm_ser_add(u_char *dat, int len, AUTH_DAT *ad, u_char **datout, int *outlen) } /* -kadm_ser_mod - the server side of the mod_entry routine - recieves : KTEXT, {values, values} - returns : CKSUM, RETCODE, {values} - acl : su, sms (as register or dealloc) - -Modifies all entries corresponding to the first values so they match the - second values. -returns the values for the changed entries -*/ + * kadm_ser_mod - the server side of the mod_entry routine + * recieves : KTEXT, {values, values} + * returns : CKSUM, RETCODE, {values} + * acl : su, sms (as register or dealloc) + * + * Modifies all entries corresponding to the first values so they match the + * second values. + * returns the values for the changed entries + */ int kadm_ser_mod(u_char *dat, int len, AUTH_DAT *ad, u_char **datout, int *outlen) { @@ -118,16 +147,34 @@ kadm_ser_mod(u_char *dat, int len, AUTH_DAT *ad, u_char **datout, int *outlen) } } +int +kadm_ser_delete(u_char *dat, int len, AUTH_DAT *ad, + u_char **datout, int *outlen) +{ + Kadm_vals values; + int wh; + int status; + + if((wh = stream_to_vals(dat, &values, len)) < 0) + return KADM_LENGTH_ERROR; + if(wh != len) + return KADM_LENGTH_ERROR; + status = kadm_delete_entry(ad->pname, ad->pinst, ad->prealm, + &values); + *outlen = 0; + return status; +} + /* -kadm_ser_get - recieves : KTEXT, {values, flags} - returns : CKSUM, RETCODE, {count, values, values, values} - acl : su - -gets the fields requested by flags from all entries matching values -returns this data for each matching recipient, after a count of how many such - matches there were -*/ + * kadm_ser_get + * recieves : KTEXT, {values, flags} + * returns : CKSUM, RETCODE, {count, values, values, values} + * acl : su + * + * gets the fields requested by flags from all entries matching values + * returns this data for each matching recipient, after a count of how many + * such matches there were + */ int kadm_ser_get(u_char *dat, int len, AUTH_DAT *ad, u_char **datout, int *outlen) { diff --git a/kerberosIV/kadmind/pw_check.c b/kerberosIV/kadmind/pw_check.c new file mode 100644 index 00000000000..96d9c9ec398 --- /dev/null +++ b/kerberosIV/kadmind/pw_check.c @@ -0,0 +1,88 @@ +/* $OpenBSD: pw_check.c,v 1.1 1997/12/15 17:56:23 art Exp $ */ +/* $KTH: pw_check.c,v 1.13 1997/04/01 08:17:50 joda Exp $ */ + +/* + * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "kadm_locl.h" + +/* + * kadm_pw_check + * + * pw : new password or "" if none passed + * newkey : key for pw as passed from client + * strings : interesting strings to check for + * + * returns NULL if pw is ok, else an explanatory string + */ +int +kadm_pw_check(char *pw, des_cblock *newkey, char **pw_msg, + char **strings) +{ + des_cblock pwkey; + int status=KADM_SUCCESS; + + if (pw == NULL || *pw == '\0') + return status; /* XXX - Change this later */ + +#ifndef NO_PW_CHECK + *pw_msg = NULL; + des_string_to_key(pw, &pwkey); /* Check AFS string to key also! */ + if (memcmp(pwkey, *newkey, sizeof(pwkey)) != 0) + { + /* no password or bad key */ + status=KADM_PW_MISMATCH; + *pw_msg = "Password doesn't match supplied DES key"; + } + else if (strlen(pw) < MIN_KPW_LEN) + { + status = KADM_INSECURE_PW; + *pw_msg="Password is too short"; + } + +#ifdef DICTPATH + *pw_msg = FascistCheck(pw, DICTPATH, strings); + if (*pw_msg) + return KADM_INSECURE_PW; +#endif + + memset(pwkey, 0, sizeof(pwkey)); +#endif + + return status; +} diff --git a/kerberosIV/kdb/krb_cache.c b/kerberosIV/kdb/krb_cache.c index d5d2dc74b7c..56eff40e518 100644 --- a/kerberosIV/kdb/krb_cache.c +++ b/kerberosIV/kdb/krb_cache.c @@ -1,4 +1,4 @@ -/* $OpenBSD: krb_cache.c,v 1.3 1997/12/12 11:29:24 art Exp $ */ +/* $OpenBSD: krb_cache.c,v 1.4 1997/12/15 17:56:23 art Exp $ */ /* $KTH: krb_cache.c,v 1.6 1997/05/02 10:27:53 joda Exp $ */ /* @@ -59,7 +59,7 @@ kerb_cache_get_principal(char *serv, char *inst, Principal *principal, unsigned { int found = 0; - if (init == 0) + if (!init) kerb_cache_init(); #ifdef DEBUG if (kerb_debug & 2) @@ -96,7 +96,7 @@ kerb_cache_put_principal(Principal *principal, unsigned int max) u_long i; int count = 0; - if (init == 0) + if (!init) kerb_cache_init(); #ifdef DEBUG @@ -133,7 +133,7 @@ kerb_cache_get_dba(char *serv, char *inst, Dba *dba, unsigned int max) { int found = 0; - if (init == 0) + if (!init) kerb_cache_init(); #ifdef DEBUG diff --git a/kerberosIV/krb/kntoln.c b/kerberosIV/krb/kntoln.c index f7f28c98181..2e7cc271ac5 100644 --- a/kerberosIV/krb/kntoln.c +++ b/kerberosIV/krb/kntoln.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kntoln.c,v 1.3 1997/12/09 07:57:23 art Exp $ */ +/* $OpenBSD: kntoln.c,v 1.4 1997/12/15 17:56:24 art Exp $ */ /* $KTH: kntoln.c,v 1.7 1997/03/23 03:53:12 joda Exp $ */ /* @@ -159,7 +159,7 @@ an_to_a(AUTH_DAT *ad, * into a struct AUTH_DAT. */ int -a_to_an(cahr *str, AUTH_DAT *ad) +a_to_an(char *str, AUTH_DAT *ad) { char *buf = (char *)malloc(strlen(str)+1); char *rlm, *inst, *princ; diff --git a/kerberosIV/sl/Makefile b/kerberosIV/sl/Makefile new file mode 100644 index 00000000000..8dc29995b9f --- /dev/null +++ b/kerberosIV/sl/Makefile @@ -0,0 +1,8 @@ +# from @(#)Makefile 8.1 (Berkeley) 6/1/93 +# $Id: Makefile,v 1.1 1997/12/15 17:56:25 art Exp $ + +LIB= sl +CFLAGS+=-I${.CURDIR} +SRCS= sl.c + +.include <bsd.lib.mk> diff --git a/kerberosIV/sl/sl.c b/kerberosIV/sl/sl.c new file mode 100644 index 00000000000..48e51a2b8c6 --- /dev/null +++ b/kerberosIV/sl/sl.c @@ -0,0 +1,200 @@ +/* $KTH: sl.c,v 1.15 1997/10/19 23:12:40 assar Exp $ */ + +/* + * Copyright (c) 1995, 1996, 1997 Kungliga Tekniska Högskolan + * (Royal Institute of Technology, Stockholm, Sweden). + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the Kungliga Tekniska + * Högskolan and its contributors. + * + * 4. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "sl_locl.h" + +static SL_cmd * +sl_match (SL_cmd *cmds, char *cmd, int exactp) +{ + SL_cmd *c, *current = NULL, *partial_cmd = NULL; + int partial_match = 0; + + for (c = cmds; c->name; ++c) { + if (c->func) + current = c; + if (strcmp (cmd, c->name) == 0) + return current; + else if (strncmp (cmd, c->name, strlen(cmd)) == 0 && + partial_cmd != current) { + ++partial_match; + partial_cmd = current; + } + } + if (partial_match == 1 && !exactp) + return partial_cmd; + else + return NULL; +} + +void +sl_help (SL_cmd *cmds, int argc, char **argv) +{ + SL_cmd *c, *prev_c; + + if (argc == 1) { + prev_c = NULL; + for (c = cmds; c->name; ++c) { + if (c->func) { + if(prev_c) + printf ("\n\t%s%s", prev_c->usage ? prev_c->usage : "", + prev_c->usage ? "\n" : ""); + prev_c = c; + printf ("%s", c->name); + } else + printf (", %s", c->name); + } + if(prev_c) + printf ("\n\t%s%s", prev_c->usage ? prev_c->usage : "", + prev_c->usage ? "\n" : ""); + } else { + c = sl_match (cmds, argv[1], 0); + if (c == NULL) + printf ("No such command: %s. " + "Try \"help\" for a list of all commands\n", + argv[1]); + else { + printf ("%s\t%s", c->name, c->usage); + if(c->help && *c->help) + printf ("%s\n", c->help); + if((++c)->name && c->func == NULL) { + printf ("\nSynonyms:"); + while (c->name && c->func == NULL) + printf ("\t%s", (c++)->name); + } + printf ("\n"); + } + } +} + +static char * +readline(char *prompt) +{ + char buf[BUFSIZ]; + printf ("%s", prompt); + fflush (stdout); + if(fgets(buf, sizeof(buf), stdin) == NULL) + return NULL; + if (buf[strlen(buf) - 1] == '\n') + buf[strlen(buf) - 1] = '\0'; + return strdup(buf); +} + +static void +add_history(char *p) +{ +} + +int +sl_command(SL_cmd *cmds, int argc, char **argv) +{ + SL_cmd *c; + c = sl_match (cmds, argv[0], 0); + if (c == NULL) + return -1; + return (*c->func)(argc, argv); +} + +int +sl_loop (SL_cmd *cmds, char *prompt) +{ + unsigned max_count; + char **ptr; + int ret; + + max_count = 17; + ptr = malloc(max_count * sizeof(*ptr)); + if (ptr == NULL) { + printf ("sl_loop: failed to allocate %u bytes of memory\n", + (int) max_count * sizeof(*ptr)); + return -1; + } + + for (;;) { + char *buf; + unsigned count; + SL_cmd *c; + + ret = 0; + buf = readline(prompt); + if(buf == NULL) + break; + + if(*buf) + add_history(buf); + count = 0; + { + char *foo = NULL; + char *p; + + for(p = strtok_r (buf, " \t", &foo); + p; + p = strtok_r (NULL, " \t", &foo)) { + if(count == max_count) { + max_count *= 2; + ptr = realloc (ptr, max_count * sizeof(*ptr)); + if (ptr == NULL) { + printf ("sl_loop: failed to allocate %u " + "bytes of memory\n", + (unsigned) max_count * sizeof(*ptr)); + return -1; + } + } + ptr[count++] = p; + } + } + if (count > 0) { + c = sl_match (cmds, ptr[0], 0); + if (c) { + ret = (*c->func)(count, ptr); + if (ret != 0) { + free (buf); + buf = NULL; + break; + } + } else + printf ("Unrecognized command: %s\n", ptr[0]); + } + free(buf); + buf = NULL; + } + free (ptr); + ptr = NULL; + return 0; +} |