From fb0a5101fdeb73f2da8ddcd3e1f542ce893420c1 Mon Sep 17 00:00:00 2001 From: no author Date: Mon, 4 Nov 2002 21:39:12 +0000 Subject: This commit was manufactured by cvs2svn to create tag 'krb5-1-2-7-beta1'. git-svn-id: svn://anonsvn.mit.edu/krb5/tags/krb5-1-2-7-beta1@14968 dc483132-0cff-0310-8789-dd5450dbe970 --- README | 651 +- doc/ChangeLog | 88 + doc/admin.texinfo | 202 +- doc/api/ChangeLog | 4 + doc/api/Makefile | 2 +- doc/build.texinfo | 81 +- doc/copyright.texinfo | 2 +- doc/definitions.texinfo | 4 +- doc/install.texinfo | 223 +- doc/krb425.texinfo | 8 + doc/send-pr.texinfo | 6 +- src/ChangeLog | 118 + src/Makefile.in | 22 +- src/acconfig.h | 2 + src/aclocal.m4 | 149 +- src/appl/bsd/ChangeLog | 220 + src/appl/bsd/Makefile.in | 1 + src/appl/bsd/configure.in | 14 +- src/appl/bsd/defines.h | 44 +- src/appl/bsd/forward.c | 2 +- src/appl/bsd/kcmd.c | 197 +- src/appl/bsd/krcp.c | 131 +- src/appl/bsd/krlogin.c | 316 +- src/appl/bsd/krlogind.c | 84 +- src/appl/bsd/krsh.c | 57 +- src/appl/bsd/krshd.c | 83 +- src/appl/bsd/login.M | 2 +- src/appl/bsd/login.c | 105 +- src/appl/bsd/loginpaths.h | 2 + src/appl/bsd/rcp.M | 12 + src/appl/bsd/rlogin.M | 11 + src/appl/bsd/rsh.M | 11 + src/appl/bsd/v4rcp.c | 24 +- src/appl/gssftp/ChangeLog | 9 + src/appl/gssftp/configure.in | 4 +- src/appl/gssftp/ftp/ChangeLog | 47 + src/appl/gssftp/ftp/cmds.c | 23 +- src/appl/gssftp/ftp/domacro.c | 18 +- src/appl/gssftp/ftp/ftp.c | 48 +- src/appl/gssftp/ftp/glob.c | 20 +- src/appl/gssftp/ftp/main.c | 3 +- src/appl/gssftp/ftp/secure.c | 97 +- src/appl/gssftp/ftpd/ChangeLog | 59 + src/appl/gssftp/ftpd/ftpcmd.y | 97 +- src/appl/gssftp/ftpd/ftpd.c | 198 +- src/appl/sample/sclient/ChangeLog | 6 + src/appl/sample/sclient/sclient.c | 2 +- src/appl/telnet/libtelnet/ChangeLog | 33 + src/appl/telnet/libtelnet/configure.in | 8 +- src/appl/telnet/libtelnet/gettytab.c | 5 +- src/appl/telnet/libtelnet/kerberos.c | 16 +- src/appl/telnet/libtelnet/kerberos5.c | 47 +- src/appl/telnet/libtelnet/setenv.c | 6 + src/appl/telnet/libtelnet/spx.c | 20 +- src/appl/telnet/telnet/ChangeLog | 15 + src/appl/telnet/telnet/commands.c | 15 +- src/appl/telnet/telnet/externs.h | 2 +- src/appl/telnet/telnet/main.c | 3 +- src/appl/telnet/telnet/tn3270.c | 7 +- src/appl/telnet/telnet/utilities.c | 6 +- src/appl/telnet/telnetd/ChangeLog | 67 + src/appl/telnet/telnetd/authenc.c | 17 +- src/appl/telnet/telnetd/configure.in | 2 +- src/appl/telnet/telnetd/ext.h | 9 +- src/appl/telnet/telnetd/slc.c | 2 +- src/appl/telnet/telnetd/state.c | 39 +- src/appl/telnet/telnetd/sys_term.c | 1 + src/appl/telnet/telnetd/telnetd-ktd.c | 53 +- src/appl/telnet/telnetd/telnetd.c | 74 +- src/appl/telnet/telnetd/termstat.c | 20 +- src/appl/telnet/telnetd/utility.c | 682 +- src/clients/ChangeLog | 10 + src/clients/configure.in | 7 +- src/clients/kinit/ChangeLog | 5 + src/clients/kinit/kinit.c | 2 +- src/clients/klist/ChangeLog | 12 + src/clients/klist/Makefile.in | 2 +- src/clients/klist/klist.c | 28 +- src/clients/ksu/ChangeLog | 41 + src/clients/ksu/Makefile.in | 3 +- src/clients/ksu/authorization.c | 7 +- src/clients/ksu/ccache.c | 6 +- src/clients/ksu/ksu.M | 30 +- src/clients/ksu/main.c | 227 +- src/clients/ksu/setenv.c | 9 +- src/config-files/ChangeLog | 10 + src/config-files/krb5.conf.M | 23 +- src/config/ChangeLog | 26 + src/config/config.guess | 645 +- src/config/config.sub | 444 +- src/config/libobj.in | 4 +- src/config/pre.in | 2 +- src/config/win-pre.in | 22 +- src/configure.in | 13 + src/include/ChangeLog | 165 + src/include/k5-int.h | 101 +- src/include/kerberosIV/ChangeLog | 15 + src/include/kerberosIV/krb.h | 6 +- src/include/krb5.hin | 376 +- src/include/krb5/ChangeLog | 25 + src/include/krb5/adm.h | 5 +- src/include/krb5/kdb.h | 2 +- src/include/krb5/macsock.h | 8 +- src/include/krb5/stock/ChangeLog | 4 + src/include/krb5/stock/osconf.h | 4 + src/include/win-mac.h | 173 +- src/kadmin/cli/ChangeLog | 25 + src/kadmin/cli/kadmin.M | 69 +- src/kadmin/cli/kadmin.c | 10 +- src/kadmin/cli/strftime.c | 881 +- src/kadmin/dbutil/ChangeLog | 42 + src/kadmin/dbutil/dump.c | 100 +- src/kadmin/dbutil/kdb5_util.M | 86 +- src/kadmin/dbutil/kdb5_util.c | 8 +- src/kadmin/dbutil/loadv4.c | 22 +- src/kadmin/ktutil/ChangeLog | 11 + src/kadmin/ktutil/ktutil_funcs.c | 19 +- src/kadmin/passwd/ChangeLog | 4 + src/kadmin/passwd/xm_kpasswd.c | 10 +- src/kadmin/server/ChangeLog | 30 + src/kadmin/server/misc.c | 41 +- src/kadmin/server/schpw.c | 2 +- src/kadmin/server/server_stubs.c | 91 +- src/kadmin/testing/proto/ChangeLog | 10 + src/kadmin/testing/proto/kdc.conf.proto | 5 +- src/kadmin/testing/proto/krb5.conf.proto | 1 + src/kadmin/testing/util/ChangeLog | 11 + src/kadmin/testing/util/tcl_kadm5.c | 5 +- src/kadmin/testing/util/tcl_ovsec_kadm.c | 2 +- src/kadmin/v4server/ChangeLog | 39 + src/kadmin/v4server/acl_files.c | 74 +- src/kadmin/v4server/admin_server.c | 4 + src/kadmin/v4server/kadm_err.et | 1 + src/kadmin/v4server/kadm_ser_wrap.c | 19 +- src/kadmin/v4server/kadm_server.c | 3 +- src/kadmin/v5passwdd/ChangeLog | 18 + src/kadmin/v5passwdd/kadm5_defs.h | 3 +- src/kadmin/v5passwdd/main.c | 5 +- src/kadmin/v5passwdd/proto_serv.c | 15 +- src/kdc/ChangeLog | 138 + src/kdc/do_as_req.c | 30 +- src/kdc/do_tgs_req.c | 99 +- src/kdc/extern.h | 6 +- src/kdc/kdc_preauth.c | 2 +- src/kdc/kdc_util.c | 129 +- src/kdc/kdc_util.h | 6 + src/kdc/kerberos_v4.c | 74 +- src/kdc/main.c | 10 +- src/kdc/network.c | 95 +- src/kdc/rtest.c | 1 + src/krb5-config.in | 213 + src/krb524/ChangeLog | 75 + src/krb524/README | 33 + src/krb524/RELEASE_NOTES | 16 - src/krb524/cnv_tkt_skey.c | 9 +- src/krb524/conv_creds.c | 32 +- src/krb524/conv_princ.c | 7 +- src/krb524/encode.c | 5 + src/krb524/krb524.h | 48 +- src/krb524/krb524d.c | 252 +- src/krb524/misc.c | 5 + src/krb524/sendmsg.c | 25 +- src/lib/ChangeLog | 60 + src/lib/crypto/ChangeLog | 21 + src/lib/crypto/Makefile.in | 4 +- src/lib/crypto/coll_proof_cksum.c | 9 +- src/lib/crypto/crypto_libinit.h | 6 +- src/lib/crypto/des/ChangeLog | 18 + src/lib/crypto/des/afsstring2key.c | 58 +- src/lib/crypto/des/des_int.h | 2 +- src/lib/crypto/des/string2key.c | 3 + src/lib/crypto/dk/ChangeLog | 14 + src/lib/crypto/dk/derive.c | 4 +- src/lib/crypto/dk/dk_decrypt.c | 20 +- src/lib/crypto/dk/dk_encrypt.c | 30 +- src/lib/crypto/keyed_cksum.c | 8 +- src/lib/crypto/make_checksum.c | 1 + src/lib/crypto/old/ChangeLog | 6 + src/lib/crypto/old/old_decrypt.c | 19 +- src/lib/crypto/old/old_encrypt.c | 9 +- src/lib/crypto/prng.c | 2 +- src/lib/crypto/sha1/ChangeLog | 23 + src/lib/crypto/sha1/Makefile.in | 21 +- src/lib/crypto/sha1/shs.c | 75 +- src/lib/crypto/sha1/shs.h | 19 +- src/lib/crypto/sha1/t_shs.c | 12 +- src/lib/crypto/sha1/t_shs3.c | 583 ++ src/lib/crypto/valid_cksumtype.c | 8 +- src/lib/crypto/valid_enctype.c | 8 +- src/lib/gssapi/ChangeLog | 13 + src/lib/gssapi/Makefile.in | 2 +- src/lib/gssapi/generic/ChangeLog | 47 + src/lib/gssapi/generic/disp_com_err_status.c | 5 + src/lib/gssapi/generic/gssapi.hin | 148 +- src/lib/gssapi/generic/gssapiP_generic.h | 34 +- src/lib/gssapi/generic/gssapi_generic.c | 118 +- src/lib/gssapi/generic/gssapi_generic.h | 22 +- src/lib/gssapi/gss_libinit.c | 8 + src/lib/gssapi/krb5/3des.txt | 274 + src/lib/gssapi/krb5/ChangeLog | 193 +- src/lib/gssapi/krb5/accept_sec_context.c | 508 +- src/lib/gssapi/krb5/acquire_cred.c | 44 +- src/lib/gssapi/krb5/add_cred.c | 46 +- src/lib/gssapi/krb5/disp_status.c | 5 + src/lib/gssapi/krb5/gssapiP_krb5.h | 85 +- src/lib/gssapi/krb5/gssapi_krb5.c | 23 +- src/lib/gssapi/krb5/gssapi_krb5.h | 54 +- src/lib/gssapi/krb5/import_sec_context.c | 2 +- src/lib/gssapi/krb5/init_sec_context.c | 523 +- src/lib/gssapi/krb5/inq_cred.c | 32 +- src/lib/gssapi/krb5/k5seal.c | 852 +- src/lib/gssapi/krb5/k5unseal.c | 1086 +-- src/lib/gssapi/krb5/ser_sctx.c | 6 - src/lib/gssapi/krb5/util_cksum.c | 1 + src/lib/gssapi/krb5/util_crypt.c | 36 +- src/lib/gssapi/krb5/util_seed.c | 2 +- src/lib/gssapi/krb5/util_seqnum.c | 4 +- src/lib/gssapi/krb5/wrap_size_limit.c | 131 +- src/lib/gssapi32.def | 8 +- src/lib/kadm5/ChangeLog | 53 + src/lib/kadm5/adb.h | 1 + src/lib/kadm5/admin.h | 32 +- src/lib/kadm5/admin_internal.h | 3 +- src/lib/kadm5/alt_prof.c | 73 +- src/lib/kadm5/chpass_util.c | 60 +- src/lib/kadm5/clnt/ChangeLog | 20 + src/lib/kadm5/clnt/Makefile.in | 2 +- src/lib/kadm5/clnt/client_init.c | 8 + src/lib/kadm5/clnt/clnt_chpass_util.c | 5 +- src/lib/kadm5/kadm_rpc_xdr.c | 10 +- src/lib/kadm5/logger.c | 5 +- src/lib/kadm5/ovsec_glue.c | 6 +- src/lib/kadm5/srv/ChangeLog | 36 + src/lib/kadm5/srv/Makefile.in | 2 +- src/lib/kadm5/srv/adb_openclose.c | 57 +- src/lib/kadm5/srv/svr_chpass_util.c | 5 +- src/lib/kadm5/srv/svr_principal.c | 42 + src/lib/kadm5/str_conv.c | 17 +- src/lib/kadm5/unit-test/ChangeLog | 13 + .../kadm5/unit-test/api.2/chpass-principal-v2.exp | 4 +- src/lib/kadm5/unit-test/api.2/get-principal-v2.exp | 4 +- .../kadm5/unit-test/api.2/randkey-principal-v2.exp | 4 +- src/lib/kadm5/unit-test/config/unix.exp | 8 + src/lib/kdb/ChangeLog | 65 + src/lib/kdb/Makefile.in | 2 +- src/lib/kdb/fetch_mkey.c | 2 +- src/lib/kdb/kdb_db2.c | 38 +- src/lib/kdb/kdb_db2.h | 6 + src/lib/kdb/kdb_xdr.c | 16 +- src/lib/kdb/keytab.c | 13 + src/lib/kdb/setup_mkey.c | 2 +- src/lib/kdb/store_mkey.c | 2 +- src/lib/kdb/t_kdb.c | 47 +- src/lib/krb4/ChangeLog | 103 + src/lib/krb4/Password.c | 9 +- src/lib/krb4/configure.in | 2 +- src/lib/krb4/cr_auth_repl.c | 10 + src/lib/krb4/cr_ciph.c | 11 + src/lib/krb4/cr_death_pkt.c | 5 +- src/lib/krb4/cr_err_repl.c | 9 + src/lib/krb4/cr_tkt.c | 18 + src/lib/krb4/decomp_tkt.c | 16 +- src/lib/krb4/dest_tkt.c | 127 +- src/lib/krb4/g_ad_tkt.c | 45 +- src/lib/krb4/g_in_tkt.c | 14 + src/lib/krb4/g_krbhst.c | 8 +- src/lib/krb4/g_krbrlm.c | 3 +- src/lib/krb4/g_pw_in_tkt.c | 1 - src/lib/krb4/in_tkt.c | 92 +- src/lib/krb4/kntoln.c | 7 +- src/lib/krb4/kparse.c | 73 +- src/lib/krb4/kuserok.c | 7 +- src/lib/krb4/mk_auth.c | 6 +- src/lib/krb4/mk_err.c | 8 + src/lib/krb4/mk_req.c | 13 + src/lib/krb4/rd_req.c | 44 +- src/lib/krb4/rd_svc_key.c | 8 +- src/lib/krb4/realmofhost.c | 8 +- src/lib/krb4/recvauth.c | 7 +- src/lib/krb4/send_to_kdc.c | 3 +- src/lib/krb4/sendauth.c | 3 +- src/lib/krb4/tf_util.c | 123 +- src/lib/krb4/win_store.c | 20 +- src/lib/krb5/ChangeLog | 38 + src/lib/krb5/Makefile.in | 6 +- src/lib/krb5/asn.1/ChangeLog | 91 + src/lib/krb5/asn.1/asn1_encode.c | 12 +- src/lib/krb5/asn.1/asn1_get.c | 9 +- src/lib/krb5/asn.1/asn1_k_decode.c | 97 +- src/lib/krb5/asn.1/asn1buf.c | 71 +- src/lib/krb5/asn.1/asn1buf.h | 15 +- src/lib/krb5/asn.1/krb5_decode.c | 30 +- src/lib/krb5/ccache/ChangeLog | 61 + src/lib/krb5/ccache/Makefile.in | 3 + src/lib/krb5/ccache/ccapi/ChangeLog | 90 + src/lib/krb5/ccache/ccapi/stdcc.c | 8 +- src/lib/krb5/ccache/ccapi/stdcc.h | 6 +- src/lib/krb5/ccache/ccapi/stdcc_util.c | 717 +- src/lib/krb5/ccache/ccapi/stdcc_util.h | 13 +- src/lib/krb5/ccache/ccapi/winccld.c | 3 + src/lib/krb5/ccache/ccapi/winccld.h | 54 + src/lib/krb5/ccache/ccdefault.c | 84 +- src/lib/krb5/ccache/ccdefops.c | 2 +- src/lib/krb5/ccache/ccfns.c | 131 + src/lib/krb5/ccache/file/ChangeLog | 3 + src/lib/krb5/ccache/file/fcc_gprin.c | 1 - src/lib/krb5/ccache/stdio/ChangeLog | 3 + src/lib/krb5/ccache/stdio/scc_skip.c | 1 - src/lib/krb5/error_tables/ChangeLog | 16 + src/lib/krb5/error_tables/asn1_err.et | 2 + src/lib/krb5/error_tables/kdb5_err.et | 2 + src/lib/krb5/error_tables/krb5_err.et | 8 +- src/lib/krb5/keytab/ChangeLog | 17 + src/lib/krb5/keytab/Makefile.in | 2 + src/lib/krb5/keytab/file/ChangeLog | 13 + src/lib/krb5/keytab/file/ktf_g_ent.c | 34 +- src/lib/krb5/keytab/ktfns.c | 80 + src/lib/krb5/keytab/ktfr_entry.c | 10 +- src/lib/krb5/keytab/srvtab/ChangeLog | 10 +- src/lib/krb5/keytab/srvtab/kts_g_ent.c | 1 + src/lib/krb5/keytab/srvtab/kts_util.c | 2 +- src/lib/krb5/krb/ChangeLog | 284 + src/lib/krb5/krb/Makefile.in | 8 + src/lib/krb5/krb/addr_comp.c | 2 +- src/lib/krb5/krb/addr_order.c | 2 +- src/lib/krb5/krb/appdefault.c | 183 + src/lib/krb5/krb/auth_con.c | 6 +- src/lib/krb5/krb/bld_princ.c | 1 + src/lib/krb5/krb/chk_trans.c | 497 +- src/lib/krb5/krb/conv_princ.c | 126 +- src/lib/krb5/krb/fwd_tgt.c | 38 +- src/lib/krb5/krb/get_creds.c | 23 +- src/lib/krb5/krb/get_in_tkt.c | 69 +- src/lib/krb5/krb/gic_keytab.c | 16 +- src/lib/krb5/krb/gic_pwd.c | 28 +- src/lib/krb5/krb/init_ctx.c | 45 +- src/lib/krb5/krb/init_keyblock.c | 61 + src/lib/krb5/krb/kfree.c | 129 +- src/lib/krb5/krb/mk_cred.c | 2 +- src/lib/krb5/krb/mk_priv.c | 8 - src/lib/krb5/krb/mk_req_ext.c | 16 +- src/lib/krb5/krb/mk_safe.c | 29 +- src/lib/krb5/krb/parse.c | 2 +- src/lib/krb5/krb/preauth.c | 5 +- src/lib/krb5/krb/preauth2.c | 8 + src/lib/krb5/krb/princ_comp.c | 2 +- src/lib/krb5/krb/rd_cred.c | 89 +- src/lib/krb5/krb/rd_priv.c | 9 +- src/lib/krb5/krb/rd_req_dec.c | 4 +- src/lib/krb5/krb/rd_safe.c | 2 +- src/lib/krb5/krb/recvauth.c | 69 +- src/lib/krb5/krb/send_tgs.c | 1 - src/lib/krb5/krb/sendauth.c | 32 +- src/lib/krb5/krb/ser_actx.c | 10 +- src/lib/krb5/krb/t_kerb.c | 32 + src/lib/krb5/krb/t_krb5.conf | 6 + src/lib/krb5/krb/t_ref_kerb.out | 2 + src/lib/krb5/krb/unparse.c | 3 + src/lib/krb5/krb/vfy_increds.c | 2 +- src/lib/krb5/krb/walk_rtree.c | 25 + src/lib/krb5/krb5_libinit.c | 10 +- src/lib/krb5/os/ChangeLog | 209 + src/lib/krb5/os/an_to_ln.c | 22 +- src/lib/krb5/os/c_ustime.c | 141 +- src/lib/krb5/os/ccdefname.c | 15 +- src/lib/krb5/os/changepw.c | 61 +- src/lib/krb5/os/def_realm.c | 13 +- src/lib/krb5/os/gmt_mktime.c | 2 +- src/lib/krb5/os/hst_realm.c | 19 +- src/lib/krb5/os/init_os_ctx.c | 80 +- src/lib/krb5/os/kuserok.c | 5 +- src/lib/krb5/os/localaddr.c | 233 +- src/lib/krb5/os/locate_kdc.c | 148 +- src/lib/krb5/os/os-proto.h | 3 +- src/lib/krb5/os/prompter.c | 14 +- src/lib/krb5/os/promptusr.c | 2 +- src/lib/krb5/os/sendto_kdc.c | 26 +- src/lib/krb5/os/t_std_conf.c | 4 +- src/lib/krb5/os/timeofday.c | 6 +- src/lib/krb5/os/toffset.c | 2 +- src/lib/krb5/posix/ChangeLog | 11 + src/lib/krb5/posix/setenv.c | 2 + src/lib/krb5/posix/syslog.c | 10 +- src/lib/krb5/rcache/ChangeLog | 22 + src/lib/krb5/rcache/rc_dfl.c | 2 +- src/lib/krb5/rcache/rc_io.c | 27 +- src/lib/krb5_32.def | 342 +- src/lib/krb5util/ChangeLog | 5 + src/lib/krb5util/compat_recv.c | 145 + src/lib/rpc/ChangeLog | 58 + src/lib/rpc/auth_gssapi_misc.c | 16 +- src/lib/rpc/clnt_perror.c | 98 +- src/lib/rpc/clnt_simple.c | 5 +- src/lib/rpc/clnt_tcp.c | 2 +- src/lib/rpc/clnt_udp.c | 2 +- src/lib/rpc/configure.in | 2 + src/lib/rpc/get_myaddress.c | 2 +- src/lib/rpc/pmap_rmt.c | 11 +- src/lib/rpc/svc_auth_gssapi.c | 16 +- src/lib/rpc/unit-test/ChangeLog | 11 + src/lib/rpc/unit-test/lib/helpers.exp | 6 +- src/lib/rpc/unit-test/server.c | 1 + src/lib/rpc/xdr.c | 2 +- src/lib/rpc/xdr_array.c | 3 +- src/lib/win_glue.c | 34 +- src/mac/CFMGlue.pl | 2 - src/mac/DylibStub.c | 5 + src/mac/ErrorTables.jam | 120 + src/mac/GSS.CFM.c | 23 +- src/mac/GSS.h | 7 + src/mac/GSSKerberos5.pbproj/project.pbxproj | 9269 ++++++++++++++++++++ src/mac/GSSKerberosPrefix.h | 69 + src/mac/GSSLibrary.exp | 29 +- src/mac/GSSLibrary.pbexp | 96 + src/mac/GenerateErrorTables.sh | 40 + src/mac/GenerateHeaderFiles.sh | 48 + src/mac/HeaderFiles.jam | 210 + src/mac/K5.CFM.c | 15 +- src/mac/K5.CFMglue.proto.h | 86 - src/mac/K5Library.exp | 86 +- src/mac/Kerberos5CoreExport.jam | 21 + src/mac/Kerberos5Lib.exp | 225 + src/mac/Kerberos5Lib.pbexp | 225 + src/mac/Kerberos5PrivateLib.pbexp | 36 + src/mac/MacOSX/Headers/GSSInit.h | 22 + src/mac/MacOSX/Headers/Kerberos5Init.h | 22 + src/mac/MacOSX/Headers/Kerberos5Prefix.h | 87 + src/mac/MacOSX/Headers/KerberosProfileInit.h | 22 + src/mac/MacOSX/Headers/cr_tkt.h | 32 + src/mac/MacOSX/Projects/GSS.pbexp | 96 + src/mac/MacOSX/Projects/Kerberos5.pbexp | 331 + .../Projects/Kerberos5.pbproj/project.pbxproj | 7034 +++++++++++++++ src/mac/MacOSX/Projects/Kerberos524.pbexp | 1 + src/mac/MacOSX/Scripts/Kerberos5Errors.jam | 86 + src/mac/MacOSX/Scripts/Kerberos5Headers.jam | 113 + src/mac/MacOSX/Sources/GSSInit.cp | 32 + src/mac/MacOSX/Sources/Kerberos5Init.cp | 45 + src/mac/MacOSX/Sources/ProfileInit.cp | 50 + src/mac/MacOSX/Sources/cr_tkt.c | 254 + src/mac/Makefile | 1074 ++- src/mac/PrivateKerberos5Lib.exp | 36 + src/mac/ProfileLib.CFM.c | 17 +- src/mac/Release notes | 167 +- src/mac/kdestroy.c | 293 + src/mac/kinit.c | 1137 +++ src/mac/klist.c | 912 ++ src/mac/kpasswd.c | 151 + src/mac/libraries/KerberosHeaders.9.pch | 2 + src/mac/libraries/KerberosHeaders.CB.pch | 4 + src/mac/libraries/KerberosHeaders.h | 11 +- src/mac/macfile_gen.pl | 191 +- src/slave/ChangeLog | 6 + src/slave/kprop.c | 15 +- src/tests/ChangeLog | 18 + src/tests/asn.1/ChangeLog | 14 + src/tests/asn.1/krb5_decode_test.c | 116 +- src/tests/asn.1/utility.c | 6 +- src/tests/configure.in | 11 +- src/tests/create/ChangeLog | 10 + src/tests/create/kdb5_mkdums.c | 8 +- src/tests/dejagnu/ChangeLog | 6 + src/tests/dejagnu/Makefile.in | 3 +- src/tests/dejagnu/config/ChangeLog | 202 + src/tests/dejagnu/config/default.exp | 2009 ++++- src/tests/dejagnu/krb-root/ChangeLog | 6 + src/tests/dejagnu/krb-root/rlogin.exp | 10 +- src/tests/dejagnu/krb-standalone/ChangeLog | 195 + src/tests/dejagnu/krb-standalone/gssapi.exp | 478 +- src/tests/dejagnu/krb-standalone/gssftp.exp | 105 +- src/tests/dejagnu/krb-standalone/kadmin.exp | 323 +- src/tests/dejagnu/krb-standalone/rcp.exp | 13 +- src/tests/dejagnu/krb-standalone/rsh.exp | 26 +- src/tests/dejagnu/krb-standalone/standalone.exp | 132 +- src/tests/dejagnu/krb-standalone/v4gssftp.exp | 497 ++ src/tests/dejagnu/krb-standalone/v4krb524d.exp | 163 + src/tests/dejagnu/krb-standalone/v4standalone.exp | 90 + src/tests/hammer/ChangeLog | 9 + src/tests/hammer/kdc5_hammer.c | 13 +- src/tests/verify/ChangeLog | 9 + src/tests/verify/kdb5_verify.c | 7 +- src/util/ChangeLog | 19 + src/util/Makefile.in | 2 +- src/util/db2/ChangeLog | 47 + src/util/db2/btree/bt_close.c | 3 +- src/util/db2/btree/bt_debug.c | 21 +- src/util/db2/btree/bt_page.c | 2 + src/util/db2/btree/bt_seq.c | 410 + src/util/db2/btree/bt_split.c | 5 +- src/util/db2/btree/extern.h | 13 +- src/util/db2/hash/dbm.c | 5 +- src/util/db2/hash/hash_debug.c | 1 - src/util/db2/include/ChangeLog | 6 + src/util/db2/include/db.h | 2 + src/util/db2/test/ChangeLog | 14 + src/util/db2/test/btree.tests/ChangeLog | 14 + src/util/db2/test/btree.tests/main.c | 83 +- src/util/db2/test/dbtest.c | 14 +- src/util/db2/test/run.test | 19 +- src/util/et/ChangeLog | 52 + src/util/et/com_err.c | 11 +- src/util/et/com_err.h | 6 +- src/util/et/error_message.c | 16 +- src/util/et/et.pbexp | 10 + src/util/et/et_c.awk | 4 +- src/util/et/et_c.perl | 316 - src/util/et/et_c.pl | 310 + src/util/et/et_h.awk | 6 +- src/util/et/et_h.perl | 219 - src/util/et/et_h.pl | 221 + src/util/et/test_et.c | 4 + src/util/makeshlib.sh | 8 +- src/util/mkrel | 34 +- src/util/profile/ChangeLog | 32 + src/util/profile/Makefile.in | 2 +- src/util/profile/krb5.conf | 8 +- src/util/profile/prof_err.et | 6 + src/util/profile/prof_parse.c | 6 +- src/util/profile/profile.pbexp | 24 + src/util/pty/ChangeLog | 166 + src/util/pty/Makefile.in | 12 +- src/util/pty/cleanup.c | 6 +- src/util/pty/configure.in | 163 +- src/util/pty/dump-utmp.c | 362 +- src/util/pty/getpty.c | 17 +- src/util/pty/libpty.h | 24 +- src/util/pty/logwtmp.c | 93 +- src/util/pty/open_ctty.c | 44 +- src/util/pty/open_slave.c | 108 +- src/util/pty/pty-int.h | 28 +- src/util/pty/pty_paranoia.c | 650 ++ src/util/pty/sane_hostname.c | 4 +- src/util/pty/update_utmp.c | 781 +- src/util/pty/update_wtmp.c | 141 +- src/util/pty/void_assoc.c | 37 +- src/util/ss/ChangeLog | 8 + src/util/ss/help.c | 14 +- src/util/ss/list_rqs.c | 13 +- src/util/ss/mk_cmds.c | 5 +- src/util/ss/utils.c | 11 +- src/wconfig.c | 7 + src/windows/ChangeLog | 71 + src/windows/Makefile.in | 6 + src/windows/README | 48 +- src/windows/cns/ChangeLog | 14 + src/windows/cns/cns.c | 34 +- src/windows/cns/cns_reg.c | 8 +- src/windows/cns/tktlist.c | 23 +- src/windows/lib/ChangeLog | 4 + src/windows/lib/cacheapi.h | 455 +- src/windows/ms2mit/ChangeLog | 8 + src/windows/ms2mit/Makefile.in | 22 + src/windows/ms2mit/ms2mit.c | 560 ++ src/windows/version.rc | 18 +- src/windows/wintel/ChangeLog | 6 + src/windows/wintel/auth.c | 17 +- src/windows/wintel/encrypt.c | 5 +- 556 files changed, 46121 insertions(+), 9570 deletions(-) create mode 100644 src/krb5-config.in delete mode 100644 src/krb524/RELEASE_NOTES create mode 100644 src/lib/crypto/sha1/t_shs3.c create mode 100644 src/lib/gssapi/krb5/3des.txt create mode 100644 src/lib/krb5/ccache/ccfns.c create mode 100644 src/lib/krb5/keytab/ktfns.c create mode 100644 src/lib/krb5/krb/appdefault.c create mode 100644 src/lib/krb5/krb/init_keyblock.c create mode 100644 src/mac/DylibStub.c create mode 100644 src/mac/ErrorTables.jam create mode 100644 src/mac/GSS.h create mode 100644 src/mac/GSSKerberos5.pbproj/project.pbxproj create mode 100644 src/mac/GSSKerberosPrefix.h create mode 100644 src/mac/GSSLibrary.pbexp create mode 100644 src/mac/GenerateErrorTables.sh create mode 100644 src/mac/GenerateHeaderFiles.sh create mode 100644 src/mac/HeaderFiles.jam create mode 100644 src/mac/Kerberos5CoreExport.jam create mode 100644 src/mac/Kerberos5Lib.exp create mode 100644 src/mac/Kerberos5Lib.pbexp create mode 100644 src/mac/Kerberos5PrivateLib.pbexp create mode 100644 src/mac/MacOSX/Headers/GSSInit.h create mode 100644 src/mac/MacOSX/Headers/Kerberos5Init.h create mode 100644 src/mac/MacOSX/Headers/Kerberos5Prefix.h create mode 100644 src/mac/MacOSX/Headers/KerberosProfileInit.h create mode 100644 src/mac/MacOSX/Headers/cr_tkt.h create mode 100644 src/mac/MacOSX/Projects/GSS.pbexp create mode 100644 src/mac/MacOSX/Projects/Kerberos5.pbexp create mode 100644 src/mac/MacOSX/Projects/Kerberos5.pbproj/project.pbxproj create mode 100644 src/mac/MacOSX/Projects/Kerberos524.pbexp create mode 100644 src/mac/MacOSX/Scripts/Kerberos5Errors.jam create mode 100644 src/mac/MacOSX/Scripts/Kerberos5Headers.jam create mode 100644 src/mac/MacOSX/Sources/GSSInit.cp create mode 100644 src/mac/MacOSX/Sources/Kerberos5Init.cp create mode 100644 src/mac/MacOSX/Sources/ProfileInit.cp create mode 100644 src/mac/MacOSX/Sources/cr_tkt.c create mode 100644 src/mac/PrivateKerberos5Lib.exp create mode 100644 src/mac/kdestroy.c create mode 100644 src/mac/kinit.c create mode 100644 src/mac/klist.c create mode 100644 src/mac/kpasswd.c create mode 100644 src/mac/libraries/KerberosHeaders.9.pch create mode 100644 src/mac/libraries/KerberosHeaders.CB.pch create mode 100644 src/tests/dejagnu/krb-standalone/v4gssftp.exp create mode 100644 src/tests/dejagnu/krb-standalone/v4krb524d.exp create mode 100644 src/tests/dejagnu/krb-standalone/v4standalone.exp create mode 100644 src/util/et/et.pbexp delete mode 100644 src/util/et/et_c.perl create mode 100644 src/util/et/et_c.pl delete mode 100644 src/util/et/et_h.perl create mode 100644 src/util/et/et_h.pl create mode 100644 src/util/profile/profile.pbexp create mode 100644 src/util/pty/pty_paranoia.c create mode 100644 src/windows/ms2mit/ChangeLog create mode 100644 src/windows/ms2mit/Makefile.in create mode 100644 src/windows/ms2mit/ms2mit.c diff --git a/README b/README index 19b193e..c4297ee 100644 --- a/README +++ b/README @@ -1,49 +1,39 @@ -these were the - Kerberos Version 5, Release 1.1 + + Kerberos Version 5, Release 1.2.7 Release Notes -which will be updated before the next release by + The MIT Kerberos Team Unpacking the Source Distribution --------------------------------- -The source distribution of Kerberos 5 comes in three gzipped tarfiles, -krb5-1.1.src.tar.gz, krb5-1.1.doc.tar.gz, and krb5-1.1.crypto.tar.gz. -The krb5-1.1.doc.tar.gz contains the doc/ directory and this README -file. The krb5-1.1.src.tar.gz contains the src/ directory and this -README file, except for the crypto library sources, which are in -krb5-1.1.crypto.tar.gz. - -Instruction on how to extract the entire distribution follow. These -directions assume that you want to extract into a directory called -DIST. +The source distribution of Kerberos 5 comes in a gzipped tarfile, +krb5-1.2.7.tar.gz. Instruction on how to extract the entire +distribution follow. These directions assume that you want to extract +into a directory called DIST. If you have the GNU tar program and gzip installed, you can simply do: mkdir DIST cd DIST - gtar zxpf krb5-1.1.src.tar.gz - gtar zxpf krb5-1.1.crypto.tar.gz - gtar zxpf krb5-1.1.doc.tar.gz + gtar zxpf krb5-1.2.7.tar.gz If you don't have GNU tar, you will need to get the FSF gzip distribution and use gzcat: mkdir DIST cd DIST - gzcat krb5-1.1.src.tar.gz | tar xpf - - gzcat krb5-1.1.crypto.tar.gz | tar xpf - - gzcat krb5-1.1.doc.tar.gz | tar xpf - + gzcat krb5-1.2.7.tar.gz | tar xpf - -Both of these methods will extract the sources into DIST/krb5-1.1/src -and the documentation into DIST/krb5-1.1/doc. +Both of these methods will extract the sources into DIST/krb5-1.2.7/src +and the documentation into DIST/krb5-1.2.7/doc. Building and Installing Kerberos 5 ---------------------------------- -The first file you should look at is doc/install.ps; it contains the -notes for building and installing Kerberos 5. The info file +The first file you should look at is doc/install-guide.ps; it contains +the notes for building and installing Kerberos 5. The info file krb5-install.info has the same information in info file format. You can view this using the GNU emacs info-mode, or by using the standalone info file viewer from the Free Software Foundation. This @@ -70,53 +60,552 @@ If you are not able to use krb5-send-pr because you haven't been able compile and install Kerberos V5 on any platform, you may send mail to krb5-bugs@mit.edu. -Notes, Major Changes, and Known Bugs ------------------------------------- - -* Triple DES support is included; however, it is only usable for - service keys at the moment, due to a large number of compatibility - issues. For example, the GSSAPI library has some (buggy) support - for a triple DES session key, but it is intentionally disabled. - ** Do not use triple-DES in your config files except as described in - ** the documentation. - -* The principal database now uses the btree backend of Berkeley DB. - This should result in improved KDC performance. - -* The lib/rpc tests do not appear to work under NetBSD-1.4, for - reasons that are not completely clear at the moment, but probably - have something to do with portmapper interfacing. This should not - affect other operations, such as kadmind operation. - -* Shared library builds are under a new framework; at this point only - Solaris (2.x), Irix (6.5), NetBSD (1.4 i386), and possibly Linux are - known to work. All other working shared library builds may be - figments of your imagination. - -* Many existing databases, especially those converted from krb4 - original databases, may contain expiration dates in 1999. You - should make sure to update these expiration dates, and also change - any config file entries that have two-digit years. - -* Hardware preauthentication is known to be broken; this will be fixed - in an upcoming release. - -* krb524d now defaults to forking into the background; use - "krb524d -nofork" to avoid forking. - -* Not all reported bugs have been fixed in this release, due to time - constraints. We are planning to make another release in the near - future with more complete triple DES support, and additional - bugfixes. Many of the bugs in our database are reported against - what is now quite old code, or require hardware that we do not have, - which make them difficult to reproduce and debug. We will work on - these older bugs and some externally submitted patches for the - following release. +Notes, Major Changes, and Known Bugs for 1.2.7 +---------------------------------------------- + +Notes: + +* This release includes a significant security patch. If you are + running kadmind4 from an earlier release, you are highly encouraged + to update, as an exploit is believed to be circulating. + +Major Changes: + +* [1238] The exploitable buffer overflow in kadmind4 + [MITKRB5-SA-2002-002] has been patched. Thanks to Johan Danielsson, + Love Hornquist-Astrand, and Assar Westerlund. + +* [1230, 1236] Hierarchical cross-realm has been repaired somewhat. + Terminating NUL characters are no longer generated, and are ignored + on receipt. + +Minor Changes: + +* [1206] Fixed memory leak in padata handling in KDC. Thanks to Ben + Cox. + +* [1207] Clients can now successfully specify explicit keysalt tuples + to password-changing kadm5 functions. Thanks to Ben Cox. + +* [1216] Fixed client-side read overruns in calls to res_search(). + Thanks to Nalin Dahyabhai. + +* [1241] The test suite has been stabilized somewhat to work better + with modern versions of tcl and expect. + +Known Bugs: + +* [1228] If tcl is built shared, and krb5 is built static, some + utility programs used by the test suite may fail to run due to RPATH + issues. (long-standing but recently acknowledged) + +* Most of the other known bugs noted in earlier 1.2.x releases (other + than those listed as fixed above) are still present. + +Notes, Major Changes, and Known Bugs for 1.2.6 +---------------------------------------------- + +Notes: + +* This release includes a significant security patch. If you are + running an earlier release, you are highly encouraged to update, as + it is theoretically possible for an intruder to compromise your + KDC. + +Major Changes: + +* The security vulnerability in xdr_array() [MITKRB5-SA-2002-001] has + been patched. Thanks to Jeffrey Hutzelman and Nikolai Zeldovich. + +* A NULL pointer dereference in kadmind has been fixed + [krb5-admin/1140]. Thanks to Mark Levinson. + +* There was a botched buffer overflow patch in kadmind4 that caused + problems with kadmind4 acl handling. It has been fixed. Thanks to + Mark Silis. + +* Correct ETYPE_INFO padata are now generated. Thanks to Lubos + Kejzlar. + +* A bug in AFS salt handling has been worked + around. [krb5-clients/1146] Thanks to Wolfgang Friebel. + +* The KDC, in handling both krb5 and krb4 TGS_REQs, now honors the + DISALLOW_ALL_TIX and DISALLOW_SVR attributes on the server + principal. This also now happens with krb524d. + +* krb524d will now, by default, convert krb5 tickets for afs service + princpals to special tokens that are actually just the EncryptedData + part of a krb5 Ticket structure. This may be overridden; please + consult src/krb524/README for details. + +* Patches from Sleepycat have been applied to the btree backend of the + Brekeley DB library; these fix potential problems with the page free + and page split operations. + +* The kdb5_util dump command has additional options to allow for + reversed or recursive (for btree only) dumps of the principal + database. This permits the recovery of prinicpals that might + otherwise be omitted in a database dump in the presence of certain + types of corruption. + +* The dump command in kdb5_util now handles master key conversion + without crashing. + +Known Bugs: + +* Most of the other known bugs noted in earlier 1.2.x releases (other + than those listed as fixed above) are still present. + +Notes, Major Changes, and Known Bugs for 1.2.5 +---------------------------------------------- + +Major Changes: + +* On MacOS X, we have reviewed the list of exported symbol names. As + in earlier MacOS releases, and the Windows releases, but unlike the + UNIX releases, the list of exported names accessible to applications + is reduced to a predefined set of symbols. We are attempting to + define a "stable" subset of the API we feel confident about + providing, as opposed to giving applications access to half of the + packet-manipulation functions we have. + + In future releases, we may investigate applying a similar export + list under some UNIX shared library implementations. + + If a function you use is not exported, we probably figured it was + functionality that should be internal to the library, or something + that should be done with a different interface, or something we + didn't know anyone was using at the moment and thought we'd like to + clean up the interface later on. If you need it, and there isn't a + cleaner way, contact us about getting it added back in to the export + list. + + A few things are marked "deprecated" in the header file, but will + continue to be provided under "#if KRB5_DEPRECATED" because even + though they're ugly, we also know they're in use and we can't phase + them out fast enough. We may replace the implementation later on + with a shim on top of some cleaner mechanism. + +* For Heimdal (and possibly Microsoft) compatibility, we now accept + encrypted delegated credentials in gssapi. Historically, the MIT + implementation has sent delegated gssapi credentials "in the clear", + but still encrypted in the AP-REQ. + +* IP address checks have been removed from rd_cred; this improves + compatibility with Heimdal. + +Minor changes: + +* A null pointer dereference in the krb5 library has been fixed. + +Known bugs: + +* Most of the other known bugs from 1.2.3 and 1.2.4 are unchanged. + +Notes, Major Changes, and Known Bugs for 1.2.4 +---------------------------------------------- + +Notes: + +* Like the 1.2.3 release, this is a patch release. One critical login + problem is fixed, and a problem with interoperability with + Microsoft software is worked around. + +Major Changes: + +* The one-character bug introduced into the login.krb5 program that + caused 8-character usernames to be rejected in some circumstances + has been fixed. + +* The handling of key version numbers has been modified in places. + The current formats of the keytab and srvtab files, as well as parts + of the remote kadmin protocol, handle key version numbers as 8-bit + quantities, when in fact they are 32-bit quantities. + + * In the keytab and srvtab support for krb5, searching for the + "highest numbered" key version now has some heuristics to deal + with the 8-bit kvno wrapping from 255 to 0 to 1.... If a kvno + greater than 240 is found, the kvno values are assumed to range + from 128 to 383 (127+256). This should handle cases like storing + kvno values 255 and 256 in the file. + + * In the keytab and srvtab support for krb5, when looking for a key + with a specific version number, the low 8 bits of the requested + kvno are compared against the value stored in the file. + + * The "ktutil" program also has a new heuristic for choosing the + "highest numbered" key in a keytab to be written out into a krb4 + srvtab file. + + These heuristics all assume that key version numbers will be + assigned sequentially, and that there will not be a large set of key + version numbers in use at one time for any given principal in a + keytab file. + + These changes were prompted by the discovery by Microsoft (while + trying to write tools to generate MIT-style keytab files) that we + could not store arbitrary 32-bit version numbers for keys. + +* Some issues with multiple enctype support in GSSAPI credential + forwarding have been fixed. + +Minor Changes: + +* A few compilation problems have been fixed. + +* New test cases have been added to the test suite to exercise some of + the new changes. + +Known Bugs: + +* Non-sequential key version numbering will confuse the new kvno + handling heuristics. + +* Long-standing but newly recognized: + + * The remote kadmin protocol will produce incorrect results when key + version numbers greater than 255 are being retrieved or stored. + The kadmin.local program does not suffer from this problem. + + * We do not support storing multiple key versions for a principal in + a srvtab file. + + * We do not support acquiring krb4 tickets using a srvtab or keytab + file without acquiring krb5 tickets at the same time (i.e., the + old krb4 "ksrvtgt" program). + +* most of the other known bugs from 1.2.3 + +Notes, Major Changes, and Known Bugs for 1.2.3 +---------------------------------------------- + +Notes: + +* This release is a patch release; some non-critical bugs and feature + requests have not been incorporated. We have focussed mainly on + important security fixes and usability fixes. + +Major Changes: + +* Certain problems with shared library builds have been eliminated or + reduced on Linux and HP-UX. + +* Various bugs in single-DES enctype similarity have been fixed; the + 1.0.x behavior of treating all single-DES enctype as equivalent has + been restored for now. This may go away in a future release. Note + that SUPPORT_DESMD5 will be treated as always false for now. + +* The KDC will now log a number of enctype parameters associated with + KDC requests, in order to allow easier debugging of enctype-related + problems. + +* A client will no longer attempt obtain a forwarded TGT with a + session key enctype that the target server won't understand. + +* Triple-DES should work on Windows now. The SHA-1 implementation had + a Windows-specific bug preventing it from working in most cases. + +* Various bugs in pty handling have been fixed. + +* Bogus utmp files with garbage characters in their names should not + get created on Solaris. Also, utmp/wtmp handling code has been + mostly rewritten, eliminating numerous bugs. + +* Potential buffer-overrun problems and null-pointer dereferences have + been fixed in ftpd, telnetd, login.krb5, and SHA-1. The first three + may be exploitable under certain conditions; the SHA-1 bug probably + isn't, as far as we know. + +* For multiple-hop interrealm authentication, the realm transit path + checking has been rewritten. The old code had a serious bug where + some of the transited realms may not have been checked against the + computed path. It was therefore possible to forge a remote client + name in certain cases. We strongly recommend updating application + server code where non-local principals may be found on ACLs. + +* In conjunction with the above fix, we've implemented KDC checking of + the realm transit path, as described in the IETF's current + kerberos-revisions draft, and set up the KDC to refuse to issue + tickets with unacceptable transit paths. (Strictly speaking, + according to the Kerberos specification, enforcement of these checks + is supposed to be left to the application servers.) Thus, if your + application servers can't be updated promptly but your KDC can, you + can still prevent such tickets from being issued. This checking is + controlled by a per-realm flag, and is enabled by default. + +* On AIX systems, the rlogin server should no longer hang when + control-C is pressed. + +* New databases will be created in btree format by default. We + believe the btree code to be less buggy than the hash format code we + have been using. This should not affect the use of any existing + databases, only newly created ones, and even that should be a + transparent change. + +Known Bugs: + +* There may be problems with running a KDC on 64-bit platforms + (environments where size_t and long are wider than 32 bits, such as + alpha/Tru64, or Solaris/SPARC in SPARCv9 mode, for example), as + indicated by the util/db2 tests not passing. These problems may + also extend to the rpc library, which may prevent the kadmin + protocol from functioning. These are being investigated. + +* ETYPE_INFO preauthentication data returned from the KDC are not + sorted in the order requested by the client. This may result in + preauthentication failure when encrypted timestamp preauthentication + is required but the client doesn't understand some of the enctypes + of the keys stored for it in the database. + +* The gssftp daemon and client, when running in krb4 mode, are + inconsistent with respect to port numbers passed to the + {mk,rd}_{priv,safe} functions. As a result, there is a small but + nonzero probability that krb4 ftp with client and server on the same + IP address will fail with a "Time is out of bounds" error. This + includes the tests/dejagnu test suite, which tests the krb4 ftp + functionality. The probability of this occuring seems to be less + than 50%. + +* The gss-sample test application suite is known to not communicate + with the gss-sample suite in 1.1.x and earlier releases. This is + the result of changes to gss-sample to increase its functionality; + fixes to allow for backwards compatibility will occur in a later + release. + +* BSD/OS 4.x may have some problems compiling. These are being + investigated. + +Notes, Major Changes, and Known Bugs for 1.2.2 +---------------------------------------------- + +Notes: + +* This release is a patch release; some non-critical bugs and feature + requests have not been incorporated. + +Major Changes: + +* The KDC dump format has been updated to include per-principal policy + information. This will require updating your slave KDCs before your + master if you want things to still work. + +* A library bug that prevented kprop from working properly with DES3 + keys has been fixed. + +* kpasswd should no longer coredump when there is no kadmin_server + line in krb5.conf. + +* ASN.1 parsing has been improved to deal with indefinite encodings, + such as those emitted by DCE-1.0 derived systems. + +* Preauthentication handling code in the initial ticket APIs has been + fixed to handle zero-length ETYPE_INFO sequences without causing a + NULL pointer dereference. + +* The replay cache should no longer leak temporary files. Related + hard-to-analyze filename bugs in the rcache code should also be + fixed. + +* Library builds should now work on AIX. + +* KDC local address search code should now work on AIX. + +* The yacc grammar for the ftp daemon has been modified to be + compilable on HP/UX with Bison; namespace pollution from system + headers was causing trouble before. + +Known Bugs: + +* The gss-sample test application suite is known to not communicate + with the gss-sample suite in 1.1.x and earlier releases. This is + the result of changes to increase functionality; fixes to allow for + backwards compatibility will occur in a later release. + +* Handling of utmp and utmpx updates is known to be broken on some + systems, such as Solaris 8. We are investigating possible solutions + to this problem. + +* Tru64 Unix 5.0 (aka OSF/1 5.0), at least, has some problems with + revoke() returning ENOTTY in open_slave in the pty library. One + possible workaround is to insert + + vfs: + revoke_tty_only = 0 + + in /etc/sysconfigtab. It is not known whether this workaround will + cause other problems. + +* BSD/OS 4.x may have some problems compiling. These are being + investigated. + +Notes, Major Changes, and Known Bugs for 1.2.1 and 1.2 +------------------------------------------------------ + +* Triple DES support, for session keys as well as user or service + keys, should be nearly complete in this release. Much of the work + that has been needed is generic multiple-cryptosystem support, so + the addition of another cryptosystem should be much easier. + + * GSSAPI support for 3DES has been added. An Internet Draft is + being worked on that will describe how this works; it is not + currently standardized. Some backwards-compatibility issues in + this area mean that enabling 3DES support must be done with + caution; service keys that are used for GSSAPI must not be updated + to 3DES until the services themselves are upgraded to support 3DES + under GSSAPI. + +* DNS support for locating KDCs is enabled by default. DNS support + for looking up the realm of a host is compiled in but disabled by + default (due to some concerns with DNS spoofing). + + We recommend that you publish your KDC information through DNS even + if you intend to rely on config files at your own site; otherwise, + sites that wish to communicate with you will have to keep their + config files updated with your information. One of the goals of + this code is to reduce the client-side configuration maintenance + requirements as much as is possible, without compromising security. + + See the administrator's guide for information on setting up DNS + information for your realm. + + One important effect of this for developers is that on many systems, + "-lresolv" must be added to the compiler command line when linking + Kerberos programs. + + Configure-time options are available to control the inclusion of the + DNS code and the setting of the defaults. Entries in krb5.conf will + also modify the behavior if the code has been compiled in. + +* Numerous buffer-overrun problems have been found and fixed. Many of + these were in locations we don't expect can be exploited in any + useful way (for example, overrunning a buffer of MAXPATHLEN bytes if + a compiled-in pathname is too long, in a program that has no special + privileges). It may be possible to exploit a few of these to + compromise system security. + +* Partial support for IPv6 addresses has been added. It can be + enabled or disabled at configure time with --enable-ipv6 or + --disable-ipv6; by default, the configure script will search for + certain types and macros, and enable the IPv6 code if they're found. + The IPv6 support at this time mostly consists of including the + addresses in credentials. + +* A protocol change has been made to the "rcmd" suite (rlogin, rsh, + rcp) to address several security problems described in Kris + Hildrum's paper presented at NDSS 2000. New command-line options + have been added to control the selection of protocol, since the + revised protocol is not compatible with the old one. + +* A security problem in login.krb5 has been fixed. This problem was + only present if the krb4 compatibility code was not compiled in. + +* A security problem with ftpd has been fixed. An error in the in the + yacc grammar permitted potential root access. + +* The client programs kinit, klist and kdestroy have been changed to + incorporate krb4 support. New command-line options control whether + krb4 behavior, krb5 behavior, or both are used. + +* Patches from Frank Cusack for much better hardware preauth support + have been incorporated. + +* Patches from Matt Crawford extend the kadmin ACL syntax so that + restrictions can be imposed on what certain administrators may do to + certain accounts. + +* A KDC on a host with multiple network addresses will now respond to + a client from the address that the client used to contact it. The + means used to implement this will however cause the KDC not to + listen on network addresses configured after the KDC has started. + +Minor changes +------------- + +* The shell code for searching for the Tcl package at configure time + has been modified. If a tclConfig.sh can be found, the information + it contains is used, otherwise the old searching method is tried. + Let us know if this new scheme causes any problems. + +* Shared library builds may work on HPUX, Rhapsody/MacOS X, and newer + Alpha systems now. + +* The Windows build will now include kvno and gss-sample. + +* The routine krb5_secure_config_files has been disabled. A new + routine, krb5_init_secure_context, has been added in its place. + +* The routine decode_krb5_ticket is now being exported as + krb5_decode_ticket. Any programs that used the old name (which + should be few) should be changed to use the new name; we will + probably eliminate the old name in the future. + +* The CCAPI-based credentials cache code has been changed to store the + local-clock time of issue and expiration rather than the KDC-clock + times. + +* On systems with large numbers of IP addresses, "kinit" should do a + better job of acquiring those addresses to put in the user's + credentials. + +* Several memory leaks in error cases in the gssrpc code have been + fixed. + +* A bug with login clobbering some internal static storage on AIX has + been fixed. + +* Per-library initialization and cleanup functions have been added, + for use in configurations that dynamically load and unload these + libraries. + +* Many compile-time warnings have been fixed. + +* The GSS sample programs have been updated to exercise more of the + API. + +* The telnet server should produce a more meaningful error message if + authentication is required but not provided. + +* Changes have been made to ksu to make it more difficult to use it to + leak information the user does not have access to. + +* The sample config file information for the CYGNUS.COM realm has been + updated, and the GNU.ORG realm has been added. + +* A configure-time option has been added to enable a replay cache in + the KDC. We recommend its use when hardware preauthentication is + being used. It is enabled by default, and can be disabled if + desired with the configure-time option --disable-kdc-replay-cache. + +* Some new routines have been added to the library and krb5.h. + +* A new routine has been added to the prompter interface to allow the + application to determine which of the strings prompted for is the + user's password, in case it is needed for other purposes. + +* The remote kadmin interface has been enhanced to support the + specification of key/salt types for a principal. + +* New keytab entries' key values can now be specified manually with a + new command in the ktutil program. + +* A longstanding bug where certain krb4 exchanges using the + compatibility library between systems with different byte orders + would fail half the time has been fixed. + +* A source file under the GPL has been replaced with an equivalent + under the BSD license. The file, strftime.c, was part of one of the + OpenVision admin system applications, and was only used on systems + that don't have strftime() in their C libraries. + +* Many bug reports are still outstanding in our database. We are + continuing to work on this backlog. + Copyright Notice and Legal Administrivia ---------------------------------------- -Copyright (C) 1985-1999 by the Massachusetts Institute of Technology. +Copyright (C) 1985-2002 by the Massachusetts Institute of Technology. All rights reserved. @@ -156,6 +645,8 @@ manner. It does NOT prevent a commercial firm from referring to the MIT trademarks in order to convey information (although in doing so, recognition of their trademark status should be given). +---- + The following copyright and permission notice applies to the OpenVision Kerberos Administration system located in kadmin/create, kadmin/dbutil, kadmin/passwd, kadmin/server, lib/kadm5, and portions @@ -194,6 +685,13 @@ of lib/rpc: and our gratitude for the valuable work which has been performed by MIT and the Kerberos community. +---- + + Portions contributed by Matt Crawford were + work performed at Fermi National Accelerator Laboratory, which is + operated by Universities Research Association, Inc., under + contract DE-AC02-76CHO3000 with the U.S. Department of Energy. + Acknowledgements ---------------- @@ -222,13 +720,22 @@ as testing to ensure DCE interoperability. Thanks to Ken Hornstein at NRL for providing many bug fixes and suggestions. +Thanks to Matt Crawford at FNAL for bugfixes and enhancements. + Thanks to Sean Mullan and Bill Sommerfeld from Hewlett Packard for their many suggestions and bug fixes. +Thanks to Nalin Dahyabhai of RedHat and Chris Evans for locating and +providing patches for numerous buffer overruns. + +Thanks to Christopher Thompson and Marcus Watts for discovering the +ftpd security bug. + Thanks to the members of the Kerberos V5 development team at MIT, both -past and present: Danillo Almeida, Jay Berkenbilt, Richard Basch, John -Carr, Don Davis, Alexandra Ellwood, Nancy Gilman, Matt Hancher, Sam -Hartman, Paul Hill, Marc Horowitz, Eva Jacobus, Barry Jaspan, Geoffrey -King, John Kohl, Scott McGuire, Kevin Mitchell, Cliff Neuman, Paul -Park, Ezra Peisach, Chris Provenzano, Ken Raeburn, Jon Rochlis, Jeff -Schiller, Brad Thompson, Harry Tsai, Ted Ts'o, Marshall Vale, Tom Yu. +past and present: Danilo Almeida, Jay Berkenbilt, Richard Basch, Mitch +Berger, John Carr, Don Davis, Alexandra Ellwood, Nancy Gilman, Matt +Hancher, Sam Hartman, Paul Hill, Marc Horowitz, Eva Jacobus, Miroslav +Jurisic, Barry Jaspan, Geoffrey King, John Kohl, Peter Litwack, Scott +McGuire, Kevin Mitchell, Cliff Neuman, Paul Park, Ezra Peisach, Chris +Provenzano, Ken Raeburn, Jon Rochlis, Jeff Schiller, Jen Selby, Brad +Thompson, Harry Tsai, Ted Ts'o, Marshall Vale, Tom Yu. diff --git a/doc/ChangeLog b/doc/ChangeLog index 38af2b8..c4fb720 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,91 @@ +2002-02-27 Tom Yu + + * build.texinfo: Update build quirks for Tru64 4.0 defaulting to + K&R mode. + +2001-09-25 Ken Raeburn + + * admin.texinfo (realms (kdc.conf)): Add description of + reject_bad_transit realm option. + +2001-02-22 Tom Yu + + * admin.texinfo: Remove references to "rename_princpal". + +2001-02-16 Tom Yu + + * admin.texinfo (Dumping a Kerberos Database to a File): + (Restoring a Kerberos Database from a Dump File): Update to + reflect new dump file format and new flags to force beta7 dump + format. + + * install.texinfo (Switching Master and Slave KDCs): + (Upgrading Existing Kerberos V5 Installations): Update to reflect + new dump file format that includes principal policy information. + +2000-06-22 Tom Yu + + * build.texinfo (HPUX): Update note for HPUX compiler flags. + (Shared Library Support): Update shared lib support info. + +2000-06-16 Ken Raeburn + + * admin.texinfo: Update descriptions to indicate full support for + des3. Describe new DNS-related libdefaults tags for krb5.conf. + + * build.texinfo (Options to Configure): Fix @item labels. + + * install.texinfo: Update descriptions to indicate full support + for des3, and describe "v4" salt as being useful only with + des-cbc-crc. + +2000-06-15 Tom Yu + + * admin.texinfo: Note in multiple places that the current default + dump format doesn't include the per-principal policy information, + and some means of working around this problem. + + * install.texinfo (Switching Master and Slave KDCs): Note that + in the process of swapping KDCs, it is necessary to do a ov format + dump in order to preserve per-principal policy information. + +2000-06-13 Tom Yu + + * install.texinfo (Upgrading Existing Kerberos V5 Installations): + Add info describing how to preserve policy information while + upgrading. Also needs to go into other sections, possibly. + +2000-06-13 Ken Raeburn + + * build.texinfo: Enter correct xref info for DNS data + descriptions. Fix up text around some xrefs. + * install.texinfo: Describe SRV and TXT DNS records. Fix up text + around some xrefs. + +2000-06-09 Tom Yu + + * admin.texinfo: Add descriptions of the kadmin {ank,cpw,ktadd} -e + flag. + +2000-06-06 Ken Raeburn + + * install.texinfo: Describe new DNS support, and 3DES upgrade + path. Update "enctypes" config file sample lines. + + * build.texinfo: No kpasswd directory. Describe new configure + options. + + * send-pr.texinfo: Suggest caution regarding tab expansion for + patches. + +2000-06-02 Ken Raeburn + + * definitions.texinfo: Update for 1.2 release. + +2000-05-31 Ken Raeburn + + * krb425.texinfo (libdefaults): Add description of v4_realm. + 1999-09-22 Tom Yu * copyright.texinfo: Update copyright again. diff --git a/doc/admin.texinfo b/doc/admin.texinfo index 2ea716b..2fcfd1b 100644 --- a/doc/admin.texinfo +++ b/doc/admin.texinfo @@ -16,7 +16,7 @@ @include definitions.texinfo @set EDITION 1.0 -@set UPDATED November 27, 1996 +@set UPDATED June 16, 2000 @finalout @c don't print black warning boxes @@ -429,7 +429,8 @@ your Kerberos realm. @itemx default_tgs_enctypes Identifies the supported list of session key encryption types that should be returned by the KDC. The list may be delimited with commas or -whitespace. Currently, the only supported encryption type is +whitespace. Currently, the supported encryption types are +"des3-hmac-sha1" and "des-cbc-crc". Support for other encryption types is planned in the future. @@ -437,7 +438,7 @@ future. Identifies the supported list of session key encryption types that should be requested by the client. The format is the same as for @emph{default_tkt_enctypes}. Again, the only supported encryption -type is "des-cbc-crc". +types are "des3-hmac-sha1" and "des-cbc-crc". @itemx clockskew Sets the maximum allowable amount of clockskew in seconds that the @@ -456,6 +457,50 @@ of cache to be created by kinit, or when forwarded tickets are received. DCE and Kerberos can share the cache, but some versions of DCE do not support the default cache as created by this version of Kerberos. Use a value of 1 on DCE 1.0.3a systems, and a value of 2 on DCE 1.1 systems. + +@itemx dns_lookup_kdc +Indicate whether DNS SRV records should be used to locate the KDCs and +other servers for a realm, if they are not listed in the information for +the realm. (Note that the @samp{admin_server} entry must be in the +file, because the DNS implementation for it is incomplete.) + +Enabling this option does open up a type of denial-of-service attack, if +someone spoofs the DNS records and redirects you to another server. +However, it's no worse than a denial of service, because that fake KDC +will be unable to decode anything you send it (besides the initial +ticket request, which has no encrypted data), and anything the fake KDC +sends will not be trusted without verification using some secret that it +won't know. + +If this option is not specified but @samp{dns_fallback} is, that value +will be used instead. If neither option is specified, the behavior +depends on configure-time options; if none were given, the default is to +enable this option. If the DNS support is not compiled in, this entry +has no effect. + +@itemx dns_lookup_realm +Indicate whether DNS TXT records should be used to determine the +Kerberos realm of a host. + +Enabling this option may permit a redirection attack, where spoofed DNS +replies persuade a client to authenticate to the wrong realm, when +talking to the wrong host (either by spoofing yet more DNS records or by +intercepting the net traffic). Depending on how the client software +manages hostnames, however, it could already be vulnerable to such +attacks. We are looking at possible ways to minimize or eliminate this +exposure. For now, we encourage more adventurous sites to try using +Secure DNS. + +If this option is not specified but @samp{dns_fallback} is, that value +will be used instead. If neither option is specified, the behavior +depends on configure-time options; if none were given, the default is to +disable this option. If the DNS support is not compiled in, this entry +has no effect. + +@itemx dns_fallback +General flag controlling the use of DNS for Kerberos information. If +both of the preceding options are specified, this option has no effect. + @end table @node appdefaults, realms (krb5.conf), libdefaults, krb5.conf @@ -724,8 +769,8 @@ Here is an example of a generic @code{krb5.conf} file: [libdefaults] ticket_lifetime = 600 default_realm = @value{PRIMARYREALM} - default_tkt_enctypes = des-cbc-crc - default_tgs_enctypes = des-cbc-crc + default_tkt_enctypes = des3-hmac-sha1 des-cbc-crc + default_tgs_enctypes = des3-hmac-sha1 des-cbc-crc [realms] @value{PRIMARYREALM} = @{ @@ -858,8 +903,9 @@ this realm. By default, the value of kdc_ports as specified in the (String.) Specifies the name of the master key. @itemx master_key_type -(Key type string.) Specifies the master key's key type. Only -"des-cbc-crc" is supported at this time. +(Key type string.) Specifies the master key's key type. Either +"des3-hmac-sha1" or +"des-cbc-crc" may be used at this time. @itemx max_life (Delta time string.) Specifes the maximum time period for which a @@ -872,23 +918,47 @@ valid ticket may be renewed in this realm. @itemx supported_enctypes List of key:salt strings. Specifies the default key/salt combinations of principals for this realm. Any principals created through -@code{kadmin} will have keys of these types. Since only the encryption -type "des-cbc-crc" is supported, you should set this tag to -@samp{des-cbc-crc:normal des-cbc-crc:v4}. +@code{kadmin} will have keys of these types. If you do not yet wish to +enable triple-DES support, you should set this tag to +@samp{des-cbc-crc:normal des-cbc-crc:v4}; otherwise, put +@samp{des3-hmac-sha1:normal} at the beginning of the list. @itemx kdc_supported_enctypes List of key:salt strings. Specifies the permitted key/salt combinations of principals for this realm. You should set this tag to -@samp{des-cbc-crc:normal des-cbc-crc:v4}. - -@b{Note:} You may also use @samp{des3-cbc-sha1:normal} before -@samp{des-cbc-crc:normal} if you wish to support triple-DES service keys -in addition to DES service keys. In order to create such service keys, -you must use the @code{-e} option to @code{kadmin.local}, running on the -KDC system itself; the remote @code{kadmin} client does not allow this -option. We do not currently support the use of triple-DES keys anywhere -other than for service keys. - +@samp{des3-hmac-sha1:normal des-cbc-crc:normal des-cbc-crc:v4}. + +@itemx reject_bad_transit +A boolean value (@code{true}, @code{false}). If set to @code{true}, the +KDC will check the list of transited realms for cross-realm tickets +against the transit path computed from the realm names and the +@code{capaths} section of its @code{krb5.conf} file; if the path in the +ticket to be issued contains any realms not in the computed path, the +ticket will not be issued, and an error will be returned to the client +instead. If this value is set to @code{false}, such tickets will be +issued anyways, and it will be left up to the application server to +validate the realm transit path. + +If the @code{disable-transited-check} flag is set in the incoming +request, this check is not performed at all. Having the +@code{reject_bad_transit} option will cause such ticket requests to be +rejected always. + +This transit path checking and config file option currently apply only +to TGS requests. + +Earlier versions of the MIT release (before 1.2.3) had bugs in the +application server support such that the server-side checks may not be +performed correctly. We recommend turning this option on, unless you +know that all application servers in this realm have been updated to +fixed versions of the software, and for whatever reason, you don't want +the KDC to do the validation. + +This is a per-realm option so that multiple-realm KDCs may control it +separately for each realm, in case (for example) one realm has had the +software on its application servers updated but another has not. + +This option defaults to @code{true}. @end table @@ -907,9 +977,9 @@ Here's an example of a @code{kdc.conf} file: kadmind_port = 749 max_life = 10h 0m 0s max_renewable_life = 7d 0h 0m 0s - master_key_type = des-cbc-crc - supported_enctypes = des-cbc-crc:normal des-cbc-crc:v4 - kdc_supported_enctypes = des-cbc-crc:normal des-cbc-crc:v4 + master_key_type = des3-hmac-sha1 + supported_enctypes = des3-hmac-sha1:normal des-cbc-crc:normal des-cbc-crc:v4 + kdc_supported_enctypes = des3-hmac-sha1:normal des-cbc-crc:normal des-cbc-crc:v4 @} [logging] @@ -1011,11 +1081,8 @@ scripts that pass specific queries to @code{kadmin}. @b{(For @code{kadmin.local} only.)} Sets the list of cryptosystem and salt types to be used for any new keys created. Available types include @samp{des3-cbc-sha1:normal}, -@samp{des-cbc-crc:normal}, and @samp{des-cbc-crc:v4}. In this release, -the @samp{des3-cbc-sha1:normal} type should only be used when -registering service principals; for any services that may request -tickets themselves to initiate some action, it should be combined with -one or more of the other types. +@samp{des-cbc-crc:normal}, and @samp{des-cbc-crc:v4}. + @end table @node Date Format, Principals, Kadmin Options, Administrating Kerberos Database Entries @@ -1092,7 +1159,6 @@ that principal. * Adding or Modifying Principals:: * Deleting Principals:: * Changing Passwords:: -* Renaming Principals:: @end menu @node Retrieving Information About a Principal, Privileges, Principals, Principals @@ -1280,7 +1346,7 @@ administrative privilege. The syntax is: @code{add_principal} has the aliases @code{addprinc} and @code{ank}@footnote{@code{ank} was the short form of the equivalent command using the deprecated @code{kadmin5} database administrative -tool. It has been kept}. @code{modify_principal} has the alias @code{modprinc}. +tool. It has been kept. @code{modify_principal} has the alias @code{modprinc}.} The @code{add_principal} and @code{modify_principal} commands take the following switches: @@ -1408,16 +1474,18 @@ Removes the policy @i{policyname} from the principal @item -randkey Sets the key for the principal to a random value (@code{add_principal} -only). @value{COMPANY} recommends using this option for host keys. You -may also wish to use the @b{kadmin.local} command-line options @b{-e -"des3-cbc-sha1:normal des-cbc-crc:normal"}@xref{Kadmin Options} on the -KDC machine itself for host keys and other service keys that are -security-critical. +only). @value{COMPANY} recommends using this option for host keys. @item -pw @i{password} Sets the key of the principal to the specified string and does not prompt for a password (@code{add_principal} only). @value{COMPANY} does not recommend using this option. + +@item -e @i{enc:salt...} +Uses the specified list of enctype-salttype pairs for setting the key of +the principal. The quotes are necessary if there are multiple +enctype-salttype pairs. This will not function against kadmin daemons +earlier than krb5-1.2. @end table If you want to just use the default values, all you need to do is: @@ -1503,7 +1571,7 @@ kadmin:} @end group @end smallexample -@node Changing Passwords, Renaming Principals, Deleting Principals, Principals +@node Changing Passwords, , Deleting Principals, Principals @subsection Changing Passwords To change a principal's password use the kadmin @code{change_password} @@ -1529,6 +1597,12 @@ Sets the key of the principal to a random value. @item @b{-pw} @i{password} Sets the password to the string @i{password}. @value{COMPANY} does not recommend using this option. + +@item @b{-e} @i{"enc:salt..."} +Uses the specified list of enctype-salttype pairs for setting the key of +the principal. The quotes are necessary if there are multiple +enctype-salttype pairs. This will not function against kadmin daemons +earlier than krb5-1.2. @end table For example: @@ -1552,35 +1626,6 @@ kadmin:} Note that @code{change_password} will not let you change the password to one that is in the principal's password history. -@node Renaming Principals, , Changing Passwords, Principals -@subsection Renaming Principals - -To rename a principal, use the kadmin @code{rename_principal} command, -which requires both the ``add'' and ``delete'' administrative -privileges. The syntax is: - -@smallexample -@b{rename_principal} [@b{-force}] @i{old_principal} @i{new_principal} -@end smallexample - -@noindent The @code{rename_principal} command has the alias @code{renprinc}. - -For example: - -@smallexample -@group -@b{kadmin:} renprinc test test0 -@b{Are you sure you want to rename the principal -"test@@@value{PRIMARYREALM}" to -"test0@@@value{PRIMARYREALM}"? (yes/no):} yes -@b{Principal "test@@@value{PRIMARYREALM}" renamed to -"test0@@@value{PRIMARYREALM}". -Make sure that you have removed "test@@@value{PRIMARYREALM}" from -all ACLs before reusing. -kadmin:} -@end group -@end smallexample - @node Policies, Dumping a Kerberos Database to a File, Principals, Administrating Kerberos Database Entries @section Policies @@ -1745,8 +1790,8 @@ To dump a Kerberos database into a file, use the @code{kdb5_util} @code{dump} command on one of the KDCs. The syntax is: @smallexample -@b{kdb5_util dump} [@b{-old}] [@b{-b6}] [@b{-ov}] [@b{-verbose}] [@i{filename} -[@i{principals...}]] +@b{kdb5_util dump} [@b{-old}] [@b{-b6}] [@b{-b7}] [@b{-ov}] [@b{-verbose}] +[@i{filename} [@i{principals...}]] @end smallexample The @code{kdb5_util dump} command takes the following options: @@ -1758,6 +1803,10 @@ causes the dump to be in the Kerberos 5 Beta 5 and earlier dump format @itemx -b6 causes the dump to be in the Kerberos 5 Beta 6 format (``kdb5_edit load_dump version 3.0''). +@itemx -b7 +causes the dump to be in the Kerberos 5 Beta 7 format (``kdb5_util +load_dump version 4''). This was the dump format produced on releases +prior to 1.2.2. @itemx -ov causes the dump to be in ovsec_adm_export format. @itemx -verbose @@ -1824,8 +1873,8 @@ To restore a Kerberos database dump from a file, use the is: @smallexample -@b{kdb5_util load} [@b{-old}] [@b{-b6}] [@b{-ov}] [@b{-verbose}] [@b{-update}] -@i{dumpfilename} @i{dbname} [@i{admin_dbname}] +@b{kdb5_util load} [@b{-old}] [@b{-b6}] [@b{-b7}] [@b{-ov}] [@b{-verbose}] +[@b{-update}] @i{dumpfilename} @i{dbname} [@i{admin_dbname}] @end smallexample The @code{kdb5_util load} command takes the following options: @@ -1837,6 +1886,9 @@ requires the dump to be in the Kerberos 5 Beta 5 and earlier dump format @itemx -b6 requires the dump to be in the Kerberos 5 Beta 6 format (``kdb5_edit load_dump version 3.0''). +@itemx -b7 +requires the dump to be in the Kerberos 5 Beta 7 format (``kdb5_util +load_dump version 4''). @itemx -ov requires the dump to be in ovsec_adm_export format. @itemx -verbose @@ -2001,6 +2053,12 @@ The @code{ktadd} command takes the following switches: use @i{keytab} as the keytab file. Otherwise, @code{ktadd} will use the default keytab file (@code{/etc/krb5.keytab}). +@item @b{-e} @i{"enc:salt..."} +Uses the specified list of enctype-salttype pairs for setting the key of +the principal. The quotes are necessary if there are multiple +enctype-salttype pairs. This will not function against kadmin daemons +earlier than krb5-1.2. + @item -q run in quiet mode. This causes @code{ktadd} to display less verbose information. @@ -2012,8 +2070,9 @@ for the kadmin @code{list_principals} (@pxref{Retrieving a List of Principals}) command. @end table -For example (The line beginning with @result{} is a continuation of the -previous line.): +Here is a sample session, using configuration files that enable only +@samp{des-cbc-crc} encryption. (The line beginning with @result{} is a +continuation of the previous line.) @smallexample @group @@ -2551,7 +2610,6 @@ KRB5PLACEHOLD_110: KRB5 error code 110 @item KRB5PLACEHOLD_111: KRB5 error code 111 @item -+ KRB5PLACEHOLD_112: KRB5 error code 112 @item KRB5PLACEHOLD_113: KRB5 error code 113 diff --git a/doc/api/ChangeLog b/doc/api/ChangeLog index b1145f1..accc0c6 100644 --- a/doc/api/ChangeLog +++ b/doc/api/ChangeLog @@ -1,3 +1,7 @@ +2000-06-22 Ken Raeburn + + * Makefile (lib1.stamp): Use texindex instead of index. + 1999-08-30 Ken Raeburn * libdes.tex: Don't use ncs style; it's availability is dependent diff --git a/doc/api/Makefile b/doc/api/Makefile index 3fd23f9..dbb2f03 100644 --- a/doc/api/Makefile +++ b/doc/api/Makefile @@ -28,7 +28,7 @@ library.dvi: lib1.stamp $(LIBTEX) $(STYLES) lib1.stamp: $(LIBTEX) $(STYLES) touch library.ind latex library - index library.idx + texindex library.idx date > lib1.stamp .tex.dvi: diff --git a/doc/build.texinfo b/doc/build.texinfo index 78aa8b4..e432717 100644 --- a/doc/build.texinfo +++ b/doc/build.texinfo @@ -59,8 +59,8 @@ only need to build Kerberos for one platform, using a single directory tree which contains both the source files and the object files is the simplest. However, if you need to maintain Kerberos for a large number of platforms, you will probably want to use separate build trees for -each platform. We recommend that you look at see @ref{OS -Incompatibilities} for notes that we have on particular operating +each platform. We recommend that you look at @ref{OS +Incompatibilities}, for notes that we have on particular operating systems. @menu @@ -152,10 +152,10 @@ building Kerberos; see @ref{Doing the Build}.): @menu * The DejaGnu Tests:: -* The KADM5 Tests:: +* The KADM5 Tests:: @end menu -@node The DejaGnu Tests, The KADM5 Tests, Testing the Build, Testing the Build +@node The DejaGnu Tests, The KADM5 Tests, Testing the Build, Testing the Build @subsection The DejaGnu Tests Some of the built-in regression tests are setup to use the DejaGnu @@ -200,7 +200,7 @@ libraries to be available during compilation and some of the tests also require Perl in order to operate. If all of these resources are not available during configuration, the KADM5 tests will not run. The TCL installation directory can be specified with the @code{--with-tcl} -configure option (see @xref{Options to Configure}). The runtest and +configure option. (See @xref{Options to Configure}.) The runtest and perl programs must be in the current execution path. If you install DejaGnu, TCL, or Perl after configuring and building @@ -208,7 +208,7 @@ Kerberos and then want to run the KADM5 tests, you will need to re-configure the tree and run @code{make} at the top level again to make sure all the proper programs are built. To save time, you actually only need to reconfigure and build in the directories src/kadmin/testing, -src/lib/rpc, src/lib/kadm5, and src/kpasswd. +src/lib/rpc, src/lib/kadm5. @node Options to Configure, osconf.h, Testing the Build, Building Kerberos V5 @section Options to Configure @@ -301,12 +301,6 @@ default, Kerberos V5 configuration will look for @code{-lnsl} and (see @ref{Solaris versions 2.0 through 2.3}) or fails to pass the tests in @file{src/tests/resolv} you will need to use this option. -@item --enable-shared - -This option will turn on the building and use of shared library objects -in the Kerberos build. This option is only supported on certain -platforms. - @item --with-vague-errors If enabled, gives vague and unhelpful error messages to the client... er, @@ -329,10 +323,33 @@ Tcl. The directory specified by @code{TCLPATH} specifies where the Tcl header file (@file{TCLPATH/include/tcl.h} as well as where the Tcl library should be found (@file{TCLPATH/lib}). +@item --enable-shared + +This option will turn on the building and use of shared library objects +in the Kerberos build. This option is only supported on certain +platforms. + +@item --enable-dns +@item --enable-dns-for-kdc +@item --enable-dns-for-realm + +Enable the use of DNS to look up a host's Kerberos realm, or a realm's +KDCs, if the information is not provided in krb5.conf. See +@xref{Hostnames for the Master and Slave KDCs}, and @xref{Mapping +Hostnames onto Kerberos Realms}. By default, DNS lookups are enabled +for the latter but not for the former. + +@item --enable-kdc-replay-cache + +Enable a cache in the KDC to detect retransmitted messages, and resend +the previous responses to them. This protects against certain types of +attempts to extract information from the KDC through some of the +hardware preauthentication systems. + @end table For example, in order to configure Kerberos on a Solaris machine using -the @samp{suncc} with the optimizer turned on, run the configure +the @samp{suncc} compiler with the optimizer turned on, run the configure script with the following options: @example @@ -397,10 +414,15 @@ variables when using the programs. Except where noted, multiple versions of the libraries may be installed on the same system and continue to work. -Currently the supported platforms are -@comment NetBSD 1.0A, AIX 3.2.5, AIX 4.1, -Solaris 2.6 (aka SunOS 5.6) and Irix 6.5. -@comment Alpha OSF/1 >= 2.1, HP-UX >= 9.X. +Currently the supported platforms are Solaris 2.6 (aka SunOS 5.6) and Irix 6.5. + +Shared library support has been tested on the following platforms but +not exhaustively (they have been built but not necessarily tested in an +installed state): Tru64 (aka Alpha OSF/1 or Digital Unix) 4.0, NetBSD +1.4.x (i386), and HP/UX 10.20. + +Platforms for which there is shared library support but not significant +testing include FreeBSD, OpenBSD, MacOS 10, AIX, Linux, and SunOS 4.x. To enable shared libraries on the above platforms, run the configure script with the option @samp{--enable-shared}. @@ -428,6 +450,7 @@ Thanks! * AIX:: * Alpha OSF/1 V1.3:: * Alpha OSF/1 (Digital Unix) V2.0++:: +* Alpha Tru64 4.0:: * BSDI:: * HPUX:: * Solaris versions 2.0 through 2.3:: @@ -452,7 +475,7 @@ causes the @code{asn.1} library to be compiled incorrectly. Using GCC version 2.6.3 or later instead of the native compiler will also work fine, both with or without optimization. -@node Alpha OSF/1 (Digital Unix) V2.0++, BSDI, Alpha OSF/1 V1.3, OS Incompatibilities +@node Alpha OSF/1 (Digital Unix) V2.0++, Alpha Tru64 4.0, Alpha OSF/1 V1.3, OS Incompatibilities @subsection Alpha OSF/1 V2.0++ There used to be a bug when using the native compiler in compiling @@ -463,9 +486,21 @@ problem would exist there. (We welcome feedback on this issue). There was never a problem in using GCC version 2.6.3. In version 3.2 and beyond of the operating system, we have not seen any -problems with the native compiler. +optimizer problems with the native compiler. + +@node Alpha Tru64 4.0, BSDI, Alpha OSF/1 (Digital Unix) V2.0++, OS Incompatibilities +@subsection Alpha Tru64 4.0 + +Alpha Tru64 4.0 will have some trouble compiling the some stdarg +prototypes, since it defaults to K&R C. Use the @samp{-std} or +@samp{-std1} flags to force ANSI behavior (e.g. @samp{./configure +--with-cc='cc -std1'}). + +@comment node-name, next, previous, up@c @node Alpha Tru64 UNIX 5.0 +@c @subsection Alpha Tru64 UNIX 5.0 +@c ... login.krb5 problems -@node BSDI, HPUX, Alpha OSF/1 (Digital Unix) V2.0++, OS Incompatibilities +@node BSDI, HPUX, Alpha Tru64 4.0, OS Incompatibilities @subsection BSDI BSDI versions 1.0 and 1.1 reportedly has a bad @samp{sed} which causes @@ -479,9 +514,9 @@ NetBSD and FreeBSD.) The native (bundled) compiler for HPUX currently will not work, because it is not a full ANSI C compiler. The optional compiler (c89) should -work as long as you give it the @samp{+Olibcalls -D_HPUX_SOURCE} (this -has only been tested for HPUX 9.0). At this point, using GCC is -probably your best bet. +work as long as you give it the @samp{-D_HPUX_SOURCE} flag +(i.e. @samp{./configure --with-cc='c89 -D_HPUX_SOURCE'}). This has only +been tested recently for HPUX 10.20. @node Solaris versions 2.0 through 2.3, Solaris 2.X, HPUX, OS Incompatibilities @subsection Solaris versions 2.0 through 2.3 diff --git a/doc/copyright.texinfo b/doc/copyright.texinfo index 7ea4758..355cad1 100644 --- a/doc/copyright.texinfo +++ b/doc/copyright.texinfo @@ -1,4 +1,4 @@ -Copyright @copyright{} 1985-1999 by the Massachusetts Institute of Technology. +Copyright @copyright{} 1985-2001 by the Massachusetts Institute of Technology. @quotation Export of software employing encryption from the United States of diff --git a/doc/definitions.texinfo b/doc/definitions.texinfo index 079809d..5a5b37c 100644 --- a/doc/definitions.texinfo +++ b/doc/definitions.texinfo @@ -19,8 +19,8 @@ @set RANDOMUSER johndoe @set RANDOMUSER1 jennifer @set RANDOMUSER2 david -@set RELEASE 1.1 -@set PREVRELEASE 1.0 +@set RELEASE 1.2 +@set PREVRELEASE 1.1 @set INSTALLDIR /usr/@value{LCPRODUCT} @set PREVINSTALLDIR @value{INSTALLDIR} @set ROOTDIR /usr/local diff --git a/doc/install.texinfo b/doc/install.texinfo index 8744b0f..2ecd8bd 100644 --- a/doc/install.texinfo +++ b/doc/install.texinfo @@ -229,7 +229,10 @@ BOSTON.@value{SECONDREALM} and HOUSTON.@value{SECONDREALM}. @node Mapping Hostnames onto Kerberos Realms, Ports for the KDC and Admin Services, Kerberos Realms, Realm Configuration Decisions @section Mapping Hostnames onto Kerberos Realms -Mapping hostnames onto Kerberos realms is done through a set of rules in +Mapping hostnames onto Kerberos realms is done in one of two ways. + +The first mechanism, which has been in use for years in MIT-based +Kerberos distributions, works through a set of rules in the @code{krb5.conf} configuration file. (@xref{krb5.conf}.) You can specify mappings for an entire domain or subdomain, and/or on a hostname-by-hostname basis. Since greater specificity takes precedence, @@ -240,7 +243,35 @@ The @value{PRODUCT} System Administrator's Guide contains a thorough description of the parts of the @code{krb5.conf} file and what may be specified in each. A sample @code{krb5.conf} file appears in @ref{krb5.conf}. You should be able to use this file, substituting the -relevant information for your Kerberos instllation for the samples. +relevant information for your Kerberos installation for the samples. + +The second mechanism, recently introduced into the MIT code base but not +currently used by default, works by looking up the information in +special @code{TXT} records in the Domain Name Service. If this +mechanism is enabled on the client, it will try to look up a @code{TXT} +record for the DNS name formed by putting the prefix @code{_kerberos} in +front of the hostname in question. If that record is not found, it will +try using @code{_kerberos} and the host's domain name, then its parent +domain, and so forth. So for the hostname +BOSTON.ENGINEERING.FOOBAR.COM, the names looked up would be: + +@smallexample +_kerberos.boston.engineering.foobar.com +_kerberos.engineering.foobar.com +_kerberos.foobar.com +_kerberos.com +@end smallexample + +The value of the first TXT record found is taken as the realm name. +(Obviously, this doesn't work all that well if a host and a subdomain +have the same name, and different realms. For example, if all the hosts +in the ENGINEERING.FOOBAR.COM domain are in the ENGINEERING.FOOBAR.COM +realm, but a host named ENGINEERING.FOOBAR.COM is for some reason in +another realm. In that case, you would set up TXT records for all +hosts, rather than relying on the fallback to the domain name.) + +Even if you do not choose to use this mechanism within your site, you +may wish to set up anyways, for use when interacting with other sites. @node Ports for the KDC and Admin Services, Slave KDCs, Mapping Hostnames onto Kerberos Realms, Realm Configuration Decisions @section Ports for the KDC and Admin Services @@ -293,11 +324,86 @@ disasters. @section Hostnames for the Master and Slave KDCs @value{COMPANY} recommends that your KDCs have a predefined set of -CNAMEs, such as @code{@value{KDCSERVER}} for the master KDC and +CNAME records (DNS hostname aliases), such as @code{@value{KDCSERVER}} +for the master KDC and @code{@value{KDCSLAVE1}}, @code{@value{KDCSLAVE2}}, @dots{} for the slave KDCs. This way, if you need to swap a machine, you only need to change a DNS entry, rather than having to change hostnames. +A new mechanism for locating KDCs of a realm through DNS has been added +to the @value{COMPANY} @value{PRODUCT} distribution. A relatively new +record type called @code{SRV} has been added to DNS. Looked up by a +service name and a domain name, these records indicate the hostname and +port number to contact for that service, optionally with weighting and +prioritization. (See RFC 2782 if you want more information. You can +follow the example below for straightforward cases.) + +The use with Kerberos is fairly straightforward. The domain name used +in the SRV record name is the domain-style Kerberos realm name. (It is +possible to have Kerberos realm names that are not DNS-style names, but +we don't recommend it for Internet use, and our code does not support it +well.) Several different Kerberos-related service names are used: + +@table @code +@item _kerberos._udp +This is for contacting any KDC. This entry will be used the most often. +Normally you should list ports 88 and 750 on each of your KDCs. + +@item _kerberos-master._udp +This entry should refer to those KDCs, if any, that will immediately see +password changes to the Kerberos database. This entry is used only in +one case, when the user is logging in and the password appears to be +incorrect; the master KDC is then contacted, and the same password used +to try to decrypt the response, in case the user's password had recently +been changed and the first KDC contacted hadn't been updated. Only if +that fails is an ``incorrect password'' error given. + +If you have only one KDC, or for whatever reason there is no accessible +KDC that would get database changes faster than the others, you do not +need to define this entry. + +@item _kerberos-adm._tcp +This should list port 749 on your master KDC. Support for it is not +complete at this time, but it will eventually be used by the +@code{kadmin} program and related utilities. For now, you will also +need the @code{admin_server} entry in @code{krb5.conf}. + +@item _kpasswd._udp +This should list port 464 on your master KDC. It is used when a user +changes her password. + +@end table + +Be aware, however, that the DNS SRV specification requires that the +hostnames listed be the canonical names, not aliases. So, for example, +you might include the following records in your (BIND-style) zone file: + +@smallexample +$ORIGIN foobar.com. +_kerberos TXT "FOOBAR.COM" +kerberos CNAME daisy +kerberos-1 CNAME use-the-force-luke +kerberos-2 CNAME bunny-rabbit +_kerberos._udp SRV 0 0 88 daisy + SRV 0 0 88 use-the-force-luke + SRV 0 0 88 bunny-rabbit +_kerberos-master._udp SRV 0 0 88 daisy +_kerberos-adm._tcp SRV 0 0 749 daisy +_kpasswd._udp SRV 0 0 464 daisy +@end smallexample + +As with the DNS-based mechanism for determining the Kerberos realm of a +host, we recommend distributing the information this way for use by +other sites that may want to interact with yours using Kerberos, even if +you don't immediately make use of it within your own site. If you +anticipate installing a very large number of machines on which it will +be hard to update the Kerberos configuration files, you may wish to do +all of your Kerberos service lookups via DNS and not put the information +(except for @code{admin_server} as noted above) in future versions of +your @code{krb5.conf} files at all. Eventually, we hope to phase out +the listing of server hostnames in the client-side configuration files; +making preparations now will make the transition easier in the future. + @node Database Propagation, , Hostnames for the Master and Slave KDCs, Realm Configuration Decisions @section Database Propagation @@ -421,7 +527,8 @@ encrypted form on the KDC's local disk. The stash file is used to authenticate the KDC to itself automatically before starting the @code{kadmind} and @code{krb5kdc} daemons (@i{e.g.,} as part of the machine's boot sequence). The stash file, like the keytab file -(@xref{The Keytab File}) is a potential point-of-entry for a break-in, +(see @xref{The Keytab File}, for more information) is a potential +point-of-entry for a break-in, and if compromised, would allow unrestricted access to the Kerberos database. If you choose to install a stash file, it should be readable only by root, and should exist only on the KDC's local disk. The file @@ -560,8 +667,8 @@ instance ``root'', you would add the following line to the acl file: Next you need to add administrative principals to the Kerberos database. (You must add at least one now.) To do this, use @code{kadmin.local} @emph{on the master KDC}. The administrative principals you create -should be the ones you added to the ACL file (see @xref{Add -Administrators to the Acl File}). In the following example, the +should be the ones you added to the ACL file. (See @xref{Add +Administrators to the Acl File}.) In the following example, the administration principal @code{admin/admin} is created: @smallexample @@ -639,8 +746,8 @@ to the KDC's @code{/etc/rc} or @code{/etc/inittab} file. You need to have a stash file in order to do this. You can verify that they started properly by checking for their startup -messages in the logging locations you defined in @code{/etc/krb5.conf} -(see @xref{Edit the Configuration Files}). For example: +messages in the logging locations you defined in @code{/etc/krb5.conf}. +(See @xref{Edit the Configuration Files}.) For example: @smallexample @b{shell%} tail /var/log/krb5kdc.log @@ -909,7 +1016,7 @@ Once your KDCs are set up and running, you are ready to use @code{kadmin} to load principals for your users, hosts, and other services into the Kerberos database. This procedure is described fully in the ``Adding or Modifying Principals'' section of the @value{PRODUCT} System -Administrator's Guide. (@xref{Create Host Keys for the Slave KDCs} for a +Administrator's Guide. (@xref{Create Host Keys for the Slave KDCs}, for a brief description.) The keytab is generated by running @code{kadmin} and issuing the @code{ktadd} command. @@ -987,7 +1094,11 @@ Disable the cron job that propagates the database. @item Run your database propagation script manually, to ensure that the slaves all have the latest copy of the database. (@xref{Propagate the Database -to Each Slave KDC}.) +to Each Slave KDC}.) As of the 1.2.2 release, it is no longer necessary +to use ``kdb5_util dump -ov'' in order to preserve per-principal policy +information, as the default dump format now supports it. Note you +should update your slaves prior to your master, so that they will +understand the new dump format. (This is a good policy anyway.) @end enumerate On the @emph{new} master KDC: @@ -1007,6 +1118,7 @@ Database to Each Slave KDC}.) Switch the CNAMEs of the old and new master KDCs. (If you don't do this, you'll need to change the @code{krb5.conf} file on every client machine in your Kerberos realm.) + @end enumerate @node Installing and Configuring UNIX Client Machines, UNIX Application Servers, Installing KDCs, Installing Kerberos V5 @@ -1050,7 +1162,7 @@ counterparts @c @code{from} @code{su}, @code{passwd}, and @code{rdist}. -@node Client Machine Configuration Files, Mac OS X Configuration, Client Programs, Installing and Configuring UNIX Client Machines +@node Client Machine Configuration Files, , Client Programs, Installing and Configuring UNIX Client Machines @subsection Client Machine Configuration Files Each machine running Kerberos must have a @code{/etc/krb5.conf} file. @@ -1357,27 +1469,29 @@ should be readable only by root. If you already have an existing Kerberos database that you created with a prior release of Kerberos 5, you can upgrade it to work with the -current release with the @code{kdb5_util} command. The process for -upgrading a Master KDC involves the following steps (the lines beginning -with => indicate a continuation of the previous line): +current release with the @code{kdb5_util} command. It is only necessary +to perform this dump/undump procedure if you were running a krb5-1.0.x +KDC and are migrating to a krb5-1.1.x or newer KDC. The process for +upgrading a Master KDC involves the following steps: @enumerate -@item Stopping your current KDC and administration +@item Stop your current KDC and administration server processes, if any. -@item Dumping your existing Kerberos database to an ASCII file with +@item Dump your existing Kerberos database to an ASCII file with @code{kdb5_util}'s ``dump'' command: @smallexample @group -@b{shell%} kdb5_util -r @value{PRIMARYREALM} dump -@result{} @value{ROOTDIR}/var/krb5kdc/old-kdb-dump +@b{shell%} cd @value{ROOTDIR}/var/krb5kdc +@b{shell%} kdb5_util dump old-kdb-dump +@b{shell%} kdb5_util dump -ov old-kdb-dump.ov @b{shell%} @end group @end smallexample -@item Creating a new Master KDC installation (@xref{Install the Master +@item Create a new Master KDC installation (@xref{Install the Master KDC}). If you have a stash file for your current database, choose any new master password but then copy your existing stash file to the location specified by your kdc.conf; if you do not have a stash file for @@ -1388,17 +1502,64 @@ your current database, you must choose the same master password. @smallexample @group -@b{shell%} kdb5_util load @value{ROOTDIR}/var/krb5kdc/old-kdb-dump +@b{shell%} cd @value{ROOTDIR}/var/krb5kdc +@b{shell%} kdb5_util load old-kdb-dump +@b{shell%} kdb5_util load -update old-kdb-dump.ov @b{shell%} @end group @end smallexample @end enumerate +The ``dump -ov'' and ``load -update'' commands are necessary in order to +preserve per-principal policy information, since the dump format in +releases prior to 1.2.2 filters out that information. If you omit those +steps, the loaded database database will lose the policy information for +each principal that has a policy. + To update a Slave KDC, you must stop the old server processes on the Slave KDC, install the new server binaries, reload the most recent slave dump file, and re-start the server processes. +@menu +* Upgrading to Triple-DES Encryption Keys:: +@end menu + +@node Upgrading to Triple-DES Encryption Keys, , Upgrading Existing Kerberos V5 Installations, Upgrading Existing Kerberos V5 Installations +@section Upgrading to Triple-DES Encryption Keys + +Beginning with the 1.2 release from MIT, Kerberos includes a stronger +encryption algorithm called ``triple DES'' -- essentially, three +applications of the basic DES encryption algorithm, greatly increasing +the resistance to a brute-force search for the key by an attacker. This +algorithm is more secure, but encryption is much slower. We expect to +add other, faster encryption algorithms at some point in the future. + +Release 1.1 had some support for triple-DES service keys, but with +release 1.2 we have added support for user keys and session keys as +well. Release 1.0 had very little support for multiple cryptosystems, +and some of that software may not function properly in an environment +using triple-DES as well as plain DES. + +Because of the way the MIT Kerberos database is structured, the KDC will +assume that a service supports only those encryption types for which +keys are found in the database. Thus, if a service has only a +single-DES key in the database, the KDC will not issue tickets for that +service that use triple-DES session keys; it will instead issue only +single-DES session keys, even if other services are already capable of +using triple-DES. So if you make sure your application server software +is updated before adding a triple-DES key for the service, clients +should be able to talk to services at all times during the updating +process. + +Normally, the listed @code{supported_enctypes} in @code{kdc.conf} are +all used when a new key is generated. You can control this with +command-line flags to @code{kadmin} and @code{kadmin.local}. You may +want to exclude triple-DES by default until you have updated a lot of +your application servers, and then change the default to include +triple-DES. We recommend that you always include @code{des-cbc-crc} in +the default list. + @node Bug Reports for Kerberos V5, Files, Upgrading Existing Kerberos V5 Installations, Top @chapter Bug Reports for @value{PRODUCT} @@ -1422,8 +1583,8 @@ Here is an example @code{krb5.conf} file: [libdefaults] ticket_lifetime = 600 default_realm = @value{PRIMARYREALM} - default_tkt_enctypes = des-cbc-crc - default_tgs_enctypes = des-cbc-crc + default_tkt_enctypes = des3-hmac-sha1 des-cbc-crc + default_tgs_enctypes = des3-hmac-sha1 des-cbc-crc [realms] @value{PRIMARYREALM} = @{ @@ -1478,17 +1639,14 @@ Here's an example of a kdc.conf file: kadmind_port = 749 max_life = 10h 0m 0s max_renewable_life = 7d 0h 0m 0s - master_key_type = des-cbc-crc - supported_enctypes = des-cbc-crc:normal + master_key_type = des3-hmac-sha1 + supported_enctypes = des3-hmac-sha1:normal des-cbc-crc:normal @} @end group @end smallexample -To add Kerberos V4 support, change the @code{supported_enctypes} line to: - -@smallexample - supported_enctypes = des-cbc-crc:normal des-cbc-crc:v4 -@end smallexample +To add Kerberos V4 support, add @code{des-cbc-crc:v4} to the +@code{supported_enctypes} line. @menu * Encryption Types and Salt Types:: @@ -1497,9 +1655,8 @@ To add Kerberos V4 support, change the @code{supported_enctypes} line to: @node Encryption Types and Salt Types, , kdc.conf, kdc.conf @appendixsubsec Encryption Types and Salt Types -Currently, @value{PRODUCT} supports only DES and triple-DES encryption; -however, triple-DES is currently supported only for service keys, not -for user keys or session keys. The encoding types include +Currently, @value{PRODUCT} supports only DES and triple-DES encryption. +The encoding types include @code{des-cbc-crc} and @code{des3-cbc-sha1}. The @dfn{salt} is additional information encoded within the key that tells what kind of key it is. The only salts that you will be likely to encounter are: @@ -1509,6 +1666,8 @@ key it is. The only salts that you will be likely to encounter are: your @value{PRODUCT} keys @item @dfn{v4}, which is necessary only for compatibility with a v4 KDC +or a v4 version of @code{kinit}, and then only with @code{des-cbc-crc} +encryption @item @dfn{afs}, which you will never need to generate, and which you will encounter only if you dump an AFS database into a Kerberos database diff --git a/doc/krb425.texinfo b/doc/krb425.texinfo index e78d4e6..12572e5 100644 --- a/doc/krb425.texinfo +++ b/doc/krb425.texinfo @@ -140,6 +140,14 @@ This subsection allows the administrator to configure exceptions to the default_domain mapping rule. It contains V4 instances (tag name) which should be translated to some specific hostname (tag value) as the second component in a Kerberos V5 principal name. + +@itemx v4_realm +This relation allows the administrator to configure a different +realm name to be used when converting V5 principals to V4 +ones. This should only be used when running separate V4 and V5 +realms, with some external means of password sychronization +between the realms. + @end table @node kdc.conf, , krb5.conf, Configuration Files diff --git a/doc/send-pr.texinfo b/doc/send-pr.texinfo index 9209ffd..7cf9b70 100644 --- a/doc/send-pr.texinfo +++ b/doc/send-pr.texinfo @@ -4,7 +4,11 @@ built and installed @value{PRODUCT}, please use the Bug reports that include proposed fixes are especially welcome. If you do include fixes, please send them using either context diffs or unified -diffs (using @samp{diff -c} or @samp{diff -u}, respectively). +diffs (using @samp{diff -c} or @samp{diff -u}, respectively). Please be +careful when using ``cut and paste'' or other such means to copy a patch +into a bug report; depending on the system being used, that can result +in converting TAB characters into spaces, which makes applying the +patches more difficult. The @code{krb5-send-pr} program is installed in the directory @code{@value{ROOTDIR}/sbin}. diff --git a/src/ChangeLog b/src/ChangeLog index 25737d4..f7b13b1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,121 @@ +2002-11-03 Ken Raeburn + + * aclocal.m4 (AC_KRB5_TCL_FIND_CONFIG): Use 'eval' when setting + TCL_LIBS to force variable substitutions to take place. + + * aclocal.m4 (AC_KRB5_TCL): If --with-tcl is given, failure to + find a library we can use is now an error. + + [pullups from trunk] + +2002-11-03 Tom Yu + + * aclocal.m4 (AC_KRB5_TCL_FIND_CONFIG): Set TCL_LIBPATH and + TCL_RPATH. + [pullup from trunk] + +2001-11-03 Ken Raeburn + + * aclocal.m4 (AC_KRB5_TCL_FIND_CONFIG): Do put /usr/include/tcl$v + in TCL_INCLUDES if that's where tcl.h is found. Don't include + tcl.h when testing to see if Tcl_CreateInterp is available. + [pullup from trunk] + +2001-12-18 Tom Yu + + * aclocal.m4 (KRB5_LIB_PARAMS): Fix hpux to deal with building + shared libs with gcc. Patch from Doug Engert; fixes + krb5-build/1021. + +2001-11-27 Ken Raeburn + + * aclocal.m4 (KRB5_LIB_PARAMS): On Linux, add "-lc" to shared + library link line. + +2001-11-06 Danilo Almeida + + * Makefile.in: Prepare Makefile for ms2mit. + +2001-01-31 Tom Yu + + * aclocal.m4 (KRB5_LIB_PARAMS): Fix up previous patch to avoid + ordering issues when calling sed, as well as some quoting + nastiness due to bugs in kadmin/testing/scripts/env_setup.shin. + +2001-01-31 Tom Yu + + * aclocal.m4 (KRB5_LIB_PARAMS): Fix up Irix RUN_ENV to work around + LD_LIBRARY*_PATH's inability to override rpaths. + +2001-01-28 Tom Yu + + * aclocal.m4 (KRB5_LIB_AUX): Smash some shared lib file extensions + so that AIX doesn't break, since static and shared libs are + mutually exclusive on AIX. + +2000-06-22 Tom Yu + + * aclocal.m4 (CC_LINK_STATIC): Another fix for freebsd shared libs + from David Cross. + +2000-06-21 Ken Raeburn + + * aclocal.m4 (KRB5_AC_ENABLE_DNS): Rewrite to fix logic. Now + --enable-dns-for-XX really will be heeded for setting default + behavior. Also, DNS support can now be compiled in while still + turned off by default. Print out whether the DNS support will be + compiled in. + +2000-06-21 Tom Yu + + * aclocal.m4: Fix freebsd CC_LINK_SHARED to have correct rpath + flags. Thanks to David Cross. + +2000-06-08 Tom Yu + + * aclocal.m4 (CC_LINK_STATIC): Fix to use old library search + order; otherwise if there are shared libraries with the same name + elsewhere in the search path, they'll take precedence over the + static ones in the tree. + +2000-05-08 Nalin Dahyabhai + + * wconfig.c (main): Warn if copying command-line option string + will overflow internal buffer. + +2000-05-03 Tom Yu + + * aclocal.m4 (AC_KRB5_TCL_TRYOLD): Search by appending stuff to + CPPFLAGS and LDFLAGS to notice if there may be problems with stuff + earlier along in either variable overriding. + +2000-04-18 Ken Raeburn + + * aclocal.m4 (KRB5_AC_ENABLE_DNS): Set RESOLV_LIB, and substitute + it into the Makefile. + (AC_LIBRARY_NET): Set RESOLV_LIB. + +2000-04-18 Danilo Almeida + + * Makefile.in (clean-windows): Actually clean gss-sample on Windows. + +2000-04-11 Danilo Almeida + + * Makefile.in (clean-windows): Clean gss-sample on Windows. + +2000-04-04 Ken Raeburn + + * aclocal.m4 (KRB5_AC_ENABLE_DNS): Check for dns, dns-for-kdc, and + dns-for-realm separately. Define KRB5_DNS_LOOKUP if either mode + is enabled. Define KRB5_DNS_LOOKUP_KDC and KRB5_DNS_LOOKUP_REALM + if the appropriate modes are enabled. + * acconfig.h (KRB5_DNS_LOOKUP_KDC, KRB5_DNS_LOOKUP_REALM): Undef. + +2000-03-24 Ken Raeburn + + * aclocal.m4 (KRB5_LIB_PARAMS): Check for alpha*-dec-osf* instead + of alpha-dec-osf*. + 2000-03-15 Ken Raeburn * aclocal.m4 (KRB5_AC_ENABLE_DNS): Fix typo that caused the DNS diff --git a/src/Makefile.in b/src/Makefile.in index 57efe5e..229efb0 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -11,7 +11,7 @@ HDRS = DISTFILES = $(SRCS) $(HDRS) COPYING COPYING.LIB ChangeLog Makefile.in -all-unix:: +all-unix:: krb5-config all-mac:: @@ -161,7 +161,8 @@ WINMAKEFILES=Makefile \ util\windows\Makefile \ windows\Makefile windows\lib\Makefile \ windows\cns\Makefile windows\gina\Makefile \ - windows\gss\Makefile windows\wintel\Makefile + windows\gss\Makefile windows\ms2mit\Makefile \ + windows\wintel\Makefile ##DOS##Makefile-windows:: $(MKFDEP) $(WINMAKEFILES) @@ -271,6 +272,8 @@ WINMAKEFILES=Makefile \ ##DOS## $(WCONFIG) config < $@.in > $@ ##DOS##windows\gss\Makefile: windows\gss\Makefile.in $(MKFDEP) ##DOS## $(WCONFIG) config < $@.in > $@ +##DOS##windows\ms2mit\Makefile: windows\ms2mit\Makefile.in $(MKFDEP) +##DOS## $(WCONFIG) config < $@.in > $@ ##DOS##windows\wintel\Makefile: windows\wintel\Makefile.in $(MKFDEP) ##DOS## $(WCONFIG) config < $@.in > $@ @@ -290,7 +293,10 @@ clean-windows:: Makefile-windows @echo Making clean in clients cd ..\clients $(MAKE) -$(MFLAGS) clean - cd .. + @echo Making in appl\gss-sample + cd ..\appl\gss-sample + $(MAKE) -$(MFLAGS) clean + cd ..\.. @echo Making clean in root # @@ -324,7 +330,7 @@ FILES= ./* \ util/* util/et/* util/profile/* WINFILES= util/windows/* windows/* windows/lib/* windows/cns/* \ - windows/wintel/* windows/gss/* windows/gina/* + windows/wintel/* windows/gss/* windows/gina/* windows/ms2mit/* MACFILES= mac/* mac/libraries/* config/* include/* \ include/krb5/* include/krb5/stock/* include/sys/* \ @@ -543,3 +549,11 @@ install-windows:: $(CP) clients\kpasswd\$(OUTPRE)kpasswd.exe "$(KRB_INSTALL_DIR)\bin\." @if exist "$(KRB_INSTALL_DIR)\bin\krb4_32.dll" del "$(KRB_INSTALL_DIR)\bin\krb4_32.dll" @if exist "$(KRB_INSTALL_DIR)\lib\krb4_32.lib" del "$(KRB_INSTALL_DIR)\lib\krb4_32.lib" + +install-unix:: + $(INSTALL) krb5-config \ + $(DESTDIR)$(CLIENT_BINDIR)/krb5-config + +krb5-config: $(srcdir)/krb5-config.in $(thisconfigdir)/config.status + cd $(thisconfigdir) && $(SHELL) config.status + diff --git a/src/acconfig.h b/src/acconfig.h index e6f00c7..7ac14f0 100644 --- a/src/acconfig.h +++ b/src/acconfig.h @@ -32,6 +32,8 @@ /* Define if DNS support for finding realms and KDC locations should be compiled in. */ #undef KRB5_DNS_LOOKUP +#undef KRB5_DNS_LOOKUP_KDC +#undef KRB5_DNS_LOOKUP_REALM /* Define to `long' if doesn't define. */ #undef time_t diff --git a/src/aclocal.m4 b/src/aclocal.m4 index 3228610..4785939 100644 --- a/src/aclocal.m4 +++ b/src/aclocal.m4 @@ -722,8 +722,7 @@ if test -n "$tcl_conf" ; then done LIBS="$old_LIBS `eval echo x $TCL_LIB_SPEC $TCL_LIBS | sed 's/^x//'`" LDFLAGS="$old_LDFLAGS $TCL_LD_FLAGS" - AC_TRY_LINK([#include -],[Tcl_CreateInterp ();], + AC_TRY_LINK( , [Tcl_CreateInterp ();], tcl_ok_conf=$file tcl_vers_maj=$TCL_MAJOR_VERSION tcl_vers_min=$TCL_MINOR_VERSION @@ -743,17 +742,19 @@ tcl_lib=no if test -n "$tcl_ok_conf" ; then . $tcl_ok_conf TCL_INCLUDES= - if test "$TCL_PREFIX" != /usr ; then - for incdir in "$TCL_PREFIX/include/tcl$v" "$TCL_PREFIX/include" ; do - if test -r "$incdir/tcl.h" -o -r "$incdir/tcl/tcl.h" ; then + for incdir in "$TCL_PREFIX/include/tcl$v" "$TCL_PREFIX/include" ; do + if test -r "$incdir/tcl.h" -o -r "$incdir/tcl/tcl.h" ; then + if test "$incdir" != "/usr/include" ; then TCL_INCLUDES=-I$incdir - break fi - done - fi - TCL_LIBS="$TCL_LIB_SPEC $TCL_LIBS $TCL_DL_LIBS" - TCL_LIBPATH= - TCL_RPATH= + break + fi + done + # Need eval because the first-level expansion could reference + # variables like ${TCL_DBGX}. + eval TCL_LIBS='"'$TCL_LIB_SPEC $TCL_LIBS $TCL_DL_LIBS'"' + TCL_LIBPATH="-L$TCL_EXEC_PREFIX/lib" + TCL_RPATH=":$TCL_EXEC_PREFIX/lib" CPPFLAGS="$old_CPPFLAGS $TCL_INCLUDES" AC_CHECK_HEADER(tcl.h,AC_DEFINE(HAVE_TCL_H) tcl_header=yes) if test $tcl_header=no; then @@ -783,8 +784,8 @@ if test "$with_tcl" != no ; then AC_CHECK_LIB(ld, main, DL_LIB=-lld) krb5_save_CPPFLAGS="$CPPFLAGS" krb5_save_LDFLAGS="$LDFLAGS" - CPPFLAGS="$TCL_INCLUDES $CPPFLAGS" - LDFLAGS="$TCL_LIBPATH $LDFLAGS" + CPPFLAGS="$CPPFLAGS $TCL_INCLUDES" + LDFLAGS="$LDFLAGS $TCL_LIBPATH" tcl_header=no AC_CHECK_HEADER(tcl.h,AC_DEFINE(HAVE_TCL_H) tcl_header=yes) if test $tcl_header=no; then @@ -857,12 +858,17 @@ if test "$with_tcl" != no ; then if test $tcl_lib = no ; then if test "$with_tcl" != try ; then AC_KRB5_TCL_TRYOLD -dnl AC_MSG_ERROR(Could not find Tcl) else AC_MSG_WARN(Could not find Tcl which is needed for some tests) fi fi fi +# If "yes" or pathname, error out if not found. +if test "$with_tcl" != no -a "$with_tcl" != try ; then + if test "$tcl_header $tcl_lib" != "yes yes" ; then + AC_MSG_ERROR(Could not find Tcl) + fi +fi ])dnl dnl @@ -1030,8 +1036,18 @@ AC_ARG_ENABLE([shared], AC_MSG_RESULT([Forcing static libraries.]) # avoid duplicate rules generation for AIX and such SHLIBEXT=.so-nobuild + SHLIBVEXT=.so.v-nobuild + SHLIBSEXT=.so.s-nobuild else AC_MSG_RESULT([Enabling shared libraries.]) + # Clear some stuff in case of AIX, etc. + if test "$STLIBEXT" = "$SHLIBEXT" ; then + STLIBEXT=.a-nobuild + LIBLIST= + LIBLINKS= + OBJLISTS= + LIBINSTLIST= + fi LIBLIST="$LIBLIST "'lib$(LIB)$(SHLIBEXT)' LIBLINKS="$LIBLINKS "'$(TOPLIBD)/lib$(LIB)$(SHLIBEXT) $(TOPLIBD)/lib$(LIB)$(SHLIBVEXT)' case "$SHLIBSEXT" in @@ -1060,9 +1076,11 @@ else SHLIBVEXT=.so.v-nobuild SHLIBSEXT=.so.s-nobuild fi], - RUN_ENV= +[ RUN_ENV= CC_LINK="$CC_LINK_STATIC" -)dnl + SHLIBEXT=.so-nobuild + SHLIBVEXT=.so.v-nobuild + SHLIBSEXT=.so.s-nobuild])dnl if test -z "$LIBLIST"; then AC_MSG_ERROR([must enable one of shared or static libraries]) @@ -1119,7 +1137,7 @@ CC_LINK_STATIC='$(CC) $(PROG_LIBPATH)' # Set up architecture-specific variables. case $krb5_cv_host in -alpha-dec-osf*) +alpha*-dec-osf*) SHLIBVEXT='.so.$(LIBMAJOR).$(LIBMINOR)' SHLIBSEXT='.so.$(LIBMAJOR)' SHLIBEXT=.so @@ -1129,7 +1147,11 @@ alpha-dec-osf*) SHLIB_EXPFLAGS='-rpath $(SHLIB_RDIRS) $(SHLIB_DIRS) $(SHLIB_EXPLIBS)' PROFFLAGS=-pg CC_LINK_SHARED='$(CC) $(PROG_LIBPATH) -Wl,-rpath -Wl,$(PROG_RPATH)' - CC_LINK_STATIC='$(CC) $(PROG_LIBPATH)' + # Need -oldstyle_liblookup to avoid picking up shared libs from + # other builds. OSF/1 / Tru64 ld programs look through the entire + # library path for shared libs prior to looking through the + # entire library path for static libs. + CC_LINK_STATIC='$(CC) $(PROG_LIBPATH) -Wl,-oldstyle_liblookup' # $(PROG_RPATH) is here to handle things like a shared tcl library RUN_ENV='LD_LIBRARY_PATH=`echo $(PROG_LIBPATH) | sed -e "s/-L//g" -e "s/ /:/g"`:$(PROG_RPATH):/usr/shlib:/usr/ccs/lib:/usr/lib/cmplrs/cc:/usr/lib:/usr/local/lib; export LD_LIBRARY_PATH; _RLD_ROOT=/dev/dummy/d; export _RLD_ROOT;' ;; @@ -1145,13 +1167,22 @@ alpha-dec-osf*) # (compiled-in or SHLIB_PATH) will be searched first. # *-*-hpux*) - PICFLAGS=+z + if test "$krb5_cv_prog_gcc" = yes; then + PICFLAGS=-fPIC + else + PICFLAGS=+z + fi INSTALL_SHLIB='$(INSTALL)' SHLIBEXT=.sl SHLIBVEXT='.$(LIBMAJOR).$(LIBMINOR)' SHLIBSEXT='.$(LIBMAJOR)' - SHLIB_EXPFLAGS='+s +b $(SHLIB_RDIRS) $(SHLIB_DIRS) $(SHLIB_EXPLIBS)' - LDCOMBINE='ld -b +h lib$(LIB)$(SHLIBSEXT)' + if test "$krb5_cv_prog_gcc" = yes; then + SHLIB_EXPFLAGS='-Wl,+s -Wl,+b,$(SHLIB_RDIRS) $(SHLIB_DIRS) $(SHLIB_EXPLIBS)' + LDCOMBINE='gcc -fPIC -shared -Wl,+h,lib$(LIB)$(SHLIBSEXT)' + else + SHLIB_EXPFLAGS='+s +b $(SHLIB_RDIRS) $(SHLIB_DIRS) $(SHLIB_EXPLIBS)' + LDCOMBINE='ld -b +h lib$(LIB)$(SHLIBSEXT)' + fi CC_LINK_SHARED='$(CC) $(PROG_LIBPATH) -Wl,+s -Wl,+b,$(PROG_RPATH)' CC_LINK_STATIC='$(CC) $(PROG_LIBPATH)' RUN_ENV='SHLIB_PATH=`echo $(PROG_LIBPATH) | sed -e "s/-L//g" -e "s/ /:/g"`; export SHLIB_PATH;' @@ -1173,7 +1204,15 @@ mips-sgi-irix6.3) # This is a Kludge; see below PROFFLAGS=-p CC_LINK_SHARED='$(CC) $(PROG_LIBPATH) -Wl,-rpath -Wl,$(PROG_RPATH)' CC_LINK_STATIC='$(CC) $(PROG_LIBPATH)' - RUN_ENV='LD_LIBRARY_PATH=`echo $(PROG_LIBPATH) | sed -e "s/-L//g" -e "s/ /:/g"`; export LD_LIBRARY_PATH;' + # This grossness is necessary due to the presence of *three* + # supported ABIs on Irix, and the precedence of the rpath over + # LD_LIBRARY*_PATH. Like OSF/1, _RLD*_ROOT needs to be set to + # work around this lossage. + add='`echo $(PROG_LIBPATH) | sed -e "s/-L//g" -e "s/ /:/g"`' + dummy=/dev/dummmy/d + # Set the N32 and 64 variables first because the unqualified + # variables affect all three and can cause the sed command to fail. + RUN_ENV="LD_LIBRARYN32_PATH=$add:/usr/lib32:/usr/lib32/internal:/lib32:/opt/lib32; export LD_LIBRARYN32_PATH; _RLDN32_ROOT=$dummy; export _RLDN32_ROOT; LD_LIBRARY64_PATH=$add:/usr/lib64:/usr/lib64/internal:/lib64:/opt/lib64; export LD_LIBRARY64_PATH; _RLD64_ROOT=$dummy; export _RLD64_ROOT; LD_LIBRARY_PATH=$add:/usr/lib:/usr/lib/internal:/lib:/lib/cmplrs/cc:/usr/lib/cmplrs/cc:/opt/lib; export LD_LIBRARY_PATH; _RLD_ROOT=$dummy; export _RLD_ROOT;" ;; mips-sgi-irix*) @@ -1187,7 +1226,15 @@ mips-sgi-irix*) PROFFLAGS=-p CC_LINK_SHARED='$(CC) $(PROG_LIBPATH) -Wl,-rpath -Wl,$(PROG_RPATH)' CC_LINK_STATIC='$(CC) $(PROG_LIBPATH)' - RUN_ENV='LD_LIBRARY_PATH=`echo $(PROG_LIBPATH) | sed -e "s/-L//g" -e "s/ /:/g"`; export LD_LIBRARY_PATH;' + # This grossness is necessary due to the presence of *three* + # supported ABIs on Irix, and the precedence of the rpath over + # LD_LIBRARY*_PATH. Like OSF/1, _RLD*_ROOT needs to be set to + # work around this lossage. + add='`echo $(PROG_LIBPATH) | sed -e "s/-L//g" -e "s/ /:/g"`' + dummy=/dev/dummmy/d + # Set the N32 and 64 variables first because the unqualified + # variables affect all three and can cause the sed command to fail. + RUN_ENV="LD_LIBRARYN32_PATH=$add:/usr/lib32:/usr/lib32/internal:/lib32:/opt/lib32; export LD_LIBRARYN32_PATH; _RLDN32_ROOT=$dummy; export _RLDN32_ROOT; LD_LIBRARY64_PATH=$add:/usr/lib64:/usr/lib64/internal:/lib64:/opt/lib64; export LD_LIBRARY64_PATH; _RLD64_ROOT=$dummy; export _RLD64_ROOT; LD_LIBRARY_PATH=$add:/usr/lib:/usr/lib/internal:/lib:/lib/cmplrs/cc:/usr/lib/cmplrs/cc:/opt/lib; export LD_LIBRARY_PATH; _RLD_ROOT=$dummy; export _RLD_ROOT;" ;; # untested... @@ -1243,7 +1290,7 @@ mips-*-netbsd*) PICFLAGS=-fpic if test "x$objformat" = "xelf" ; then SHLIBVEXT='.so.$(LIBMAJOR)' - CC_LINK_SHARED='$(CC) $(PROG_LIBPATH) -Wl,-rpath -Wl,-R$(PROG_RPATH)' + CC_LINK_SHARED='$(CC) $(PROG_LIBPATH) -Wl,-rpath -Wl,$(PROG_RPATH)' else SHLIBVEXT='.so.$(LIBMAJOR).$(LIBMINOR)' CC_LINK_SHARED='$(CC) $(PROG_LIBPATH) -R$(PROG_RPATH)' @@ -1324,7 +1371,7 @@ mips-*-netbsd*) # Linux ld doesn't default to stuffing the SONAME field... # Use objdump -x to examine the fields of the library LDCOMBINE='ld -shared -h lib$(LIB)$(SHLIBSEXT)' - SHLIB_EXPFLAGS='-R$(SHLIB_RDIRS) $(SHLIB_DIRS) $(SHLIB_EXPLIBS)' + SHLIB_EXPFLAGS='-R$(SHLIB_RDIRS) $(SHLIB_DIRS) $(SHLIB_EXPLIBS) -lc' PROFFLAGS=-pg CC_LINK_SHARED='$(CC) $(PROG_LIBPATH) -Wl,-rpath -Wl,$(PROG_RPATH)' CC_LINK_STATIC='$(CC) $(PROG_LIBPATH)' @@ -1396,7 +1443,8 @@ AC_DEFUN(AC_LIBRARY_NET, [ # ugliness is necessary: AC_CHECK_LIB(socket, gethostbyname, LIBS="-lsocket -lnsl $LIBS", - AC_CHECK_LIB(resolv, gethostbyname), + AC_CHECK_LIB(resolv, gethostbyname, + LIBS="-lresolv $LIBS" ; RESOLV_LIB=-lresolv), -lnsl) ) ) @@ -1406,20 +1454,61 @@ AC_DEFUN(AC_LIBRARY_NET, [ KRB5_AC_ENABLE_DNS if test "$enable_dns" = yes ; then AC_CHECK_FUNC(res_search, , AC_CHECK_LIB(resolv, res_search, - LIBS="$LIBS -lresolv", + LIBS="$LIBS -lresolv" ; RESOLV_LIB=-lresolv, AC_ERROR(Cannot find resolver support routine res_search in -lresolv.) )) fi + AC_SUBST(RESOLV_LIB) ]) dnl dnl dnl KRB5_AC_ENABLE_DNS dnl AC_DEFUN(KRB5_AC_ENABLE_DNS, [ +AC_MSG_CHECKING(if DNS Kerberos lookup support should be compiled in) + AC_ARG_ENABLE([dns], -[ --enable-dns enable DNS lookups of Kerberos realm and servers], , -[enable_dns=no]) - if test "$enable_dns" = yes; then +[ --enable-dns build in support for Kerberos-related DNS lookups], , +[enable_dns=default]) + + AC_ARG_ENABLE([dns-for-kdc], +[ --enable-dns-for-kdc enable DNS lookups of Kerberos KDCs (default=YES)], , +[case "$enable_dns" in + yes | no) enable_dns_for_kdc=$enable_dns ;; + *) enable_dns_for_kdc=yes ;; +esac]) + if test "$enable_dns_for_kdc" = yes; then + AC_DEFINE(KRB5_DNS_LOOKUP_KDC) + fi + + AC_ARG_ENABLE([dns-for-realm], +[ --enable-dns-for-realm enable DNS lookups of Kerberos realm names], , +[case "$enable_dns" in + yes | no) enable_dns_for_realm=$enable_dns ;; + *) enable_dns_for_realm=no ;; +esac]) + if test "$enable_dns_for_realm" = yes; then + AC_DEFINE(KRB5_DNS_LOOKUP_REALM) + fi + + if test "$enable_dns_for_kdc,$enable_dns_for_realm" != no,no + then + # must compile in the support code + if test "$enable_dns" = no ; then + AC_MSG_ERROR(cannot both enable some DNS options and disable DNS support) + fi + enable_dns=yes + fi + if test "$enable_dns" = yes ; then AC_DEFINE(KRB5_DNS_LOOKUP) + else + enable_dns=no fi + +AC_MSG_RESULT($enable_dns) +dnl AC_MSG_CHECKING(if DNS should be used to find KDCs by default) +dnl AC_MSG_RESULT($enable_dns_for_kdc) +dnl AC_MSG_CHECKING(if DNS should be used to find realm name by default) +dnl AC_MSG_RESULT($enable_dns_for_realm) + ]) diff --git a/src/appl/bsd/ChangeLog b/src/appl/bsd/ChangeLog index d3314b0..73c12dc 100644 --- a/src/appl/bsd/ChangeLog +++ b/src/appl/bsd/ChangeLog @@ -1,3 +1,223 @@ +2002-01-25 Ken Raeburn + + * login.c (main): Fix fencepost error in last change. + +2001-12-21 Ken Raeburn + + * loginpaths.h [_PATH_DEFPATH]: Undefine LPATH and RPATH before + redefining them. + * login.c (main): If the supplied name is longer than the utmp + buffer, don't bother trying it as a username. + (dolastlog): Don't assume lastlog.ll_time is a time_t. + +2001-01-13 Sam Hartman + + * configure.in: Force SunOS to not use termios. + [pullup 5.89->5.90 from trunk] + +2001-01-12 Sam Hartman + + * krlogin.c: Previously, we only used TIOCGLTC on systems with + termios. This is sort of silly since its a BSD 4.[23] IOCTL. We + then go out of our way not to use it on IRIX, Solaris or HPUX. I + think all this comes about because you really want to use BSD + IOCTLS on Sunos rather than termios. I propose to do that and + never [s/never/only/? --tlyu] use BSD IOCTLs on Sunos. + [pullup 5.68->5.69 from trunk] + +2001-09-07 Tom Yu + + * krlogind.c (protocol): Don't do TIOCPKT on systems with STREAMS + ptys, even if there is a TIOCPKT, since it may result in hangs on + some systems where BSD packet mode is (presumably) not implemented + properly, such as AIX 4.3.3. Should get cleaned up at some later + point to actually I_PUSH "pckt" or equivalent and do translation + between STREAMS and BSD style packet mode. + [pullup from trunk] + +2001-02-16 Tom Yu + + * login.M: Don't include "= 0" as part of the "accept_passwd" + config option. + +2001-01-26 Tom Yu + + * krshd.c: Get path for NOLOGIN file from paths.h if present, + mirroring logic in login.c. [patch from David MacKenzie + krb5-appl/913, pulled up from trunk] + +2001-01-26 Tom Yu + + * krlogin.c (read_wrapper): Copy from the current point and not + the start of the cached buffer. [pullup from trunk] + +2001-01-23 Tom Yu + + * forward.c (rd_and_store_for_creds): Overwrite any existing value + of the KRB5CCNAME environment variable. + +2000-07-19 Peter S Litwack + + * krlogin.c (writer): Improved bandwith efficiency by reading + and sending more than one character at a time if multiple + characters are available to be read from the terminal. + * krlogin.c (read_wrapper): Added this function as a helper + to writer. It facilitates checking for escape sequences + (~^Z etc.) when reading mulitple characters at a time. + +2000-06-29 Ken Raeburn + + Patch from Donn Cave and Leonard Peirce from 1.1 release cycle: + * login.c (k_init): Call krb5_cc_set_default_name right after + setting the environment variable. + (main): Likewise. + +2000-06-23 Ken Raeburn + + * rcp.M, rsh.M, rlogin.M: Add description of new -PO, -PN + options. + +2000-06-19 Tom Yu + + * krshd.c (recvauth): Call krb5_recvauth_version() rather than + calling krb5_recvauth() with arguments intended for + krb5_recvauth_version(). + + * kcmd.c: Conditionalize krb_sendauth prototype based on sense of + KRB5_KRB4_COMPAT. + +2000-06-15 Tom Yu + + * login.c (try_convert524): Add use_ccache argument. Handle case + where we have gotten v5 creds via password being entered and don't + crash in that case, since previous code was assuming that v5 creds + were always being provided. Adapted from patch by Bob Basch. + +2000-06-10 Ken Raeburn + + * krcp.c (main): Fix logic again, this time in the "success" + case. If there's a problem retrieving the new-protocol subkey, + print a message and exit, don't fall back. + * krsh.c (main): Ditto; don't look at enctype to try to guess + protocol version. Delete unused variable "similar". + +2000-06-09 Ken Raeburn + + * krlogin.c (main): Rework fallback logic. Fall back to k4cmd + unless encryption and the new protocol were both requested. + + * krsh.c (main): Rework fallback logic. Fall back to k4cmd if new + protocol wasn't requested. + + * krcp.c (main): Revert setting of AP_OPTS_MUTUAL_REQUIRED + unconditionally, which was added by mistake with last set of + patches. If kcmd fails and the new protocol is requested, don't + fall back to v4. + +2000-05-31 Ken Raeburn + + * Makefile.in (kcmd.o, krcp.o, krlogin.o, krlogind.o, krsh.o, + krshd.o): Depend on defines.h. + * krlogind.c: Include defines.h. + * krcp.c: Ditto. + + * defines.h (enum kcmd_proto): New type. + (rcmd_stream_read, rcmd_stream_write, getport, + rcmd_stream_init_krb5): Add prototypes. + + * kcmd.c (use_ivecs): New variable. + (encivec_i, encivec_o): Each is now an array of two elements. + (input, output, twrite, krb5_write_message, krb5_net_read, + krb5_net_write, krb_sendauth): Add prototypes. + (kcmd): New argument PROTONUMP points to enum kcmd_proto. If + value is KCMD_PROTOCOL_COMPAT_HACK, set it to KCMD_NEW_PROTOCOL or + KCMD_OLD_PROTOCOL depending on session key type. Use subkeys for + new protocol. Callers updated. + (normal_read, v5_des_read, v4_des_read, twrite, v5_des_write, + v4_des_write, rcmd_stream_write, rcmd_stream_read): Take + additional argument indicating whether the fd is for the secondary + channel; ignored except in some v5 cases. Callers updated. + (rcmd_stream_init_krb5): New argument, kcmd protocol version. Set + up ivecs for secondary channel in each direction with values 0x2 + ior primary channel value. Callers updated. + (v5_des_read, v5_des_write): For new protocol, plaintext now has + its length prepended but not counted. + + * krcp.c (main): Set kcmd protocol version based on command line, + not on encryption type. Default to COMPAT_HACK. + * krsh.c (main): Ditto. + * krlogin.c (main): Ditto. + + * krlogind.c (recvauth): Use new krb5_compat_recvauth_version + routine. Determine client's kcmd protocol version and initialize + based on it. + * krshd.c (recvauth): Ditto. + +2000-05-19 Nalin Dahyabhai + Ken Raeburn + + * krcp.c (sink): bail if the target directory/file name is too long + * krlogind.c (recvauth, krb4 compat): truncate user name if the + principal's root would be too long to be valid + * v4rcp.c (sink): bail if the target directory/file name is too long + +2000-05-18 Tom Yu + + * krshd.c: Shuffle inclusion of defines.h so that some krb5 + structures are declared prior to the kcmd() prototype. + +2000-05-16 Ken Raeburn + + * defines.h (kcmd): Add prototype. + * krcp.c (main): Add extra arg to a kcmd call I missed yesterday. + +2000-05-15 Ken Raeburn + + * krcp.c (main): Fix some conditionalizations to make proper + indentation easier. + + * kcmd.c (encivec_i, encivec_o): New variables replace old single + variable encivec. + (rcmd_stream_init_krb5): New argument am_client, used to + initialize both ivec values. + * krcp.c (main, answer_auth): Pass new argument. + * krlogin.c (main): Ditto. + * krlogind.c (recvauth): Ditto. + * krsh.c (main): Ditto. + * krshd.c (recvauth): Ditto. + + * defines.h (OPTS_FORWARD_CREDS, OPTS_FORWARDABLE_CREDS): Change + numbers so they don't conflict with AP_OPTS_USE_SUBKEY. + * kcmd.c (kcmd): New argument authconp, used to return the auth + context to the caller if desired. + * krlogin.c (auth_context): New variable. + (main): Request a subkey from sendauth. Get the auth context from + kcmd so we can retrieve the subkey. If non-DES session key is + being used, pass the subkey to rcmd_stream_init_krb5 instead of + the session key; fail if no subkey is found and encryption is + required. + * krlogind.c (recvauth): If a non-DES session key is being used, + pass the client-provided subkey to rcmd_stream_init_krb5. + * krcp.c (main): Set up and use subkey as above. + * krsh.c (main): Set up and use subkey as above. + * krshd.c (recvauth): Accept and use subkey as above. + +2000-05-08 Ken Raeburn + + * v4rcp.c (main, case 'k'): Make sure krb_realm is + null-terminated. + +2000-04-27 Nalin Dahyabhai + + * krlogin.c (main): Don't overflow buffer "term". + * krshd.c (doit): Don't overflow buffer "cmdbuf". + * login.c (afs_login): Don't overflow buffer "aklog_path". + +2000-03-24 Ken Raeburn + + * configure.in: Check for alpha*-dec-osf* instead of + alpha-dec-osf*. + 2000-03-15 Ken Raeburn Mark D. Roth diff --git a/src/appl/bsd/Makefile.in b/src/appl/bsd/Makefile.in index eee13ca..93a6cba 100644 --- a/src/appl/bsd/Makefile.in +++ b/src/appl/bsd/Makefile.in @@ -90,3 +90,4 @@ install:: getdtablesize.o: $(srcdir)/getdtablesize.c +kcmd.o krcp.o krlogin.o krlogind.o krsh.o krshd.o : defines.h diff --git a/src/appl/bsd/configure.in b/src/appl/bsd/configure.in index 6d31f48..051af51 100644 --- a/src/appl/bsd/configure.in +++ b/src/appl/bsd/configure.in @@ -25,16 +25,20 @@ dnl Make our operating system-specific security checks and definitions for dnl login. dnl case $krb5_cv_host in -*-*-aix3*) # AIX has streams include files but not streams TTY -# Moreover, strops.h trashes sys/ioctl.h -krb5_cv_has_streams=no -;; -alpha-dec-osf*) +*-*-aix3*) + # AIX has streams include files but not streams TTY + # Moreover, strops.h trashes sys/ioctl.h + krb5_cv_has_streams=no + ;; +alpha*-dec-osf*) AC_CHECK_LIB(security,setluid, AC_DEFINE(HAVE_SETLUID) LOGINLIBS="$LOGINLIBS -lsecurity" ) ;; +*-*-sunos4*) + ac_cv_header_termios_h=no + ;; esac dnl dnl After beta6 this functionality will be integrated with aclocal.m4 diff --git a/src/appl/bsd/defines.h b/src/appl/bsd/defines.h index fd9c3e1..6365d2c 100644 --- a/src/appl/bsd/defines.h +++ b/src/appl/bsd/defines.h @@ -1,3 +1,43 @@ -#define OPTS_FORWARD_CREDS 0x00000002 -#define OPTS_FORWARDABLE_CREDS 0x00000001 +#define OPTS_FORWARD_CREDS 0x00000020 +#define OPTS_FORWARDABLE_CREDS 0x00000010 #define RCMD_BUFSIZ 5120 + +enum kcmd_proto { + /* Old protocol: DES encryption only. No subkeys. No protection + for cleartext length. No ivec supplied. OOB hacks used for + rlogin. Checksum may be omitted at connection startup. */ + KCMD_OLD_PROTOCOL = 1, + /* New protocol: Any encryption scheme. Client-generated subkey + required. Prepend cleartext-length to cleartext data (but don't + include it in count). Starting ivec defined, chained. In-band + signalling. Checksum required. */ + KCMD_NEW_PROTOCOL, + /* Hack: Get credentials, and use the old protocol iff the session + key type is single-DES. */ + KCMD_PROTOCOL_COMPAT_HACK, + /* Using Kerberos version 4. */ + KCMD_V4_PROTOCOL, + /* ??? */ + KCMD_UNKNOWN_PROTOCOL +}; + +extern int kcmd (int *sock, char **ahost, int /* u_short */ rport, + char *locuser, char *remuser, char *cmd, + int *fd2p, char *service, char *realm, + krb5_creds **cred, + krb5_int32 *seqno, krb5_int32 *server_seqno, + struct sockaddr_in *laddr, + struct sockaddr_in *faddr, + krb5_auth_context *authconp, + krb5_flags authopts, + int anyport, int suppress_err, + enum kcmd_proto *protonum /* input and output */ + ); + +extern int rcmd_stream_read (int fd, char *buf, int len, int secondary); +extern int rcmd_stream_write (int fd, char *buf, int len, int secondary); +extern int getport (int *); + +extern void rcmd_stream_init_krb5 (krb5_keyblock *in_keyblock, + int encrypt_flag, int lencheck, + int am_client, enum kcmd_proto protonum); diff --git a/src/appl/bsd/forward.c b/src/appl/bsd/forward.c index e22fc1d..e47b8ff 100644 --- a/src/appl/bsd/forward.c +++ b/src/appl/bsd/forward.c @@ -51,7 +51,7 @@ rd_and_store_for_creds(context, auth_context, inbuf, ticket, ccache) */ sprintf(ccname, "FILE:/tmp/krb5cc_p%d", getpid()); - setenv("KRB5CCNAME", ccname, 0); + setenv("KRB5CCNAME", ccname, 1); if (retval = krb5_cc_resolve(context, ccname, ccache)) goto cleanup; diff --git a/src/appl/bsd/kcmd.c b/src/appl/bsd/kcmd.c index 0e68f88..3e401cc 100644 --- a/src/appl/bsd/kcmd.c +++ b/src/appl/bsd/kcmd.c @@ -117,14 +117,18 @@ static char des_inbuf[2*RCMD_BUFSIZ]; /* needs to be > largest read size */ static char des_outpkt[2*RCMD_BUFSIZ+4]; /* needs to be > largest write size */ static krb5_data desinbuf; static krb5_data desoutbuf; -static krb5_data encivec; + +/* XXX Overloaded: use_ivecs!=0 -> new protocol, inband signalling, etc. */ +static int use_ivecs; +static krb5_data encivec_i[2], encivec_o[2]; + static krb5_keyblock *keyblock; /* key for encrypt/decrypt */ -static int (*input)(); -static int (*output)(); +static int (*input)(int, char *, int, int); +static int (*output)(int, char *, int, int); static char storage[2*RCMD_BUFSIZ]; /* storage for the decryption */ static int nstored = 0; static char *store_ptr = storage; -static int twrite(); +static int twrite(int, char *, int, int); static int v5_des_read(), v5_des_write(); #ifdef KRB5_KRB4_COMPAT static int v4_des_read(), v4_des_write(); @@ -133,8 +137,29 @@ static int right_justify; #endif static int do_lencheck; +/* XXX: These should be internal to krb5 library, or declared in krb5.h. */ +extern krb5_error_code krb5_write_message (krb5_context, krb5_pointer, + krb5_data *); +extern int krb5_net_read (krb5_context, int , char *, int); +extern int krb5_net_write (krb5_context, int , const char *, int); +/* XXX: And these should be declared in krb.h, or private. */ +#ifdef KRB5_KRB4_COMPAT +extern int +krb_sendauth(long options, int fd, KTEXT ticket, + char *service, char *inst, char *realm, + unsigned KRB4_32 checksum, + MSG_DAT *msg_data, + CREDENTIALS *cred, + Key_schedule schedule, + struct sockaddr_in *laddr, + struct sockaddr_in *faddr, + char *version); +#endif + +int kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, - cred, seqno, server_seqno, laddr, faddr, authopts, anyport, suppress_err) + cred, seqno, server_seqno, laddr, faddr, authconp, authopts, anyport, + suppress_err, protonump) int *sock; char **ahost; u_short rport; @@ -142,15 +167,17 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, int *fd2p; char *service; char *realm; - krb5_creds **cred; + krb5_creds **cred; /* output only */ krb5_int32 *seqno; krb5_int32 *server_seqno; struct sockaddr_in *laddr, *faddr; + krb5_auth_context *authconp; krb5_flags authopts; int anyport; int suppress_err; /* Don't print if authentication fails */ + enum kcmd_proto *protonump; { - int i, s, timo = 1, pid; + int s, pid; #ifdef POSIX_SIGNALS sigset_t oldmask, urgmask; #else @@ -164,7 +191,6 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, int rc; char *host_save; krb5_error_code status; - krb5_error *err_ret; krb5_ap_rep_enc_part *rep_ret; krb5_error *error = 0; int sin_len; @@ -174,6 +200,8 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, krb5_auth_context auth_context = NULL; char *cksumbuf; krb5_data cksumdat; + char *kcmd_version; + enum kcmd_proto protonum = *protonump; if ((cksumbuf = malloc(strlen(cmd)+strlen(remuser)+64)) == 0 ) { fprintf(stderr, "Unable to allocate memory for checksum buffer.\n"); @@ -361,12 +389,35 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR)) goto bad2; - /* call Kerberos library routine to obtain an authenticator, + if (protonum == KCMD_PROTOCOL_COMPAT_HACK) { + krb5_boolean is_des; + status = krb5_c_enctype_compare (bsd_context, ENCTYPE_DES_CBC_CRC, + ret_cred->keyblock.enctype, &is_des); + if (status) + goto bad2; + protonum = is_des ? KCMD_OLD_PROTOCOL : KCMD_NEW_PROTOCOL; + } + + switch (protonum) { + case KCMD_NEW_PROTOCOL: + authopts |= AP_OPTS_USE_SUBKEY; + kcmd_version = "KCMDV0.2"; + break; + case KCMD_OLD_PROTOCOL: + kcmd_version = "KCMDV0.1"; + break; + default: + status = EINVAL; + goto bad2; + } + + /* Call Kerberos library routine to obtain an authenticator, pass it over the socket to the server, and obtain mutual - authentication. */ + authentication. */ status = krb5_sendauth(bsd_context, &auth_context, (krb5_pointer) &s, - "KCMDV0.1", ret_cred->client, ret_cred->server, - authopts, &cksumdat, ret_cred, 0, &error, &rep_ret, NULL); + kcmd_version, ret_cred->client, ret_cred->server, + authopts, &cksumdat, ret_cred, 0, + &error, &rep_ret, NULL); free(cksumbuf); if (status) { if (!suppress_err) @@ -440,10 +491,13 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, sigsetmask(oldmask); #endif /* POSIX_SIGNALS */ *sock = s; + *protonump = protonum; /* pass back credentials if wanted */ if (cred) krb5_copy_creds(bsd_context, ret_cred, cred); krb5_free_creds(bsd_context, ret_cred); + if (authconp) + *authconp = auth_context; return (0); bad2: @@ -464,6 +518,7 @@ kcmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, service, realm, #ifdef KRB5_KRB4_COMPAT +int k4cmd(sock, ahost, rport, locuser, remuser, cmd, fd2p, ticket, service, realm, cred, schedule, msg_data, laddr, faddr, authopts, anyport) int *sock; @@ -701,7 +756,7 @@ reread: #endif /* KRB5_KRB4_COMPAT */ - +int getport(alport) int *alport; { @@ -733,16 +788,25 @@ getport(alport) return -1; } +static int +normal_read (int fd, char *buf, int len, int secondary) +{ + return read (fd, buf, len); +} + void rcmd_stream_init_normal() { - input = read; + input = normal_read; output = twrite; } -void rcmd_stream_init_krb5(in_keyblock, encrypt_flag, lencheck) +void rcmd_stream_init_krb5(in_keyblock, encrypt_flag, lencheck, am_client, + protonum) krb5_keyblock *in_keyblock; int encrypt_flag; int lencheck; + int am_client; + enum kcmd_proto protonum; { krb5_error_code status; size_t blocksize; @@ -760,33 +824,35 @@ void rcmd_stream_init_krb5(in_keyblock, encrypt_flag, lencheck) input = v5_des_read; output = v5_des_write; - if (status = krb5_c_enctype_compare(bsd_context, ENCTYPE_DES_CBC_CRC, - keyblock->enctype, - &similar)) { - /* XXX what do I do? */ - abort(); - } - - if (similar) { - encivec.length = 0; + if (protonum == KCMD_OLD_PROTOCOL) { + use_ivecs = 0; return; } + use_ivecs = 1; + if (status = krb5_c_block_size(bsd_context, keyblock->enctype, &blocksize)) { /* XXX what do I do? */ abort(); } - encivec.length = blocksize; + encivec_i[0].length = encivec_i[1].length = encivec_o[0].length + = encivec_o[1].length = blocksize; - if ((encivec.data = malloc(encivec.length)) == NULL) { + if ((encivec_i[0].data = malloc(encivec_i[0].length * 4)) == NULL) { /* XXX what do I do? */ abort(); } + encivec_i[1].data = encivec_i[0].data + encivec_i[0].length; + encivec_o[0].data = encivec_i[1].data + encivec_i[0].length; + encivec_o[1].data = encivec_o[0].data + encivec_i[0].length; /* is there a better way to initialize this? */ - memset(encivec.data, '\0', blocksize); + memset(encivec_i[0].data, am_client, blocksize); + memset(encivec_o[0].data, 1 - am_client, blocksize); + memset(encivec_i[1].data, 2 | am_client, blocksize); + memset(encivec_o[1].data, 2 | (1 - am_client), blocksize); } #ifdef KRB5_KRB4_COMPAT @@ -808,35 +874,39 @@ void rcmd_stream_init_krb4(session, encrypt_flag, lencheck, justify) } #endif -int rcmd_stream_read(fd, buf, len) +int rcmd_stream_read(fd, buf, len, sec) int fd; register char *buf; int len; + int sec; { - return (*input)(fd, buf, len); + return (*input)(fd, buf, len, sec); } -int rcmd_stream_write(fd, buf, len) +int rcmd_stream_write(fd, buf, len, sec) int fd; register char *buf; int len; + int sec; { - return (*output)(fd, buf, len); + return (*output)(fd, buf, len, sec); } /* Because of rcp lossage, translate fd 0 to 1 when writing. */ -static int twrite(fd, buf, len) +static int twrite(fd, buf, len, secondary) int fd; char *buf; int len; + int secondary; { return write((fd == 0) ? 1 : fd, buf, len); } -static int v5_des_read(fd, buf, len) +static int v5_des_read(fd, buf, len, secondary) int fd; char *buf; int len; + int secondary; { int nreturned = 0; size_t net_len,rd_len; @@ -879,7 +949,8 @@ static int v5_des_read(fd, buf, len) rd_len = (rd_len << 8) | c; if (ret = krb5_c_encrypt_length(bsd_context, keyblock->enctype, - rd_len, &net_len)) { + use_ivecs ? rd_len + 4 : rd_len, + &net_len)) { errno = ret; return(-1); } @@ -902,8 +973,8 @@ static int v5_des_read(fd, buf, len) plain.data = storage; /* decrypt info */ - if (krb5_c_decrypt(bsd_context, keyblock, KCMD_KEYUSAGE, - encivec.length?&encivec:0, + if (ret = krb5_c_decrypt(bsd_context, keyblock, KCMD_KEYUSAGE, + use_ivecs ? encivec_i + secondary : 0, &cipher, &plain)) { /* probably out of sync */ errno = EIO; @@ -911,6 +982,19 @@ static int v5_des_read(fd, buf, len) } store_ptr = storage; nstored = rd_len; + if (use_ivecs) { + int rd_len2; + rd_len2 = storage[0] & 0xff; + rd_len2 <<= 8; rd_len2 |= storage[1] & 0xff; + rd_len2 <<= 8; rd_len2 |= storage[2] & 0xff; + rd_len2 <<= 8; rd_len2 |= storage[3] & 0xff; + if (rd_len2 != rd_len) { + /* cleartext length trashed? */ + errno = EIO; + return -1; + } + store_ptr += 4; + } if (nstored > len) { memcpy(buf, store_ptr, len); nreturned += len; @@ -927,23 +1011,39 @@ static int v5_des_read(fd, buf, len) -static int v5_des_write(fd, buf, len) +static int v5_des_write(fd, buf, len, secondary) int fd; char *buf; int len; + int secondary; { - unsigned char *len_buf = (unsigned char *) des_outpkt; krb5_data plain; krb5_enc_data cipher; - - plain.data = buf; - plain.length = len; + char tmpbuf[2*RCMD_BUFSIZ+8]; + unsigned char *len_buf = (unsigned char *) tmpbuf; + + if (use_ivecs) { + unsigned char *lenbuf2 = (unsigned char *) tmpbuf; + if (len + 4 > sizeof(tmpbuf)) + abort (); + lenbuf2[0] = (len & 0xff000000) >> 24; + lenbuf2[1] = (len & 0xff0000) >> 16; + lenbuf2[2] = (len & 0xff00) >> 8; + lenbuf2[3] = (len & 0xff); + memcpy (tmpbuf + 4, buf, len); + + plain.data = tmpbuf; + plain.length = len + 4; + } else { + plain.data = buf; + plain.length = len; + } cipher.ciphertext.length = sizeof(des_outpkt)-4; cipher.ciphertext.data = desoutbuf.data; if (krb5_c_encrypt(bsd_context, keyblock, KCMD_KEYUSAGE, - encivec.length?&encivec:0, + use_ivecs ? encivec_o + secondary : 0, &plain, &cipher)) { errno = EIO; return(-1); @@ -951,6 +1051,7 @@ static int v5_des_write(fd, buf, len) desoutbuf.length = cipher.ciphertext.length; + len_buf = (unsigned char *) des_outpkt; len_buf[0] = (len & 0xff000000) >> 24; len_buf[1] = (len & 0xff0000) >> 16; len_buf[2] = (len & 0xff00) >> 8; @@ -1032,11 +1133,11 @@ int len; errno = EIO; return(-1); } - (void) pcbc_encrypt(des_inbuf, - storage, + (void) pcbc_encrypt((des_cblock *) des_inbuf, + (des_cblock *) storage, (net_len < 8) ? 8 : net_len, v4_schedule, - v4_session, + &v4_session, DECRYPT); /* * when the cleartext block is < 8 bytes, it is "right-justified" @@ -1092,11 +1193,11 @@ int len; /* this "right-justifies" the data in the buffer */ (void) memcpy(garbage_buf + 8 - len, buf, len); } - (void) pcbc_encrypt((len < 8) ? garbage_buf : buf, - des_outpkt+4, + (void) pcbc_encrypt((des_cblock *) ((len < 8) ? garbage_buf : buf), + (des_cblock *) (des_outpkt+4), (len < 8) ? 8 : len, v4_schedule, - v4_session, + &v4_session, ENCRYPT); /* tell the other end the real amount, but send an 8-byte padded diff --git a/src/appl/bsd/krcp.c b/src/appl/bsd/krcp.c index 9670145..7292e72 100644 --- a/src/appl/bsd/krcp.c +++ b/src/appl/bsd/krcp.c @@ -71,6 +71,8 @@ char copyright[] = #include #include +#include "defines.h" + #define RCP_BUFSIZ 4096 int sock; @@ -131,7 +133,7 @@ void error KRB5_STDARG_P((char *fmt, ...)); void error KRB5_STDARG_P((char *, va_list)); #endif -#define ga() (void) rcmd_stream_write(rem, "", 1) +#define ga() (void) rcmd_stream_write(rem, "", 1, 0) int main(argc, argv) int argc; @@ -153,6 +155,8 @@ int main(argc, argv) krb5_error_code status; int euid; char **orig_argv = save_argv(argc, argv); + krb5_auth_context auth_context; + enum kcmd_proto kcmd_proto = KCMD_PROTOCOL_COMPAT_HACK; status = krb5_init_context(&bsd_context); if (status) { @@ -224,6 +228,14 @@ int main(argc, argv) } strcpy(krb_config, *argv); goto next_arg; + case 'P': + if (!strcmp (*argv, "O")) + kcmd_proto = KCMD_OLD_PROTOCOL; + else if (!strcmp (*argv, "N")) + kcmd_proto = KCMD_NEW_PROTOCOL; + else + usage (); + goto next_arg; #endif /* KERBEROS */ /* The rest of these are not for users. */ case 'd': @@ -376,20 +388,22 @@ int main(argc, argv) suser = pwd->pw_name; else if (!okname(suser)) continue; + (void) sprintf(buf, #if defined(hpux) || defined(__hpux) - (void) sprintf(buf, "remsh %s -l %s -n %s %s '%s%s%s:%s'", + "remsh %s -l %s -n %s %s '%s%s%s:%s'", #else - (void) sprintf(buf, "rsh %s -l %s -n %s %s '%s%s%s:%s'", + "rsh %s -l %s -n %s %s '%s%s%s:%s'", #endif host, suser, cmd, src, tuser ? tuser : "", tuser ? "@" : "", thost, targ); } else + (void) sprintf(buf, #if defined(hpux) || defined(__hpux) - (void) sprintf(buf, "remsh %s -n %s %s '%s%s%s:%s'", + "remsh %s -n %s %s '%s%s%s:%s'", #else - (void) sprintf(buf, "rsh %s -n %s %s '%s%s%s:%s'", + "rsh %s -n %s %s '%s%s%s:%s'", #endif argv[i], cmd, src, tuser ? tuser : "", @@ -397,7 +411,7 @@ int main(argc, argv) thost, targ); (void) susystem(buf); } else { /* local to remote */ -krb5_creds *cred; + krb5_creds *cred; if (rem == -1) { (void) sprintf(buf, "%s -t %s", cmd, targ); @@ -418,10 +432,14 @@ krb5_creds *cred; 0, /* No server seq # */ &local, &foreign, - authopts, + &auth_context, authopts, 0, /* Not any port # */ - 0); + 0, + &kcmd_proto); if (status) { + if (kcmd_proto == KCMD_NEW_PROTOCOL) + /* Don't fall back to less safe methods. */ + exit (1); #ifdef KRB5_KRB4_COMPAT fprintf(stderr, "Trying krb4 rcp...\n"); if (strncmp(buf, "-x rcp", 6) == 0) @@ -442,8 +460,29 @@ krb5_creds *cred; try_normal(orig_argv); #endif } - else - rcmd_stream_init_krb5(&cred->keyblock, encryptflag, 0); + else { + krb5_boolean similar; + krb5_keyblock *key = &cred->keyblock; + + if (status = krb5_c_enctype_compare(bsd_context, + ENCTYPE_DES_CBC_CRC, + cred->keyblock.enctype, + &similar)) + try_normal(orig_argv); /* doesn't return */ + + if (!similar) { + status = krb5_auth_con_getlocalsubkey (bsd_context, + auth_context, + &key); + if ((status || !key) && encryptflag) + try_normal(orig_argv); + } + if (key == 0) + key = &cred->keyblock; + + rcmd_stream_init_krb5(key, encryptflag, 0, 1, + kcmd_proto); + } rem = sock; #else rem = rcmd(&host, port, pwd->pw_name, @@ -521,10 +560,14 @@ krb5_creds *cred; 0, /* No server seq # */ (struct sockaddr_in *) 0, &foreign, - authopts, + &auth_context, authopts, 0, /* Not any port # */ - 0); + 0, + &kcmd_proto); if (status) { + if (kcmd_proto == KCMD_NEW_PROTOCOL) + /* Don't fall back to less safe methods. */ + exit (1); #ifdef KRB5_KRB4_COMPAT fprintf(stderr, "Trying krb4 rcp...\n"); if (strncmp(buf, "-x rcp", 6) == 0) @@ -543,8 +586,27 @@ krb5_creds *cred; #else try_normal(orig_argv); #endif - } else - rcmd_stream_init_krb5(&cred->keyblock, encryptflag, 0); + } else { + krb5_keyblock *key = &cred->keyblock; + + if (kcmd_proto == KCMD_NEW_PROTOCOL) { + status = krb5_auth_con_getlocalsubkey (bsd_context, + auth_context, + &key); + if (status) { + com_err (argv[0], status, + "determining subkey for session"); + exit (1); + } + if (!key) { + com_err (argv[0], 0, + "no subkey negotiated for connection"); + exit (1); + } + } + + rcmd_stream_init_krb5(key, encryptflag, 0, 1, kcmd_proto); + } rem = sock; euid = geteuid(); @@ -741,7 +803,7 @@ void source(argc, argv) */ (void) sprintf(buf, "T%ld 0 %ld 0\n", stb.st_mtime, stb.st_atime); - (void) rcmd_stream_write(rem, buf, strlen(buf)); + (void) rcmd_stream_write(rem, buf, strlen(buf), 0); if (response() < 0) { (void) close(f); continue; @@ -749,7 +811,7 @@ void source(argc, argv) } (void) sprintf(buf, "C%04o %ld %s\n", (int) stb.st_mode&07777, (long ) stb.st_size, last); - (void) rcmd_stream_write(rem, buf, strlen(buf)); + (void) rcmd_stream_write(rem, buf, strlen(buf), 0); if (response() < 0) { (void) close(f); continue; @@ -765,7 +827,7 @@ void source(argc, argv) amt = stb.st_size - i; if (readerr == 0 && read(f, bp->buf, amt) != amt) readerr = errno; - (void) rcmd_stream_write(rem, bp->buf, amt); + (void) rcmd_stream_write(rem, bp->buf, amt, 0); } (void) close(f); if (readerr == 0) @@ -810,14 +872,14 @@ void rsource(name, statp) if (pflag) { (void) sprintf(buf, "T%ld 0 %ld 0\n", statp->st_mtime, statp->st_atime); - (void) rcmd_stream_write(rem, buf, strlen(buf)); + (void) rcmd_stream_write(rem, buf, strlen(buf), 0); if (response() < 0) { closedir(d); return; } } (void) sprintf(buf, "D%04o %d %s\n", statp->st_mode&07777, 0, last); - (void) rcmd_stream_write(rem, buf, strlen(buf)); + (void) rcmd_stream_write(rem, buf, strlen(buf), 0); if (response() < 0) { closedir(d); return; @@ -836,7 +898,7 @@ void rsource(name, statp) source(1, bufv); } closedir(d); - (void) rcmd_stream_write(rem, "E\n", 2); + (void) rcmd_stream_write(rem, "E\n", 2, 0); (void) response(); } @@ -845,7 +907,7 @@ void rsource(name, statp) int response() { char resp, c, rbuf[RCP_BUFSIZ], *cp = rbuf; - if (rcmd_stream_read(rem, &resp, 1) != 1) + if (rcmd_stream_read(rem, &resp, 1, 0) != 1) lostconn(); switch (resp) { @@ -858,7 +920,7 @@ int response() case 1: /* error, followed by err msg */ case 2: /* fatal error, "" */ do { - if (rcmd_stream_read(rem, &c, 1) != 1) + if (rcmd_stream_read(rem, &c, 1, 0) != 1) lostconn(); *cp++ = c; } while (cp < &rbuf[RCP_BUFSIZ] && c != '\n'); @@ -941,12 +1003,12 @@ void sink(argc, argv) targisdir = 1; for (first = 1; ; first = 0) { cp = cmdbuf; - if (rcmd_stream_read(rem, cp, 1) <= 0) + if (rcmd_stream_read(rem, cp, 1, 0) <= 0) return; if (*cp++ == '\n') SCREWUP("unexpected '\\n'"); do { - if (rcmd_stream_read(rem, cp, 1) != 1) + if (rcmd_stream_read(rem, cp, 1, 0) != 1) SCREWUP("lost connection"); } while (*cp++ != '\n'); *cp = 0; @@ -1012,11 +1074,17 @@ void sink(argc, argv) size = size * 10 + (*cp++ - '0'); if (*cp++ != ' ') SCREWUP("size not delimited"); - if (targisdir) + if (targisdir) { + if(strlen(targ) + strlen(cp) + 2 >= sizeof(nambuf)) + SCREWUP("target name too long"); (void) sprintf(nambuf, "%s%s%s", targ, *targ ? "/" : "", cp); - else - (void) strcpy(nambuf, targ); + } else { + if (strlen(targ) + 1 >= sizeof (nambuf)) + SCREWUP("target name too long"); + (void) strncpy(nambuf, targ, sizeof(nambuf) - 1); + } + nambuf[sizeof(nambuf) - 1] = '\0'; exists = stat(nambuf, &stb) == 0; if (cmdbuf[0] == 'D') { if (exists) { @@ -1064,7 +1132,7 @@ void sink(argc, argv) amt = size - i; count += amt; do { - j = rcmd_stream_read(rem, cp, amt); + j = rcmd_stream_read(rem, cp, amt, 0); if (j <= 0) { if (j == 0) error("rcp: dropped connection"); @@ -1159,7 +1227,7 @@ error(fmt, va_alist) va_end(ap); if (iamremote) - (void) rcmd_stream_write(rem, buf, strlen(buf)); + (void) rcmd_stream_write(rem, buf, strlen(buf), 0); else (void) write(2, buf+1, strlen(buf+1)); } @@ -1170,7 +1238,7 @@ void usage() { #ifdef KERBEROS fprintf(stderr, - "Usage: \trcp [-p] [-x] [-k realm] f1 f2; or:\n\trcp [-r] [-p] [-x] [-k realm] f1 ... fn d2\n"); + "Usage: \trcp [-PN | -PO] [-p] [-x] [-k realm] f1 f2; or:\n\trcp [-PN | -PO] [-r] [-p] [-x] [-k realm] f1 ... fn d2\n"); #else fputs("usage: rcp [-p] f1 f2; or: rcp [-rp] f1 ... fn d2\n", stderr); #endif @@ -1315,7 +1383,8 @@ void exit(1); } - rcmd_stream_init_krb5(&new_creds->keyblock, encryptflag, 0); + rcmd_stream_init_krb5(&new_creds->keyblock, encryptflag, 0, 0, + KCMD_OLD_PROTOCOL); /* cleanup */ krb5_free_cred_contents(bsd_context, &creds); diff --git a/src/appl/bsd/krlogin.c b/src/appl/bsd/krlogin.c index da4a889..02a8d30 100644 --- a/src/appl/bsd/krlogin.c +++ b/src/appl/bsd/krlogin.c @@ -138,12 +138,6 @@ char copyright[] = #endif #endif -/* how do we tell apart irix 5 and irix 4? */ -#if defined(__sgi) && defined(__mips) -/* IRIX 5: TIOCGLTC doesn't actually work */ -#undef TIOCGLTC -#endif - #ifndef TIOCPKT_NOSTOP /* These values are over-the-wire protocol, *not* local values */ #define TIOCPKT_NOSTOP 0x10 @@ -177,6 +171,7 @@ int fflag = 0, Fflag = 0; krb5_creds *cred; struct sockaddr_in local, foreign; krb5_context bsd_context; +krb5_auth_context auth_context; #ifdef KRB5_KRB4_COMPAT Key_schedule v4_schedule; @@ -377,7 +372,8 @@ main(argc, argv) #endif #endif int port, debug_port = 0; - + enum kcmd_proto kcmd_proto = KCMD_PROTOCOL_COMPAT_HACK; + memset(&defaultservent, 0, sizeof(struct servent)); if (strrchr(argv[0], '/')) argv[0] = strrchr(argv[0], '/')+1; @@ -502,6 +498,16 @@ main(argc, argv) argv++, argc--; goto another; } + if (argc > 0 && !strcmp(*argv, "-PO")) { + kcmd_proto = KCMD_OLD_PROTOCOL; + argv++, argc--; + goto another; + } + if (argc > 0 && !strcmp(*argv, "-PN")) { + kcmd_proto = KCMD_NEW_PROTOCOL; + argv++, argc--; + goto another; + } #endif /* KERBEROS */ if (host == 0) goto usage; @@ -559,7 +565,8 @@ main(argc, argv) if (tcgetattr(0, &ttyb) == 0) { int ospeed = cfgetospeed (&ttyb); - (void) strcat(term, "/"); + term[sizeof(term) - 1] = '\0'; + (void) strncat(term, "/", sizeof(term) - 1 - strlen(term)); if (ospeed >= 50) /* On some systems, ospeed is the baud rate itself, not a table index. */ @@ -567,15 +574,16 @@ main(argc, argv) else if (ospeed >= sizeof(speeds)/sizeof(char*)) /* Past end of table, but not high enough to look like a real speed. */ - (void) strcat (term, speeds[sizeof(speeds)/sizeof(char*) - 1]); + (void) strncat (term, speeds[sizeof(speeds)/sizeof(char*) - 1], sizeof(term) - 1 - strlen(term)); else { - (void) strcat(term, speeds[ospeed]); + (void) strncat(term, speeds[ospeed], sizeof(term) - 1 - strlen(term)); } + term[sizeof (term) - 1] = '\0'; } #else if (ioctl(0, TIOCGETP, &ttyb) == 0) { - (void) strcat(term, "/"); - (void) strcat(term, speeds[ttyb.sg_ospeed]); + (void) strncat(term, "/", sizeof(term) - 1 - strlen(term)); + (void) strncat(term, speeds[ttyb.sg_ospeed], sizeof(term) - 1 - strlen(term)); } #endif (void) get_window_size(0, &winsize); @@ -631,10 +639,14 @@ main(argc, argv) 0, /* No need for sequence number */ 0, /* No need for server seq # */ &local, &foreign, - authopts, + &auth_context, authopts, 0, /* Not any port # */ - 0); + 0, + &kcmd_proto); if (status) { + if (kcmd_proto == KCMD_NEW_PROTOCOL && encrypt_flag) + /* Don't fall back to something less secure. */ + exit (1); #ifdef KRB5_KRB4_COMPAT fprintf(stderr, "Trying krb4 rlogin...\n"); status = k4cmd(&sock, &host, port, @@ -650,19 +662,20 @@ main(argc, argv) try_normal(orig_argv); #endif } else { - krb5_boolean similar; - - rcmd_stream_init_krb5(&cred->keyblock, encrypt_flag, 1); + krb5_keyblock *key = 0; - if (status = krb5_c_enctype_compare(bsd_context, ENCTYPE_DES_CBC_CRC, - cred->keyblock.enctype, &similar)) - try_normal(orig_argv); /* doesn't return */ - - if (!similar) { + if (kcmd_proto == KCMD_NEW_PROTOCOL) { do_inband = 1; - if (debug_port) - fprintf(stderr, "DEBUG: setting do_inband\n"); + + status = krb5_auth_con_getlocalsubkey (bsd_context, auth_context, + &key); + if ((status || !key) && encrypt_flag) + try_normal(orig_argv); } + if (key == 0) + key = &cred->keyblock; + + rcmd_stream_init_krb5(key, encrypt_flag, 1, 1, kcmd_proto); } rem = sock; @@ -755,6 +768,8 @@ struct tchars { }; #endif + +#ifndef POSIX_TERMIOS #ifdef TIOCGLTC /* * POSIX 1003.1-1988 does not define a 'suspend' character. @@ -768,14 +783,8 @@ struct tchars { struct ltchars defltc; struct ltchars noltc = { -1, -1, -1, -1, -1, -1 }; #endif - -#ifndef POSIX_TERMIOS struct tchars deftc; struct tchars notc = { -1, -1, -1, -1, -1, -1 }; -#ifndef TIOCGLTC -struct ltchars defltc; -struct ltchars noltc = { -1, -1, -1, -1, -1, -1 }; -#endif #endif doit(oldmask) @@ -793,9 +802,6 @@ doit(oldmask) /* there's a POSIX way of doing this, but do we need it general? */ deftty.c_cc[VLNEXT] = 0; #endif -#ifdef TIOCGLTC - (void) ioctl(0, TIOCGLTC, (char *)&defltc); -#endif #else #ifdef USE_TERMIO struct termio sb; @@ -1035,13 +1041,15 @@ int signo; */ writer() { - unsigned char c; - register n; - register bol = 1; /* beginning of line */ - register local = 0; - + int n_read; + char buf[1024]; + int got_esc; /* set to true by read_wrapper if an escape char + was encountered */ + char c; + #ifdef ultrix fd_set waitread; + register n; /* we need to wait until the reader() has set up the terminal, else the read() below may block and not unblock when the terminal @@ -1062,89 +1070,169 @@ writer() } } #endif /* ultrix */ + + /* This loop works as follows. Call read_wrapper to get data until + we would block or until we read a cmdchar at the beginning of a line. + If got_esc is false, we just send everything we got back. If got_esc + is true, we send everything except the cmdchar at the end and look at + the next char. If its a "." we break out of the loop and terminate. + If its ^Z or ^Y we call stop with the value of the char and continue. + If its none of those, we send the cmdchar and then send the char we + just read, unless that char is also the cmdchar (in which case we are + only supposed to send one of them). When this loop ends, so does the + program. + */ + for (;;) { - n = read(0, &c, 1); - if (n <= 0) { - if (n < 0 && errno == EINTR) - continue; + + /* read until we would block or we get a cmdchar */ + n_read = read_wrapper(0,buf,sizeof(buf),&got_esc); + + /* if read returns an error or 0 bytes, just quit */ + if (n_read <= 0) { + break; + } + + if (!got_esc) { + if (rcmd_stream_write(rem, buf, n_read, 0) == 0) { + prf("line gone"); + break; + } + continue; + } + else { + /* This next test is necessary to avoid sending 0 bytes of data + in the event that we got just a cmdchar */ + if (n_read > 1) { + if (rcmd_stream_write(rem, buf, n_read-1, 0) == 0) { + prf("line gone"); break; + } } - /* - * If we're at the beginning of the line - * and recognize a command character, then - * we echo locally. Otherwise, characters - * are echo'd remotely. If the command - * character is doubled, this acts as a - * force and local echo is suppressed. - */ - if (bol) { - bol = 0; - if (c == cmdchar) { - bol = 0; - local = 1; - continue; - } - } else if (local) { - local = 0; + if (read_wrapper(0,&c,1,&got_esc) <= 0) { + break; + } + #ifdef POSIX_TERMIOS - if (c == '.' || c == deftty.c_cc[VEOF]) { + if (c == '.' || c == deftty.c_cc[VEOF]) #else - if (c == '.' || c == deftc.t_eofc) { + if (c == '.' || c == deftc.t_eofc) #endif - if (confirm_death()) { - echo(c); - break; - } - } -#ifdef TIOCGLTC - if ((c == defltc.t_suspc || c == defltc.t_dsuspc) - && !no_local_escape) { - bol = 1; + { + if (confirm_death()) { echo(c); - stop(c); - continue; + break; + } } -#else + #ifdef POSIX_TERMIOS - if ( ( - (c == deftty.c_cc[VSUSP]) + if ( ( + (c == deftty.c_cc[VSUSP]) #ifdef VDSUSP - || (c == deftty.c_cc[VDSUSP]) -#endif - ) - && !no_local_escape) { - bol = 1; - echo(c); - stop(c); - continue; - } + || (c == deftty.c_cc[VDSUSP]) #endif + ) + && !no_local_escape) { + echo(c); + stop(c); + continue; + } +#else /*POSIX_TERMIOS*/ +#ifdef TIOCGLTC + if ((c == defltc.t_suspc || c == defltc.t_dsuspc) + && !no_local_escape) { + echo(c); + stop(c); + continue; + } +#endif /*TIOCGLTC*/ #endif - if (c != cmdchar) - (void) rcmd_stream_write(rem, &cmdchar, 1); + + if (c != cmdchar) { + rcmd_stream_write(rem, &cmdchar, 1, 0); } - if (rcmd_stream_write(rem, &c, 1) == 0) { - prf("line gone"); - break; + + if (rcmd_stream_write(rem,&c,1,0) == 0) { + prf("line gone"); + break; } -#ifdef POSIX_TERMIOS - bol = (c == deftty.c_cc[VKILL] || - c == deftty.c_cc[VINTR] || - c == '\r' || c == '\n'); -#ifdef TIOCGLTC - if (!bol) - bol = (c == defltc.t_suspc); -#endif -#else /* !POSIX_TERMIOS */ - bol = c == defkill || c == deftc.t_eofc || - c == deftc.t_intrc || c == defltc.t_suspc || - c == '\r' || c == '\n'; -#endif + } } } +/* This function reads up to size bytes from file desciptor fd into buf. + It will copy as much data as it can without blocking, but will never + copy more than size bytes. In addition, if it encounters a cmdchar + at the beginning of a line, it will copy everything up to and including + the cmdchar, but nothing after that. In this instance *esc_char is set + to true and any remaining data is buffered and copied on a subsequent + call. Otherwise, *esc_char will be set to false and the minimum of size, + 1024, and the number of bytes that can be read without blocking will + be copied. In all cases, a non-negative return value indicates the number + of bytes actually copied and a return value of -1 indicates that there + was a read error (other than EINTR) and errno is set appropriately. +*/ + +int read_wrapper(fd,buf,size,got_esc) + int fd; + char *buf; + int size; + int *got_esc; +{ + static char tbuf[1024]; + static char *data_start = tbuf; + static char *data_end = tbuf; + static int bol = 1; + int return_length = 0; + char c; + + /* if we have no data buffered, get more */ + if (data_start == data_end) { + int n_read; + while ((n_read = read(fd, tbuf, sizeof(tbuf))) <= 0) { + if (n_read < 0 && errno == EINTR) + continue; + return n_read; + } + data_start = tbuf; + data_end = tbuf+n_read; + } + + *got_esc = 0; + /* We stop when we've fully checked the buffer or have checked size + bytes. We break out and set *got_esc if we encounter a cmdchar + at the beginning of a line. + */ + + while (data_start+return_length < data_end && return_length < size) { + + c = *(data_start+return_length); + return_length++; + + if (bol == 1 && c == cmdchar) { + bol = 0; + *got_esc = 1; + break; + } + +#ifdef POSIX_TERMIOS + bol = (c == deftty.c_cc[VKILL] || + c == deftty.c_cc[VINTR] || + c == '\r' || c == '\n'); + +#else /* !POSIX_TERMIOS */ + bol = c == defkill || c == deftc.t_eofc || + c == deftc.t_intrc || c == defltc.t_suspc || + c == '\r' || c == '\n'; +#endif + } + + memcpy(buf, data_start, return_length); + data_start = data_start + return_length; + return return_length; +} echo(c) register char c; @@ -1187,14 +1275,13 @@ stop(cmdc) (void) signal(SIGCHLD, SIG_IGN); #endif -#ifdef TIOCGLTC - (void) kill(cmdc == defltc.t_suspc ? 0 : getpid(), SIGTSTP); -#else #ifdef POSIX_TERMIOS (void) kill(cmdc == deftty.c_cc[VSUSP] ? 0 : getpid(), SIGTSTP); +#else +#ifdef TIOCGLTC + (void) kill(cmdc == defltc.t_suspc ? 0 : getpid(), SIGTSTP); #endif #endif - #ifdef POSIX_SIGNALS sa.sa_handler = catchild; (void) sigaction(SIGCHLD, &sa, (struct sigaction *)0); @@ -1239,7 +1326,7 @@ sendwindow() wp->ws_col = htons(winsize.ws_col); wp->ws_xpixel = htons(winsize.ws_xpixel); wp->ws_ypixel = htons(winsize.ws_ypixel); - (void) rcmd_stream_write(rem, obuf, sizeof(obuf)); + (void) rcmd_stream_write(rem, obuf, sizeof(obuf), 0); } @@ -1458,7 +1545,7 @@ fd_set readset, excset, writeset; bufp += n; } if (FD_ISSET(rem, &readset)) { - rcvcnt = rcmd_stream_read(rem, rcvbuf, sizeof (rcvbuf)); + rcvcnt = rcmd_stream_read(rem, rcvbuf, sizeof (rcvbuf), 0); if (rcvcnt == 0) return (0); if (rcvcnt < 0) @@ -1514,11 +1601,6 @@ mode(f) switch(f) { case 0: -#ifdef TIOCGLTC -#if !defined(sun) - (void) ioctl(0, TIOCSLTC, (char *)&defltc); -#endif -#endif (void) tcsetattr(0, TCSADRAIN, &deftty); break; case 1: @@ -1555,14 +1637,6 @@ mode(f) newtty.c_cc[VMIN] = 1; newtty.c_cc[VTIME] = 0; (void) tcsetattr(0, TCSADRAIN, &newtty); -#ifdef TIOCGLTC - /* Do this after the tcsetattr() in case this version - * of termio supports the VSUSP or VDSUSP characters */ -#if !defined(sun) - /* this forces ICRNL under Solaris... */ - (void) ioctl(0, TIOCSLTC, (char *)&noltc); -#endif -#endif break; default: return; diff --git a/src/appl/bsd/krlogind.c b/src/appl/bsd/krlogind.c index e37b84c..9254449 100644 --- a/src/appl/bsd/krlogind.c +++ b/src/appl/bsd/krlogind.c @@ -250,6 +250,7 @@ AUTH_DAT *v4_kdata; Key_schedule v4_schedule; #include "com_err.h" +#include "defines.h" #define SECURE_MESSAGE "This rlogin session is using DES encryption for all data transmissions.\r\n" @@ -815,7 +816,7 @@ void doit(f, fromp) stripdomain, always_ip, &rhost_sane); if (retval) - fatalperror(2, "failed make_sane_hostname"); + fatalperror(f, "failed make_sane_hostname"); if (passwd_req) execl(login_program, "login", "-p", "-h", rhost_sane, lusername, 0); @@ -825,8 +826,9 @@ void doit(f, fromp) #else /* USE_LOGIN_F */ execl(login_program, "login", "-r", rhost_sane, 0); #endif /* USE_LOGIN_F */ - - fatalperror(2, login_program); + syslog(LOG_ERR, "failed exec of %s: %s", + login_program, error_message(errno)); + fatalperror(f, login_program); /*NOTREACHED*/ } /* if (pid == 0) */ @@ -850,7 +852,7 @@ void doit(f, fromp) #if defined(KERBEROS) if (do_encrypt) { - if (rcmd_stream_write(f, SECURE_MESSAGE, sizeof(SECURE_MESSAGE)) < 0){ + if (rcmd_stream_write(f, SECURE_MESSAGE, sizeof(SECURE_MESSAGE), 0) < 0){ sprintf(buferror, "Cannot encrypt-write network."); fatal(p,buferror); } @@ -918,11 +920,11 @@ int sendoob(fd, byte) message[3] = 'o'; message[4] = *byte; - cc = rcmd_stream_write(fd, message, sizeof(message)); + cc = rcmd_stream_write(fd, message, sizeof(message), 0); while (cc < 0 && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { /* also shouldn't happen */ sleep(5); - cc = rcmd_stream_write(fd, message, sizeof(message)); + cc = rcmd_stream_write(fd, message, sizeof(message), 0); } } else { send(fd, byte, 1, MSG_OOB); @@ -984,7 +986,8 @@ void protocol(f, p) int on = 1; #endif -#if defined(TIOCPKT) && !defined(__svr4__) || defined(solaris20) +#if defined(TIOCPKT) && !(defined(__svr4__) || defined(HAVE_STREAMS)) \ + || defined(solaris20) /* if system has TIOCPKT, try to turn it on. Some drivers * may not support it. Save flag for later. */ @@ -1033,7 +1036,7 @@ void protocol(f, p) } #define pkcontrol(c) ((c)&(TIOCPKT_FLUSHWRITE|TIOCPKT_NOSTOP|TIOCPKT_DOSTOP)) if (FD_ISSET(f, &ibits)) { - fcc = rcmd_stream_read(f, fibuf, sizeof (fibuf)); + fcc = rcmd_stream_read(f, fibuf, sizeof (fibuf), 0); if (fcc < 0 && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { fcc = 0; } else { @@ -1121,7 +1124,7 @@ void protocol(f, p) } if (FD_ISSET(f, &obits) && pcc > 0) { - cc = rcmd_stream_write(f, pbp, pcc); + cc = rcmd_stream_write(f, pbp, pcc, 0); if (cc < 0 && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { /* also shouldn't happen */ sleep(5); @@ -1160,7 +1163,7 @@ void fatal(f, msg) buf[0] = '\01'; /* error indicator */ (void) sprintf(buf + 1, "%s: %s.\r\n",progname, msg); if ((f == netf) && (pid > 0)) - (void) rcmd_stream_write(f, buf, strlen(buf)); + (void) rcmd_stream_write(f, buf, strlen(buf), 0); else (void) write(f, buf, strlen(buf)); syslog(LOG_ERR,"%s\n",msg); @@ -1377,9 +1380,11 @@ recvauth(valid_checksum) int len; krb5_data inbuf; char v4_instance[INST_SZ]; /* V4 Instance */ - char v4_version[9]; + krb5_data version; krb5_authenticator *authenticator; krb5_rcache rcache; + enum kcmd_proto kcmd_proto; + krb5_keyblock *key; *valid_checksum = 0; len = sizeof(laddr); @@ -1423,8 +1428,8 @@ recvauth(valid_checksum) if (status) return status; } - if ((status = krb5_compat_recvauth(bsd_context, &auth_context, &netf, - "KCMDV0.1", + if ((status = krb5_compat_recvauth_version(bsd_context, &auth_context, + &netf, NULL, /* Specify daemon principal */ 0, /* no flags */ keytab, /* normally NULL to use v5srvtab */ @@ -1438,8 +1443,8 @@ recvauth(valid_checksum) &ticket, /* return ticket */ &auth_sys, /* which authentication system*/ - &v4_kdata, v4_schedule, v4_version))) { - + &v4_kdata, v4_schedule, + &version))) { if (auth_sys == KRB5_RECVAUTH_V5) { /* * clean up before exiting @@ -1453,7 +1458,25 @@ recvauth(valid_checksum) getstr(netf, lusername, sizeof (lusername), "locuser"); getstr(netf, term, sizeof(term), "Terminal type"); - if ((auth_sys == KRB5_RECVAUTH_V5) && !checksum_ignored) { + + kcmd_proto = KCMD_UNKNOWN_PROTOCOL; + if (auth_sys == KRB5_RECVAUTH_V5) { + if (version.length != 9) { + fatal (netf, "bad application version length"); + } + if (!memcmp (version.data, "KCMDV0.1", 9)) + kcmd_proto = KCMD_OLD_PROTOCOL; + else if (!memcmp (version.data, "KCMDV0.2", 9)) + kcmd_proto = KCMD_NEW_PROTOCOL; + } +#ifdef KRB5_KRB4_COMPAT + if (auth_sys == KRB5_RECVAUTH_V4) + kcmd_proto = KCMD_V4_PROTOCOL; +#endif + + if ((auth_sys == KRB5_RECVAUTH_V5) + && !(checksum_ignored + && kcmd_proto == KCMD_OLD_PROTOCOL)) { if ((status = krb5_auth_con_getauthenticator(bsd_context, auth_context, &authenticator))) @@ -1500,7 +1523,8 @@ recvauth(valid_checksum) * Assume it to be the same as the first component of the * principal's name. */ - strcpy(rusername, v4_kdata->pname); + strncpy(rusername, v4_kdata->pname, sizeof(rusername) - 1); + rusername[sizeof(rusername) - 1] = '\0'; status = krb5_425_conv_principal(bsd_context, v4_kdata->pname, v4_kdata->pinst, v4_kdata->prealm, @@ -1519,22 +1543,20 @@ recvauth(valid_checksum) &client))) return status; - rcmd_stream_init_krb5(ticket->enc_part2->session, do_encrypt, 1); - - { - krb5_boolean similar; - - if (status = krb5_c_enctype_compare(bsd_context, ENCTYPE_DES_CBC_CRC, - ticket->enc_part2->session->enctype, - &similar)) - return(status); + key = 0; + status = krb5_auth_con_getremotesubkey (bsd_context, auth_context, &key); + if (status) + fatal (netf, "Server can't get session subkey"); + if (!key && do_encrypt && kcmd_proto == KCMD_NEW_PROTOCOL) + fatal (netf, "No session subkey sent"); + if (key && kcmd_proto == KCMD_OLD_PROTOCOL) + fatal (netf, "Session subkey not permitted under old kcmd protocol"); + if (key == 0) + key = ticket->enc_part2->session; - if (!similar) { - do_inband = 1; - syslog(LOG_DEBUG, "setting do_inband"); - } - } + rcmd_stream_init_krb5 (key, do_encrypt, 1, 0, kcmd_proto); + do_inband = (kcmd_proto == KCMD_NEW_PROTOCOL); getstr(netf, rusername, sizeof(rusername), "remuser"); diff --git a/src/appl/bsd/krsh.c b/src/appl/bsd/krsh.c index 9d602b2..c1741d8 100644 --- a/src/appl/bsd/krsh.c +++ b/src/appl/bsd/krsh.c @@ -93,8 +93,6 @@ krb5_sigtype sendsig(); #define UCB_RSH "/usr/ucb/rsh" #endif - - krb5_context bsd_context; krb5_creds *cred; @@ -137,7 +135,7 @@ main(argc, argv0) struct servent *sp; struct servent defaultservent; struct sockaddr_in local, foreign; - int suppress; + int suppress = 0; #ifdef POSIX_SIGNALS sigset_t omask, igmask; @@ -148,6 +146,7 @@ main(argc, argv0) #ifdef KERBEROS krb5_flags authopts; krb5_error_code status; + krb5_auth_context auth_context; int fflag = 0, Fflag = 0; #ifdef KRB5_KRB4_COMPAT KTEXT_ST v4_ticket; @@ -155,6 +154,7 @@ main(argc, argv0) #endif #endif /* KERBEROS */ int debug_port = 0; + enum kcmd_proto kcmd_proto = KCMD_PROTOCOL_COMPAT_HACK; memset(&defaultservent, 0, sizeof(struct servent)); if (strrchr(argv[0], '/')) @@ -239,6 +239,16 @@ main(argc, argv0) argv++, argc--; goto another; } + if (argc > 0 && !strcmp(*argv, "-PO")) { + argv++, argc--; + kcmd_proto = KCMD_OLD_PROTOCOL; + goto another; + } + if (argc > 0 && !strcmp(*argv, "-PN")) { + argv++, argc--; + kcmd_proto = KCMD_NEW_PROTOCOL; + goto another; + } #endif /* KERBEROS */ /* * Ignore the -L, -w, -e and -8 flags to allow aliases with rlogin @@ -367,10 +377,15 @@ main(argc, argv0) 0, /* No need for sequence number */ 0, /* No need for server seq # */ &local, &foreign, - authopts, + &auth_context, authopts, 1, /* Always set anyport, there is no need not to. --proven */ - suppress); + suppress, + &kcmd_proto); if (status) { + /* If new protocol requested, don't fall back to less secure + ones. */ + if (kcmd_proto == KCMD_NEW_PROTOCOL) + exit (1); #ifdef KRB5_KRB4_COMPAT /* No encrypted Kerberos 4 rsh. */ if (encrypt_flag) @@ -391,8 +406,24 @@ main(argc, argv0) #else try_normal(argv0); #endif - } else - rcmd_stream_init_krb5(&cred->keyblock, encrypt_flag, 0); + } else { + krb5_keyblock *key = &cred->keyblock; + + if (kcmd_proto == KCMD_NEW_PROTOCOL) { + status = krb5_auth_con_getlocalsubkey (bsd_context, auth_context, + &key); + if (status) { + com_err (argv[0], status, "determining subkey for session"); + exit (1); + } + if (!key) { + com_err (argv[0], 0, "no subkey negotiated for connection"); + exit (1); + } + } + + rcmd_stream_init_krb5(key, encrypt_flag, 0, 1, kcmd_proto); + } #ifdef HAVE_ISATTY if(encrypt_flag&&isatty(2)) { @@ -489,7 +520,7 @@ main(argc, argv0) } if (FD_ISSET(rem, &rembits) == 0) goto rewrite; - wc = rcmd_stream_write(rem, bp, cc); + wc = rcmd_stream_write(rem, bp, cc, 0); if (wc < 0) { if ((errno == EWOULDBLOCK) || (errno == EAGAIN)) goto rewrite; @@ -524,7 +555,7 @@ main(argc, argv0) } if (FD_ISSET(rfd2, &ready)) { errno = 0; - cc = rcmd_stream_read(rfd2, buf, sizeof buf); + cc = rcmd_stream_read(rfd2, buf, sizeof buf, 1); if (cc <= 0) { if ((errno != EWOULDBLOCK) && (errno != EAGAIN)) FD_CLR(rfd2, &readfrom); @@ -533,7 +564,7 @@ main(argc, argv0) } if (FD_ISSET(rem, &ready)) { errno = 0; - cc = rcmd_stream_read(rem, buf, sizeof buf); + cc = rcmd_stream_read(rem, buf, sizeof buf, 0); if (cc <= 0) { if ((errno != EWOULDBLOCK) && (errno != EAGAIN)) FD_CLR(rem, &readfrom); @@ -546,9 +577,9 @@ main(argc, argv0) exit(0); usage: fprintf(stderr, - "usage: \trsh host [ -l login ] [ -n ] [ -x ] [ -f / -F] command\n"); + "usage: \trsh host [ -PN / -PO ] [ -l login ] [ -n ] [ -x ] [ -f / -F] command\n"); fprintf(stderr, - "OR \trsh [ -l login ] [-n ] [ -x ] [ -f / -F ] host command\n"); + "OR \trsh [ -PN / -PO ] [ -l login ] [-n ] [ -x ] [ -f / -F ] host command\n"); exit(1); } @@ -557,7 +588,7 @@ main(argc, argv0) krb5_sigtype sendsig(signo) char signo; { - (void) rcmd_stream_write(rfd2, &signo, 1); + (void) rcmd_stream_write(rfd2, &signo, 1, 1); } diff --git a/src/appl/bsd/krshd.c b/src/appl/bsd/krshd.c index 3844087..7bd8dbf 100644 --- a/src/appl/bsd/krshd.c +++ b/src/appl/bsd/krshd.c @@ -48,8 +48,8 @@ char copyright[] = * or by the name of the daemon. If command-line arguments are present, they * take priority. The options are: * -k means trust krb4 or krb5 -* -5 means trust krb5 -* -4 means trust krb4 (using .klogin) + * -5 means trust krb5 + * -4 means trust krb4 (using .klogin) * */ @@ -73,9 +73,7 @@ char copyright[] = #define SERVE_NON_KRB #define LOG_REMOTE_REALM #define LOG_CMD -#include "defines.h" - #ifdef HAVE_UNISTD_H #include #endif @@ -162,6 +160,18 @@ char copyright[] = Key_schedule v4_schedule; #endif +#ifdef HAVE_PATHS_H +#include +#endif + +#if defined(_PATH_NOLOGIN) +#define NOLOGIN _PATH_NOLOGIN +#else +#define NOLOGIN "/etc/nologin" +#endif + +#include "defines.h" + #if HAVE_ARPA_NAMESER_H #include #endif @@ -1119,7 +1129,7 @@ void doit(f, fromp) goto signout_please; } - if (pwd->pw_uid && !access("/etc/nologin", F_OK)) { + if (pwd->pw_uid && !access(NOLOGIN, F_OK)) { error("Logins currently disabled.\n"); goto signout_please; } @@ -1245,7 +1255,7 @@ if(port) shutdown(s, 1+1); FD_CLR(pv[0], &readfrom); } else { - (void) rcmd_stream_write(s, buf, cc); + (void) rcmd_stream_write(s, buf, cc, 1); } } if (FD_ISSET(pw[0], &ready)) { @@ -1256,12 +1266,12 @@ if(port) shutdown(f, 1+1); FD_CLR(pw[0], &readfrom); } else { - (void) rcmd_stream_write(f, buf, cc); + (void) rcmd_stream_write(f, buf, cc, 0); } } if (port&&FD_ISSET(s, &ready)) { /* read from the alternate channel, signal the child */ - if (rcmd_stream_read(s, &sig, 1) <= 0) { + if (rcmd_stream_read(s, &sig, 1, 1) <= 0) { FD_CLR(s, &readfrom); } else { #ifdef POSIX_SIGNALS @@ -1277,7 +1287,7 @@ if(port) if (FD_ISSET(f, &ready)) { /* read from the net, write to child stdin */ errno = 0; - cc = rcmd_stream_read(f, buf, sizeof(buf)); + cc = rcmd_stream_read(f, buf, sizeof(buf), 0); if (cc <= 0) { (void) close(px[1]); FD_CLR(f, &readfrom); @@ -1468,15 +1478,16 @@ if(port) strcpy((char *) cmdbuf + offst, kprogdir); cp = copy + 3 + offst; + cmdbuf[sizeof(cmdbuf) - 1] = '\0'; if (auth_sys == KRB5_RECVAUTH_V4) { - strcat(cmdbuf, "/v4rcp"); + strncat(cmdbuf, "/v4rcp", sizeof(cmdbuf) - 1 - strlen(cmdbuf)); } else { - strcat(cmdbuf, "/rcp"); + strncat(cmdbuf, "/rcp", sizeof(cmdbuf) - 1 - strlen(cmdbuf)); } if (stat((char *)cmdbuf + offst, &s) >= 0) - strcat(cmdbuf, cp); + strncat(cmdbuf, cp, sizeof(cmdbuf) - 1 - strlen(cmdbuf)); else - strcpy(cmdbuf, copy); + strncpy(cmdbuf, copy, sizeof(cmdbuf) - 1 - strlen(cmdbuf)); free(copy); } #endif @@ -1775,7 +1786,6 @@ recvauth(netf, peersin, valid_checksum) krb5_data inbuf; #ifdef KRB5_KRB4_COMPAT char v4_instance[INST_SZ]; /* V4 Instance */ - char v4_version[9]; #endif krb5_authenticator *authenticator; krb5_ticket *ticket; @@ -1783,6 +1793,8 @@ recvauth(netf, peersin, valid_checksum) struct passwd *pwd; uid_t uid; gid_t gid; + enum kcmd_proto kcmd_proto; + krb5_data version; *valid_checksum = 0; len = sizeof(laddr); @@ -1828,8 +1840,7 @@ recvauth(netf, peersin, valid_checksum) } #ifdef KRB5_KRB4_COMPAT - status = krb5_compat_recvauth(bsd_context, &auth_context, &netf, - "KCMDV0.1", + status = krb5_compat_recvauth_version(bsd_context, &auth_context, &netf, NULL, /* Specify daemon principal */ 0, /* no flags */ keytab, /* normally NULL to use v5srvtab */ @@ -1842,14 +1853,14 @@ recvauth(netf, peersin, valid_checksum) &ticket, /* return ticket */ &auth_sys, /* which authentication system*/ - &v4_kdata, 0, v4_version); + &v4_kdata, 0, &version); #else - status = krb5_recvauth(bsd_context, &auth_context, &netf, - "KCMDV0.1", - NULL, /* daemon principal */ - 0, /* no flags */ - keytab, /* normally NULL to use v5srvtab */ - &ticket); /* return ticket */ + status = krb5_recvauth_version(bsd_context, &auth_context, &netf, + NULL, /* daemon principal */ + 0, /* no flags */ + keytab, /* normally NULL to use v5srvtab */ + &ticket, /* return ticket */ + &version); /* application version string */ auth_sys = KRB5_RECVAUTH_V5; #endif @@ -1891,6 +1902,14 @@ recvauth(netf, peersin, valid_checksum) /* Must be V5 */ + kcmd_proto = KCMD_UNKNOWN_PROTOCOL; + if (version.length != 9) + fatal (netf, "bad application version length"); + if (!memcmp (version.data, "KCMDV0.1", 9)) + kcmd_proto = KCMD_OLD_PROTOCOL; + if (!memcmp (version.data, "KCMDV0.2", 9)) + kcmd_proto = KCMD_NEW_PROTOCOL; + getstr(netf, remuser, sizeof(locuser), "remuser"); if ((status = krb5_unparse_name(bsd_context, ticket->enc_part2->client, @@ -1939,7 +1958,21 @@ recvauth(netf, peersin, valid_checksum) if (!strncmp(cmdbuf, "-x ", 3)) do_encrypt = 1; - rcmd_stream_init_krb5(ticket->enc_part2->session, do_encrypt, 0); + + { + krb5_keyblock *key; + status = krb5_auth_con_getremotesubkey (bsd_context, auth_context, + &key); + if (status) + fatal (netf, "Server can't get session subkey"); + if (!key && do_encrypt && kcmd_proto == KCMD_NEW_PROTOCOL) + fatal (netf, "No session subkey sent"); + if (key && kcmd_proto == KCMD_OLD_PROTOCOL) + fatal (netf, "Session subkey not allowed in old kcmd protocol"); + if (key == 0) + key = ticket->enc_part2->session; + rcmd_stream_init_krb5 (key, do_encrypt, 0, 0, kcmd_proto); + } /* Null out the "session" because kcmd.c references the session * key here, and we do not want krb5_free_ticket() to destroy it. */ @@ -1990,7 +2023,7 @@ void fatal(f, msg) buf[0] = '\01'; /* error indicator */ (void) sprintf(buf + 1, "%s: %s.\r\n",progname, msg); if ((f == netf) && (pid > 0)) - (void) rcmd_stream_write(f, buf, strlen(buf)); + (void) rcmd_stream_write(f, buf, strlen(buf), 0); else (void) write(f, buf, strlen(buf)); syslog(LOG_ERR,"%s\n",msg); diff --git a/src/appl/bsd/login.M b/src/appl/bsd/login.M index f48fd0c..bcbddab 100644 --- a/src/appl/bsd/login.M +++ b/src/appl/bsd/login.M @@ -74,7 +74,7 @@ Attempt to run aklog. Default value true. .IP aklog_path Where to find it [not yet implemented.] Default value .I $(prefix)/bin/aklog. -.IP accept_passwd = 0 +.IP accept_passwd Don't accept plaintext passwords [not yet implemented]. Default value false. .SH DIAGNOSTICS diff --git a/src/appl/bsd/login.c b/src/appl/bsd/login.c index 40af3ce..13e8181 100644 --- a/src/appl/bsd/login.c +++ b/src/appl/bsd/login.c @@ -517,6 +517,7 @@ void k_init (ttyn) if (!getenv(KRB5_ENV_CCNAME)) { sprintf(ccfile, "FILE:/tmp/krb5cc_p%d", getpid()); setenv(KRB5_ENV_CCNAME, ccfile, 1); + krb5_cc_set_default_name(kcontext, ccfile); unlink(ccfile+strlen("FILE:")); } else { /* note it correctly */ @@ -619,9 +620,10 @@ int have_v5_tickets (me) #endif /* KRB5_GET_TICKETS */ #ifdef KRB4_CONVERT -try_convert524 (kcontext, me) - krb5_context kcontext; - krb5_principal me; +try_convert524(kcontext, me, use_ccache) + krb5_context kcontext; + krb5_principal me; + int use_ccache; { krb5_principal kpcserver; krb5_error_code kpccode; @@ -632,38 +634,45 @@ try_convert524 (kcontext, me) /* or do this directly with krb524_convert_creds_kdc */ krb524_init_ets(kcontext); - /* cc->ccache, already set up */ - /* client->me, already set up */ - if ((kpccode = krb5_build_principal(kcontext, - &kpcserver, - krb5_princ_realm(kcontext, me)->length, - krb5_princ_realm(kcontext, me)->data, - "krbtgt", - krb5_princ_realm(kcontext, me)->data, - NULL))) { - com_err("login/v4", kpccode, - "while creating service principal name"); - return 0; - } - memset((char *) &increds, 0, sizeof(increds)); - increds.client = me; - increds.server = kpcserver; - increds.times.endtime = 0; - increds.keyblock.enctype = ENCTYPE_DES_CBC_CRC; - if ((kpccode = krb5_get_credentials(kcontext, 0, - ccache, - &increds, - &v5creds))) { - com_err("login/v4", kpccode, - "getting V5 credentials"); - return 0; - } - if ((kpccode = krb524_convert_creds_kdc(kcontext, - v5creds, - &v4creds))) { - com_err("login/v4", kpccode, - "converting to V4 credentials"); + /* If we have forwarded v5 tickets, retrieve the credentials from + * the cache; otherwise, the v5 credentials are in my_creds. + */ + if (use_ccache) { + /* cc->ccache, already set up */ + /* client->me, already set up */ + kpccode = krb5_build_principal(kcontext, &kpcserver, + krb5_princ_realm(kcontext, me)->length, + krb5_princ_realm(kcontext, me)->data, + "krbtgt", + krb5_princ_realm(kcontext, me)->data, + NULL); + if (kpccode) { + com_err("login/v4", kpccode, + "while creating service principal name"); + return 0; + } + + memset((char *) &increds, 0, sizeof(increds)); + increds.client = me; + increds.server = kpcserver; + increds.times.endtime = 0; + increds.keyblock.enctype = ENCTYPE_DES_CBC_CRC; + kpccode = krb5_get_credentials(kcontext, 0, ccache, + &increds, &v5creds); + krb5_free_principal(kcontext, kpcserver); + increds.server = NULL; + if (kpccode) { + com_err("login/v4", kpccode, "getting V5 credentials"); + return 0; + } + + kpccode = krb524_convert_creds_kdc(kcontext, v5creds, &v4creds); + krb5_free_creds(kcontext, v5creds); + } else + kpccode = krb524_convert_creds_kdc(kcontext, &my_creds, &v4creds); + if (kpccode) { + com_err("login/v4", kpccode, "converting to V4 credentials"); return 0; } /* this is stolen from the v4 kinit */ @@ -913,8 +922,9 @@ afs_login () struct stat st; /* construct the name */ /* get this from profile later */ - strcpy (aklog_path, KPROGDIR); - strcat (aklog_path, "/aklog"); + aklog_path[sizeof(aklog_path) - 1] = '\0'; + strncpy (aklog_path, KPROGDIR, sizeof(aklog_path) - 1); + strncat (aklog_path, "/aklog", sizeof(aklog_path) - 1 - strlen(aklog_path)); /* only run it if we can find it */ if (stat (aklog_path, &st) == 0) { system(aklog_path); @@ -1145,8 +1155,13 @@ int main(argc, argv) } argc -= optind; argv += optind; - if (*argv) - username = *argv; + /* Throw away too-long names, they can't be usernames. */ + if (*argv) { + if (strlen (*argv) <= UT_NAMESIZE) + username = *argv; + else + fprintf (stderr, "login name '%s' too long\n", *argv); + } #if !defined(POSIX_TERMIOS) && defined(TIOCLSET) ioctlval = 0; @@ -1448,7 +1463,7 @@ int main(argc, argv) #if defined(KRB5_GET_TICKETS) && defined(KRB4_CONVERT) if (login_krb4_convert && !got_v4_tickets) { if (got_v5_tickets||forwarded_v5_tickets) - try_convert524 (kcontext, me); + try_convert524(kcontext, me, forwarded_v5_tickets); } #endif @@ -1746,8 +1761,10 @@ int main(argc, argv) #ifdef KRB5_GET_TICKETS /* ccfile[0] is only set if we got tickets above */ - if (login_krb5_get_tickets && ccfile[0]) + if (login_krb5_get_tickets && ccfile[0]) { (void) setenv(KRB5_ENV_CCNAME, ccfile, 1); + krb5_cc_set_default_name(kcontext, ccfile); + } #endif /* KRB5_GET_TICKETS */ if (tty[sizeof("tty")-1] == 'd') @@ -2086,6 +2103,7 @@ void dolastlog(quiet, tty) { #if defined(HAVE_LASTLOG_H) || (defined(BSD) && (BSD >= 199103)) struct lastlog ll; + time_t lltime; int fd; if ((fd = open(LASTLOG, O_RDWR, 0)) >= 0) { @@ -2094,7 +2112,9 @@ void dolastlog(quiet, tty) if ((read(fd, (char *)&ll, sizeof(ll)) == sizeof(ll)) && (ll.ll_time != 0)) { - printf("Last login: %.*s ", 24-5, (char *)ctime(&ll.ll_time)); + /* .ll_time may not be a time_t. */ + lltime = ll.ll_time; + printf("Last login: %.*s ", 24-5, (char *)ctime(&lltime)); if (*ll.ll_host != '\0') printf("from %.*s\n", sizeof(ll.ll_host), ll.ll_host); @@ -2103,7 +2123,8 @@ void dolastlog(quiet, tty) } (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), SEEK_SET); } - (void) time(&ll.ll_time); + (void) time(&lltime); + ll.ll_time = lltime; (void) strncpy(ll.ll_line, tty, sizeof(ll.ll_line)); ll.ll_line[sizeof(ll.ll_line) - 1] = '\0'; diff --git a/src/appl/bsd/loginpaths.h b/src/appl/bsd/loginpaths.h index 41683ee..e2f759c 100644 --- a/src/appl/bsd/loginpaths.h +++ b/src/appl/bsd/loginpaths.h @@ -96,6 +96,8 @@ #endif #ifdef _PATH_DEFPATH +#undef LPATH +#undef RPATH #define LPATH _PATH_DEFPATH #define RPATH _PATH_DEFPATH #endif diff --git a/src/appl/bsd/rcp.M b/src/appl/bsd/rcp.M index 46267a5..e047db5 100644 --- a/src/appl/bsd/rcp.M +++ b/src/appl/bsd/rcp.M @@ -24,11 +24,13 @@ rcp \- remote file copy .B rcp [\fB\-p\fP] [\fB\-x\fP] [\fB\-k\fP \fIrealm\fP ] [\fB\-D\fP \fIport\fP] [\fB\-N\fP] +[\fB\-PN | \-PO\fP] .I file1 file2 .sp .B rcp [\fB\-p\fB] [\fB\-x\fP] [\fP\-k\fP \fIrealm\fP] [\fB\-r\fP] [\fB\-D\fP \fIport\fP] [\fB\-N\fP] +[\fB\-PN | \-PO\fP] .I file ... directory .SH DESCRIPTION .B Rcp @@ -93,6 +95,16 @@ instead of the remote host's realm as determined by if any of the source files are directories, copy each subtree rooted at that name; in this case the destination must be a directory. .TP +\fB-PN\fP +.TP +\fB-PO\fP +Explicitly request new or old version of the Kerberos ``rcmd'' +protocol. The new protocol avoids many security problems found in the +old one, but is not interoperable with older servers. (An +"input/output error" and a closed connection is the most likely result +of attempting this combination.) If neither option is specified, some +simple heuristics are used to guess which to try. +.TP \fB\-D\fP \fIport\fP connect to port .I port diff --git a/src/appl/bsd/rlogin.M b/src/appl/bsd/rlogin.M index 79ac327..601fe46 100644 --- a/src/appl/bsd/rlogin.M +++ b/src/appl/bsd/rlogin.M @@ -25,6 +25,7 @@ rlogin \- remote login .I rhost [\fB\-e\fP\fI\|c\fP] [\fB\-8\fP] [\fB\-c\fP] [ \fB\-a\fP] [\fB\-f\fP] [\fB\-F\fP] [\fB\-t\fP \fItermtype\fP] [\fB\-n\fP] [\fB\-7\fP] +[\fB\-PN | \-PO\fP] [\fB\-d\fP] [\fB\-k\fP \fIrealm\fP] [\fB\-x\fP] [\fB\-L\fP] [\fB\-l\fP \fIusername\fP] .PP @@ -133,6 +134,16 @@ instead of the remote host's realm as determined by turn on DES encryption for all data passed via the rlogin session. This significantly reduces response time and significantly increases CPU utilization. +.TP +\fB-PN\fP +.TP +\fB-PO\fP +Explicitly request new or old version of the Kerberos ``rcmd'' +protocol. The new protocol avoids many security problems found in the +old one, but is not interoperable with older servers. (An +"input/output error" and a closed connection is the most likely result +of attempting this combination.) If neither option is specified, some +simple heuristics are used to guess which to try. .SH SEE ALSO rsh(1), kerberos(3), krb_sendauth(3), krb_realmofhost(3), rlogin(1) [UCB version] diff --git a/src/appl/bsd/rsh.M b/src/appl/bsd/rsh.M index 2b342c3..11a7290 100644 --- a/src/appl/bsd/rsh.M +++ b/src/appl/bsd/rsh.M @@ -25,6 +25,7 @@ rsh \- remote shell .I host [\fB\-l\fP \fIusername\fP] [\fB\-n\fP] [\fB\-d\fP] [\fB\-k\fP \fIrealm\fP] [\fB\-f\fP | \fB\-F\fP] [\fB\-x\fP] +[\fB\-PN | \-PO\fP] .I command .SH DESCRIPTION .B Rsh @@ -101,6 +102,16 @@ on the TCP sockets used for communication with the remote host. redirects input from the special device .I /dev/null (see the BUGS section below). +.TP +\fB-PN\fP +.TP +\fB-PO\fP +Explicitly request new or old version of the Kerberos ``rcmd'' +protocol. The new protocol avoids many security problems found in the +old one, but is not interoperable with older servers. (An +"input/output error" and a closed connection is the most likely result +of attempting this combination.) If neither option is specified, some +simple heuristics are used to guess which to try. .PP If you omit .IR command , diff --git a/src/appl/bsd/v4rcp.c b/src/appl/bsd/v4rcp.c index 36754de..3267783 100644 --- a/src/appl/bsd/v4rcp.c +++ b/src/appl/bsd/v4rcp.c @@ -208,7 +208,7 @@ int kstream_read(krem, buf, len) /* decrypt it */ des_pcbc_encrypt ((des_cblock *)krem->retbuf, (des_cblock *)krem->retbuf, - sz, *krem->sched, *krem->ivec, + sz, *krem->sched, krem->ivec, DECRYPT); /* now retbuf has sz bytes, return len or x of them to the user */ @@ -265,7 +265,7 @@ int kstream_write(krem, buf, len) abort (); /* memset(outbuf+4+4, 0x42, BUFSIZ); */ st = des_pcbc_encrypt ((des_cblock *)buf, (des_cblock *)(krem->outbuf+4+4), outlen, - *krem->sched, *krem->ivec, ENCRYPT); + *krem->sched, krem->ivec, ENCRYPT); if (st) abort(); return write(krem->write_fd, krem->outbuf+4, 4+outlen); @@ -400,6 +400,7 @@ int main(argc, argv) if (argc == 0) usage(); strncpy(krb_realm,*argv,REALM_SZ); + krb_realm[REALM_SZ-1] = 0; sprintf(realmarg, " -k %s", krb_realm); goto next_arg; #endif /* KERBEROS */ @@ -782,11 +783,20 @@ void sink(argc, argv) size = size * 10 + (*cp++ - '0'); if (*cp++ != ' ') SCREWUP("size not delimited"); - if (targisdir) - (void) sprintf(nambuf, "%s%s%s", targ, - *targ ? "/" : "", cp); - else - (void) strcpy(nambuf, targ); + if (targisdir) { + if (strlen(targ) + strlen(cp) + 1 < sizeof(nambuf)) { + (void) sprintf(nambuf, "%s%s%s", targ, + *targ ? "/" : "", cp); + } else { + SCREWUP("target directory name too long"); + } + } else { + if (strlen(targ) + 1 < sizeof(nambuf)) + (void) strncpy(nambuf, targ, sizeof(nambuf)-1); + else + SCREWUP("target pathname too long"); + } + nambuf[sizeof(nambuf)-1] = '\0'; exists = stat(nambuf, &stb) == 0; if (cmdbuf[0] == 'D') { if (exists) { diff --git a/src/appl/gssftp/ChangeLog b/src/appl/gssftp/ChangeLog index 691a2e9..b8205e0 100644 --- a/src/appl/gssftp/ChangeLog +++ b/src/appl/gssftp/ChangeLog @@ -1,3 +1,12 @@ +2001-12-18 Ken Raeburn + + * configure.in: Check for strerror. + +2000-03-24 Ken Raeburn + + * configure.in: Check for alpha*-dec-osf* instead of + alpha-dec-osf*. + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/appl/gssftp/configure.in b/src/appl/gssftp/configure.in index f0c2bff..3851949 100644 --- a/src/appl/gssftp/configure.in +++ b/src/appl/gssftp/configure.in @@ -20,7 +20,7 @@ AC_CHECK_HEADERS(unistd.h stdlib.h string.h sys/select.h sys/sockio.h paths.h) CHECK_UTMP DECLARE_SYS_ERRLIST AC_REPLACE_FUNCS(getdtablesize) -AC_HAVE_FUNCS(getcwd getusershell seteuid setreuid setresuid) +AC_HAVE_FUNCS(getcwd getusershell seteuid setreuid setresuid strerror) AC_CHECK_LIB(crypt,crypt) dnl AC_CHECK_LIB(util,logwtmp) dnl dnl @@ -67,7 +67,7 @@ else FTPD_LIBS="../../../krb524/libkrb524.a" fi case $krb5_cv_host in -alpha-dec-osf*) +alpha*-dec-osf*) AC_CHECK_LIB(security,setluid, AC_DEFINE(HAVE_SETLUID) FTPD_LIBS="$FTPD_LIBS -lsecurity" diff --git a/src/appl/gssftp/ftp/ChangeLog b/src/appl/gssftp/ftp/ChangeLog index 411aff7..63fe2f5 100644 --- a/src/appl/gssftp/ftp/ChangeLog +++ b/src/appl/gssftp/ftp/ChangeLog @@ -1,3 +1,50 @@ +2001-12-18 Ken Raeburn + + * cmds.c (strerror): Only define if not HAVE_STRERROR. + * ftp.c (strerror): Likewise. + * secure.c (secure_putbuf, secure_getbyte): Use strerror. + +2001-11-30 Tom Yu + + * glob.c (execbrc): Fix some fencepost errors. Don't copy + uninitialized memory past the end of the pattern string. Don't + increment pointer beyond string end. + +2001-11-02 Tom Yu + + * cmds.c (setpeer): Kludge to #define unix on BSD for now. + +2001-10-29 Ezra Peisach + + * secure.c: Instead of hard wiring the FUDGE_FACTOR, new variables + to keep track of the total buffer length desired and the actual + maximum that can be fitted. Add secure_determine_constants() to + determine the mechanism dependent overhead. This has a hard limit + for krb4 - for gssapi use gss_wrap_size_limit. + [pullup from trunk] + +2001-10-26 Ken Raeburn + + * cmds.c (setpeer): Use unsigned short for port number. Patch + from Garry Zacheiss. + +2000-05-11 Nalin Dahyabhai + + * domacro.c (domacro): Don't overflow "line2" + * ftp.c (getreply, krb4 compat): Bail if message data too big for buffer + (getreply, gssapi): Ditto. + (pswitch): Don't overflow "ntin", "ntout", "mapin", "mapout". + (do_auth, krb4 compat): Don't overflow "realm". + +2000-04-27 Nalin Dahyabhai + + * cmds.c (remglob): Don't overflow buffer "temp". + (shell): Don't overflow buffer "shellnam". + (quote1): "buf" + * glob.c (ftpglob): Fix boundary in buffer "agpath". + (expand): Don't overflow buffer pointed to by "gpath". + (execbrc): Don't overflow buffer "restbuf". + 2000-02-18 Ken Raeburn * cmds.c (mls): Declare some variables volatile to protect against diff --git a/src/appl/gssftp/ftp/cmds.c b/src/appl/gssftp/ftp/cmds.c index 2a8e775..886327a 100644 --- a/src/appl/gssftp/ftp/cmds.c +++ b/src/appl/gssftp/ftp/cmds.c @@ -70,10 +70,12 @@ extern char **ftpglob(); extern char *home; extern char *remglob(); extern char *getenv(); +#ifndef HAVE_STRERROR #define strerror(error) (sys_errlist[error]) #ifdef NEED_SYS_ERRLIST extern char *sys_errlist[]; #endif +#endif extern off_t restart_point; extern char reply_string[]; @@ -126,7 +128,7 @@ setpeer(argc, argv) char *argv[]; { char *host, *hookup(); - short port; + unsigned short port; if (connected) { printf("Already connected to %s, use close first.\n", @@ -182,7 +184,7 @@ setpeer(argc, argv) (void) login(argv[1]); } -#ifndef unix +#ifndef unix /* XXX */ #ifdef _AIX #define unix #endif @@ -190,6 +192,10 @@ setpeer(argc, argv) #ifdef __hpux #define unix #endif + +#ifdef BSD +#define unix +#endif #endif #if defined(unix) && (NBBY == 8 || defined(linux)) @@ -1049,7 +1055,8 @@ remglob(argv,doswitch) return (cp); } if (ftemp == NULL) { - (void) strcpy(temp, _PATH_TMP); + (void) strncpy(temp, _PATH_TMP, sizeof(temp) - 1); + temp[sizeof(temp) - 1] = '\0'; (void) mktemp(temp); oldverbose = verbose, verbose = 0; oldhash = hash, hash = 0; @@ -1510,7 +1517,8 @@ shell(argc, argv) if (namep == NULL) namep = shell; (void) strcpy(shellnam,"-"); - (void) strcat(shellnam, ++namep); + (void) strncat(shellnam, ++namep, sizeof(shellnam) - 1 - strlen(shellnam)); + shellnam[sizeof(shellnam) - 1] = '\0'; if (strcmp(namep, "sh") != 0) shellnam[0] = '+'; if (debug) { @@ -1702,13 +1710,14 @@ quote1(initial, argc, argv) register int i, len; char buf[FTP_BUFSIZ]; /* must be >= sizeof(line) */ - (void) strcpy(buf, initial); + (void) strncpy(buf, initial, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; if (argc > 1) { len = strlen(buf); - len += strlen(strcpy(&buf[len], argv[1])); + len += strlen(strncpy(&buf[len], argv[1], sizeof(buf) - 1 - len)); for (i = 2; i < argc; i++) { buf[len++] = ' '; - len += strlen(strcpy(&buf[len], argv[i])); + len += strlen(strncpy(&buf[len], argv[i], sizeof(buf) - 1 - len)); } } if (command(buf) == PRELIM) { diff --git a/src/appl/gssftp/ftp/domacro.c b/src/appl/gssftp/ftp/domacro.c index 9bc277b..ecfe9b4 100644 --- a/src/appl/gssftp/ftp/domacro.c +++ b/src/appl/gssftp/ftp/domacro.c @@ -71,7 +71,8 @@ domacro(argc, argv) code = -1; return; } - (void) strcpy(line2, line); + (void) strncpy(line2, line, sizeof(line2) - 1); + line2[sizeof(line2) - 1] = '\0'; TOP: cp1 = macros[i].mac_start; while (cp1 != macros[i].mac_end) { @@ -92,7 +93,11 @@ TOP: } cp1--; if (argc - 2 >= j) { - (void) strcpy(cp2, argv[j+1]); + if(cp2 + strlen(argv[j+1]) - line < sizeof(line)) + (void) strncpy(cp2, argv[j+1], + sizeof(line) - 1 - + (cp2 - line)); + line[sizeof(line) - 1] = '\0'; cp2 += strlen(argv[j+1]); } break; @@ -101,7 +106,11 @@ TOP: loopflg = 1; cp1++; if (count < argc) { - (void) strcpy(cp2, argv[count]); + if(cp2 + strlen(argv[j+1]) - line < sizeof(line)) + (void) strncpy(cp2, argv[count], + sizeof(line) - 1 - + (cp2 - line)); + line[sizeof(line) - 1] = '\0'; cp2 += strlen(argv[count]); } break; @@ -138,7 +147,8 @@ TOP: if (bell && c->c_bell) { (void) putchar('\007'); } - (void) strcpy(line, line2); + (void) strncpy(line, line2, sizeof(line) - 1); + line[sizeof(line) - 1] = '\0'; makeargv(); argc = margc; argv = margv; diff --git a/src/appl/gssftp/ftp/ftp.c b/src/appl/gssftp/ftp/ftp.c index 11f583a..cc84f4b 100644 --- a/src/appl/gssftp/ftp/ftp.c +++ b/src/appl/gssftp/ftp/ftp.c @@ -154,10 +154,12 @@ uid_t getuid(); sig_t lostpeer(); off_t restart_point = 0; +#ifndef HAVE_STRERROR #define strerror(error) (sys_errlist[error]) #ifdef NEED_SYS_ERRLIST extern char *sys_errlist[]; #endif +#endif extern int connected; @@ -680,9 +682,13 @@ getreply(expecteof) n = '5'; } else { if (debug) printf("%c:", safe ? 'S' : 'P'); - memcpy(ibuf, msg_data.app_data, - msg_data.app_length); - strcpy(&ibuf[msg_data.app_length], "\r\n"); + if(msg_data.app_length < sizeof(ibuf) - 2) { + memcpy(ibuf, msg_data.app_data, + msg_data.app_length); + strcpy(&ibuf[msg_data.app_length], "\r\n"); + } else { + printf("Message too long!"); + } continue; } #endif @@ -703,9 +709,14 @@ getreply(expecteof) "failed unsealing reply"); n = '5'; } else { - memcpy(ibuf, msg_buf.value, - msg_buf.length); - strcpy(&ibuf[msg_buf.length], "\r\n"); + if(msg_buf.length < sizeof(ibuf) - 2 - 1) { + memcpy(ibuf, msg_buf.value, + msg_buf.length); + strcpy(&ibuf[msg_buf.length], "\r\n"); + } else { + user_gss_error(maj_stat, min_stat, + "reply was too long"); + } gss_release_buffer(&min_stat,&msg_buf); continue; } @@ -1636,20 +1647,24 @@ pswitch(flag) mcase = op->mcse; ip->ntflg = ntflag; ntflag = op->ntflg; - (void) strncpy(ip->nti, ntin, 16); + (void) strncpy(ip->nti, ntin, sizeof(ip->nti) - 1); (ip->nti)[strlen(ip->nti)] = '\0'; - (void) strcpy(ntin, op->nti); - (void) strncpy(ip->nto, ntout, 16); + (void) strncpy(ntin, op->nti, sizeof(ntin) - 1); + ntin[sizeof(ntin) - 1] = '\0'; + (void) strncpy(ip->nto, ntout, sizeof(ip->nto) - 1); (ip->nto)[strlen(ip->nto)] = '\0'; - (void) strcpy(ntout, op->nto); + (void) strncpy(ntout, op->nto, sizeof(ntout) - 1); + ntout[sizeof(ntout) - 1] = '\0'; ip->mapflg = mapflag; mapflag = op->mapflg; (void) strncpy(ip->mi, mapin, MAXPATHLEN - 1); (ip->mi)[strlen(ip->mi)] = '\0'; - (void) strcpy(mapin, op->mi); + (void) strncpy(mapin, op->mi, sizeof(mapin) - 1); + mapin[sizeof(mapin) - 1] = '\0'; (void) strncpy(ip->mo, mapout, MAXPATHLEN - 1); (ip->mo)[strlen(ip->mo)] = '\0'; - (void) strcpy(mapout, op->mo); + (void) strncpy(mapout, op->mo, sizeof(mapout) - 1); + mapout[sizeof(mapout) - 1] = '\0'; ip->authtype = auth_type; auth_type = op->authtype; ip->clvl = clevel; @@ -1846,7 +1861,8 @@ gunique(local) fprintf(stderr, "local: %s: %s\n", local, strerror(errno)); return((char *) 0); } - (void) strcpy(new, local); + (void) strncpy(new, local, sizeof(new) - 3); + new[sizeof(new) - 1] = '\0'; cp = new + strlen(new); *cp++ = '.'; while (!d) { @@ -2054,9 +2070,11 @@ do_auth() if (verbose) printf("%s accepted as authentication type\n", "KERBEROS_V4"); - strcpy(inst, (char *) krb_get_phost(hostname)); + strncpy(inst, (char *) krb_get_phost(hostname), sizeof(inst) - 1); + inst[sizeof(inst) - 1] = '\0'; if (realm[0] == '\0') - strcpy(realm, (char *) krb_realmofhost(hostname)); + strncpy(realm, (char *) krb_realmofhost(hostname), sizeof(realm) - 1); + realm[sizeof(realm) - 1] = '\0'; if ((kerror = krb_mk_req(&ticket, service = "ftp", inst, realm, checksum)) && (kerror != KDC_PR_UNKNOWN || diff --git a/src/appl/gssftp/ftp/glob.c b/src/appl/gssftp/ftp/glob.c index f92ee5e..52b9899 100644 --- a/src/appl/gssftp/ftp/glob.c +++ b/src/appl/gssftp/ftp/glob.c @@ -118,7 +118,7 @@ ftpglob(v) globerr = 0; gpath = agpath; gpathp = gpath; *gpathp = 0; - lastgpathp = &gpath[sizeof agpath - 2]; + lastgpathp = &gpath[sizeof(agpath) - 1]; ginit(agargv); globcnt = 0; collect(v); if (globcnt == 0 && (gflag&1)) { @@ -198,7 +198,8 @@ expand(as) globerr = "Unknown user name after ~"; (void) strcpy(gpath, gpath + 1); } else - (void) strcpy(gpath, home); + (void) strncpy(gpath, home, FTP_BUFSIZ - 1); + gpath[FTP_BUFSIZ - 1] = '\0'; gpathp = strend(gpath); } } @@ -283,6 +284,7 @@ execbrc(p, s) for (lm = restbuf; *p != '{'; *lm++ = *p++) continue; + /* pe starts pointing to one past the first '{'. */ for (pe = ++p; *pe; pe++) switch (*pe) { @@ -299,6 +301,8 @@ execbrc(p, s) case '[': for (pe++; *pe && *pe != ']'; pe++) continue; + if (!*pe) + pe--; continue; } pend: @@ -311,7 +315,7 @@ pend: continue; case '}': - if (brclev) { + if (brclev) { /* brclev = 0 is outermost brace set */ brclev--; continue; } @@ -324,8 +328,12 @@ pend: doit: savec = *pm; *pm = 0; - (void) strcpy(lm, pl); - (void) strcat(restbuf, pe + 1); + (void) strncpy(lm, pl, sizeof(restbuf) - 1 - (lm - restbuf)); + restbuf[sizeof(restbuf) - 1] = '\0'; + if (*pe) { + (void) strncat(restbuf, pe + 1, + sizeof(restbuf) - 1 - strlen(restbuf)); + } *pm = savec; if (s == 0) { sgpathp = gpathp; @@ -700,7 +708,7 @@ gethdir(home) { register struct passwd *pp = getpwnam(home); - if (!pp || home + strlen(pp->pw_dir) >= lastgpathp) + if (!pp || ((home + strlen(pp->pw_dir)) >= lastgpathp)) return (1); (void) strcpy(home, pp->pw_dir); return (0); diff --git a/src/appl/gssftp/ftp/main.c b/src/appl/gssftp/ftp/main.c index 9c1e43a..6c7e1e9 100644 --- a/src/appl/gssftp/ftp/main.c +++ b/src/appl/gssftp/ftp/main.c @@ -193,7 +193,8 @@ main(argc, argv) pw = getpwuid(getuid()); if (pw != NULL) { home = homedir; - (void) strcpy(home, pw->pw_dir); + (void) strncpy(home, pw->pw_dir, sizeof(homedir) - 1); + homedir[sizeof(homedir) - 1] = '\0'; } if (argc > 0) { if (setjmp(toplevel)) diff --git a/src/appl/gssftp/ftp/secure.c b/src/appl/gssftp/ftp/secure.c index 48f57f9..3f5b7c1 100644 --- a/src/appl/gssftp/ftp/secure.c +++ b/src/appl/gssftp/ftp/secure.c @@ -3,6 +3,11 @@ * secure read(), write(), getc(), and putc(). * Only one security context, thus only work on one fd at a time! */ +#ifdef GSSAPI +#include +#include +extern gss_ctx_id_t gcontext; +#endif /* GSSAPI */ #include /* stuff which is specific to client or server */ @@ -31,9 +36,12 @@ extern gss_ctx_id_t gcontext; #include #include +#ifndef HAVE_STRERROR +#define strerror(error) (sys_errlist[error]) #ifdef NEED_SYS_ERRLIST extern char *sys_errlist[]; #endif +#endif #if (SIZEOF_SHORT == 4) typedef unsigned short ftp_uint32; @@ -52,29 +60,29 @@ extern struct sockaddr_in myaddr; extern int dlevel; extern char *auth_type; +/* Some libc's (GNU libc, at least) define MAX as a macro. Forget that. */ +#ifdef MAX +#undef MAX +#endif + #define MAX maxbuf extern unsigned int maxbuf; /* maximum output buffer size */ extern unsigned char *ucbuf; /* cleartext buffer */ static unsigned int nout, bufp; /* number of chars in ucbuf, * pointer into ucbuf */ +static unsigned int smaxbuf; /* Internal saved value of maxbuf + in case changes on us */ +static unsigned int smaxqueue; /* Maximum allowed to queue before + flush buffer. < smaxbuf by fudgefactor */ #ifdef KRB5_KRB4_COMPAT -#define FUDGE_FACTOR 32 /* Amount of growth +#define KRB4_FUDGE_FACTOR 32 /* Amount of growth * from cleartext to ciphertext. * krb_mk_priv adds this # bytes. * Must be defined for each auth type. */ #endif /* KRB5_KRB4_COMPAT */ -#ifdef GSSAPI -#undef FUDGE_FACTOR -#define FUDGE_FACTOR 64 /*It appears to add 52 byts, but I'm not usre it is a constant--hartmans*/ -#endif /*GSSAPI*/ - -#ifndef FUDGE_FACTOR /* In case no auth types define it. */ -#define FUDGE_FACTOR 0 -#endif - #ifdef KRB5_KRB4_COMPAT /* XXX - The following must be redefined if KERBEROS_V4 is not used * but some other auth type is. They must have the same properties. */ @@ -145,20 +153,63 @@ extern secure_error(); #define ERR -2 -static +/* + * Given maxbuf as a buffer size, determine how much can we + * really transfer given the overhead of different algorithms + * + * Sets smaxbuf and smaxqueue + */ + +static int secure_determine_constants() +{ + smaxbuf = maxbuf; + smaxqueue = maxbuf; + +#ifdef KRB5_KRB4_COMPAT + /* For KRB4 - we know the fudge factor to be 32 */ + if (strcmp(auth_type, "KERBEROS_V4") == 0) { + smaxqueue = smaxbuf - KRB4_FUDGE_FACTOR; + } +#endif +#ifdef GSSAPI + if (strcmp(auth_type, "GSSAPI") == 0) { + OM_uint32 maj_stat, min_stat, mlen; + OM_uint32 msize = maxbuf; + maj_stat = gss_wrap_size_limit(&min_stat, gcontext, + (dlevel == PROT_P), + GSS_C_QOP_DEFAULT, + msize, &mlen); + if (maj_stat != GSS_S_COMPLETE) { + secure_gss_error(maj_stat, min_stat, + "GSSAPI fudge determination"); + /* Return error how? */ + return ERR; + } + smaxqueue = mlen; + } +#endif + + return 0; +} + +static int secure_putbyte(fd, c) int fd; unsigned char c; { int ret; + if ((smaxbuf == 0) || (smaxqueue == 0) || (smaxbuf != maxbuf)) { + ret = secure_determine_constants(); + if (ret) return ret; + } ucbuf[nout++] = c; - if (nout == MAX - FUDGE_FACTOR) { + if (nout == smaxqueue) { nout = 0; - ret = secure_putbuf(fd, ucbuf, MAX - FUDGE_FACTOR); + ret = secure_putbuf(fd, ucbuf, smaxqueue); return(ret?ret:c); } -return (c); + return (c); } /* returns: @@ -228,18 +279,20 @@ unsigned int nbyte; static unsigned int bufsize; /* size of outbuf */ ftp_int32 length; ftp_uint32 net_len; + unsigned int fudge = smaxbuf - smaxqueue; /* Difference in length + buffer lengths required */ /* Other auth types go here ... */ #ifdef KRB5_KRB4_COMPAT - if (bufsize < nbyte + FUDGE_FACTOR) { + if (bufsize < nbyte + fudge) { if (outbuf? - (outbuf = realloc(outbuf, (unsigned) (nbyte + FUDGE_FACTOR))): - (outbuf = malloc((unsigned) (nbyte + FUDGE_FACTOR)))) { - bufsize =nbyte + FUDGE_FACTOR; + (outbuf = realloc(outbuf, (unsigned) (nbyte + fudge))): + (outbuf = malloc((unsigned) (nbyte + fudge)))) { + bufsize = nbyte + fudge; } else { bufsize = 0; secure_error("%s (in malloc of PROT buffer)", - sys_errlist[errno]); + strerror(errno)); return(ERR); } } @@ -286,7 +339,7 @@ unsigned int nbyte; } else { bufsize = 0; secure_error("%s (in malloc of PROT buffer)", - sys_errlist[errno]); + strerror(errno)); return(ERR); } } @@ -315,7 +368,7 @@ int fd; != sizeof(length)) { secure_error("Couldn't read PROT buffer length: %d/%s", kerror, - kerror == -1 ? sys_errlist[errno] + kerror == -1 ? strerror(errno) : "premature EOF"); return(ERR); } @@ -327,7 +380,7 @@ int fd; if ((kerror = looping_read(fd, ucbuf, length)) != length) { secure_error("Couldn't read %u byte PROT buffer: %s", length, kerror == -1 ? - sys_errlist[errno] : "premature EOF"); + strerror(errno) : "premature EOF"); return(ERR); } /* Other auth types go here ... */ diff --git a/src/appl/gssftp/ftpd/ChangeLog b/src/appl/gssftp/ftpd/ChangeLog index a459d30..51a1243 100644 --- a/src/appl/gssftp/ftpd/ChangeLog +++ b/src/appl/gssftp/ftpd/ChangeLog @@ -1,3 +1,62 @@ +2001-12-18 Ken Raeburn + + * ftpd.c (strerror): Only define if not HAVE_STRERROR. + +2001-11-30 Tom Yu + + * ftpcmd.y (pathname): Handle returns from ftpglob() better so + that errors get sent via reply(), while causing some match + failures to match to simply return $1, so the higher level can + deal. Previously, some failures would cause synch problems since + NULL would be returned and no reply was sent. + +2001-11-02 Tom Yu + + * ftpcmd.y: Kludge to #define unix on BSD for now. + +2001-10-29 Ken Raeburn + + * ftpd.c (login): New argument LOGINCODE, optional result code to + override local use of success code 230 when homedir is not + accessible but root directory is. + (user): Pass result code 232 to login. + (pass): Pass result code 0 to login. + +2001-08-28 Ezra Peisach + + * ftpd.c (auth_data): Iterate over all krb4 services instead of + trying to examine the srvtab file for a particular key (which + failes when falling back on the v5 keytab for des3 services). + [pullup from trunk] + +2001-04-25 Tom Yu + + * ftpcmd.y: Don't dereference a NULL pointer returned from + ftpglob(). + + * ftpd.c: Be more paranoid about return values from ftpglob(). + Police uses of sprintf(). Account for expansion in + radix_encode(). + +2000-08-25 Tom Yu + + * ftpcmd.y: Fix up grammar so that single character token names + are no longer used; this was breaking the build using bison on + HP/UX because some system headers declare structures with members + having all-uppercase field names and bison puts the token name + #define statements in front of the C declarations section in the + output, causing them to be in force while those headers get + #included. There doesn't seem to be much purpose in not just + using character constants, anyway. + +2000-06-14 Tom Yu + + * ftpcmd.y (nonguest): Return $1, not 1, if (!guest). + +2000-05-11 Nalin Dahyabhai + + * ftpd.c (gunique): Make sure that path stored in "new" isn't too long. + 2000-02-18 Ken Raeburn * ftpd.c (reply, lreply): Declare with format attribute under diff --git a/src/appl/gssftp/ftpd/ftpcmd.y b/src/appl/gssftp/ftpd/ftpcmd.y index acd1871..80465a5 100644 --- a/src/appl/gssftp/ftpd/ftpcmd.y +++ b/src/appl/gssftp/ftpd/ftpcmd.y @@ -91,13 +91,16 @@ extern MSG_DAT msg_data; extern gss_ctx_id_t gcontext; #endif -#ifndef unix +#ifndef unix /* XXX */ #ifdef _AIX #define unix #endif #ifdef __hpux #define unix #endif +#ifdef BSD +#define unix +#endif #endif #ifndef NBBY @@ -172,9 +175,6 @@ struct tab sitetab[]; %union { int num; char *str; } %token - A B C E F I - L N P R S T - SP CRLF COMMA STRING NUMBER USER PASS ACCT REIN QUIT PORT @@ -353,7 +353,7 @@ cmd: USER SP username CRLF = { reply(202, "ALLO command ignored."); } - | ALLO SP NUMBER SP R SP NUMBER CRLF + | ALLO SP NUMBER SP 'R' SP NUMBER CRLF = { reply(202, "ALLO command ignored."); } @@ -698,103 +698,103 @@ host_port: NUMBER COMMA NUMBER COMMA NUMBER COMMA NUMBER COMMA } ; -form_code: N +form_code: 'N' = { $$ = FORM_N; } - | T + | 'T' = { $$ = FORM_T; } - | C + | 'C' = { $$ = FORM_C; } ; -prot_code: C +prot_code: 'C' = { $$ = PROT_C; } - | S + | 'S' = { $$ = PROT_S; } - | P + | 'P' = { $$ = PROT_P; } - | E + | 'E' = { $$ = PROT_E; } ; -type_code: A +type_code: 'A' = { cmd_type = TYPE_A; cmd_form = FORM_N; } - | A SP form_code + | 'A' SP form_code = { cmd_type = TYPE_A; cmd_form = $3; } - | E + | 'E' = { cmd_type = TYPE_E; cmd_form = FORM_N; } - | E SP form_code + | 'E' SP form_code = { cmd_type = TYPE_E; cmd_form = $3; } - | I + | 'I' = { cmd_type = TYPE_I; } - | L + | 'L' = { cmd_type = TYPE_L; cmd_bytesz = NBBY; } - | L SP byte_size + | 'L' SP byte_size = { cmd_type = TYPE_L; cmd_bytesz = $3; } /* this is for a bug in the BBN ftp */ - | L byte_size + | 'L' byte_size = { cmd_type = TYPE_L; cmd_bytesz = $2; } ; -struct_code: F +struct_code: 'F' = { $$ = STRU_F; } - | R + | 'R' = { $$ = STRU_R; } - | P + | 'P' = { $$ = STRU_P; } ; -mode_code: S +mode_code: 'S' = { $$ = MODE_S; } - | B + | 'B' = { $$ = MODE_B; } - | C + | 'C' = { $$ = MODE_C; } @@ -808,12 +808,19 @@ pathname: pathstring * This is a valid reply in some cases but not in others. */ if (logged_in && $1 && strncmp((char *) $1, "~", 1) == 0) { - *(char **)&($$) = *ftpglob((char *) $1); - if (globerr != NULL) { - reply(550, globerr); - $$ = NULL; - } - free((char *) $1); + char **vv; + + vv = ftpglob((char *) $1); + $$ = (vv != NULL) ? *vv : NULL; + if ($$ == NULL) { + if (globerr == NULL) + $$ = $1; + else { + reply(550, "%s", globerr); + free((char *) $1); + } + } else + free((char *) $1); } else $$ = $1; } @@ -865,7 +872,7 @@ nonguest: check_login $$ = 0; } else - $$ = 1; + $$ = $1; } ; %% @@ -1349,51 +1356,51 @@ yylex() case 'A': case 'a': - return (A); + return ('A'); case 'B': case 'b': - return (B); + return ('B'); case 'C': case 'c': - return (C); + return ('C'); case 'E': case 'e': - return (E); + return ('E'); case 'F': case 'f': - return (F); + return ('F'); case 'I': case 'i': - return (I); + return ('I'); case 'L': case 'l': - return (L); + return ('L'); case 'N': case 'n': - return (N); + return ('N'); case 'P': case 'p': - return (P); + return ('P'); case 'R': case 'r': - return (R); + return ('R'); case 'S': case 's': - return (S); + return ('S'); case 'T': case 't': - return (T); + return ('T'); } break; diff --git a/src/appl/gssftp/ftpd/ftpd.c b/src/appl/gssftp/ftpd/ftpd.c index c7dfc8a..d4ded83 100644 --- a/src/appl/gssftp/ftpd/ftpd.c +++ b/src/appl/gssftp/ftpd/ftpd.c @@ -109,10 +109,12 @@ static char sccsid[] = "@(#)ftpd.c 5.40 (Berkeley) 7/2/91"; #define L_INCR 1 #endif +#ifndef HAVE_STRERROR #define strerror(error) (sys_errlist[error]) #ifdef NEED_SYS_ERRLIST extern char *sys_errlist[]; #endif +#endif extern char *mktemp (); @@ -761,7 +763,17 @@ user(name) int result; #ifdef GSSAPI if (auth_type && strcmp(auth_type, "GSSAPI") == 0) { + int len; + authorized = ftpd_gss_userok(&client_name, name) == 0; + len = sizeof("GSSAPI user is not authorized as " + "; Password required.") + + strlen(client_name.value) + + strlen(name); + if (len >= sizeof(buf)) { + syslog(LOG_ERR, "user: username too long"); + name = "[username too long]"; + } sprintf(buf, "GSSAPI user %s is%s authorized as %s", client_name.value, authorized ? "" : " not", name); @@ -772,7 +784,19 @@ user(name) #endif /* GSSAPI */ #ifdef KRB5_KRB4_COMPAT if (auth_type && strcmp(auth_type, "KERBEROS_V4") == 0) { + int len; + authorized = kuserok(&kdata,name) == 0; + len = sizeof("Kerberos user .@ is not authorized as " + "; Password required.") + + strlen(kdata.pname) + + strlen(kdata.pinst) + + strlen(kdata.prealm) + + strlen(name); + if (len >= sizeof(buf)) { + syslog(LOG_ERR, "user: username too long"); + name = "[username too long]"; + } sprintf(buf, "Kerberos user %s%s%s@%s is%s authorized as %s", kdata.pname, *kdata.pinst ? "." : "", kdata.pinst, kdata.prealm, @@ -796,7 +820,7 @@ user(name) syslog(authorized ? LOG_INFO : LOG_ERR, "%s", buf); if (result == 232) - login(NULL); + login(NULL, result); return; } @@ -1064,11 +1088,11 @@ pass(passwd) } login_attempts = 0; /* this time successful */ - login(passwd); + login(passwd, 0); return; } -login(passwd) +login(passwd, logincode) char *passwd; { if (have_creds) { @@ -1127,8 +1151,11 @@ login(passwd) reply(530, "User %s: can't change directory to %s.", pw->pw_name, pw->pw_dir); goto bad; - } else - lreply(230, "No directory! Logging in with home=/"); + } else { + if (!logincode) + logincode = 230; + lreply(logincode, "No directory! Logging in with home=/"); + } } } if (guest) { @@ -1179,6 +1206,11 @@ retrieve(cmd, name) } else { char line[FTP_BUFSIZ]; + if (strlen(cmd) + strlen(name) + 1 >= sizeof(line)) { + syslog(LOG_ERR, "retrieve: filename too long"); + reply(501, "filename too long"); + return; + } (void) sprintf(line, cmd, name), name = line; fin = ftpd_popen(line, "r"), closefunc = ftpd_pclose; st.st_size = -1; @@ -1417,6 +1449,10 @@ dataconn(name, size, mode) return (file); } +/* + * XXX callers need to limit total length of output string to + * FTP_BUFSIZ + */ #ifdef STDARG secure_error(char *fmt, ...) #else @@ -1616,13 +1652,19 @@ statfilecmd(filename) { char line[FTP_BUFSIZ]; FILE *fin; - int c; + int c, n; char str[FTP_BUFSIZ], *p; + if (strlen(filename) + sizeof("/bin/ls -lgA ") + >= sizeof(line)) { + reply(501, "filename too long"); + return; + } (void) sprintf(line, "/bin/ls -lgA %s", filename); fin = ftpd_popen(line, "r"); lreply(211, "status of %s:", filename); p = str; + n = 0; while ((c = getc(fin)) != EOF) { if (c == '\n') { if (ferror(stdout)){ @@ -1639,7 +1681,16 @@ statfilecmd(filename) *p = '\0'; reply(0, "%s", str); p = str; - } else *p++ = c; + n = 0; + } else { + *p++ = c; + n++; + if (n >= sizeof(str)) { + reply(551, "output line too long"); + (void) ftpd_pclose(fin); + return; + } + } } if (p != str) { *p = '\0'; @@ -1723,6 +1774,10 @@ fatal(s) char cont_char = ' '; +/* + * XXX callers need to limit total length of output string to + * FTP_BUFSIZ bytes for now. + */ #ifdef STDARG reply(int n, char *fmt, ...) #else @@ -1744,22 +1799,32 @@ reply(n, fmt, p0, p1, p2, p3, p4, p5) #endif if (auth_type) { - char in[FTP_BUFSIZ], out[FTP_BUFSIZ]; + /* + * Deal with expansion in mk_{safe,priv}, + * radix_encode, gss_seal, plus slop. + */ + char in[FTP_BUFSIZ*3/2], out[FTP_BUFSIZ*3/2]; int length, kerror; if (n) sprintf(in, "%d%c", n, cont_char); else in[0] = '\0'; strncat(in, buf, sizeof (in) - strlen(in) - 1); #ifdef KRB5_KRB4_COMPAT if (strcmp(auth_type, "KERBEROS_V4") == 0) { - if ((length = clevel == PROT_P ? - krb_mk_priv((unsigned char *)in, - (unsigned char *)out, - strlen(in), schedule, &kdata.session, - &ctrl_addr, &his_addr) - : krb_mk_safe((unsigned char *)in, - (unsigned char *)out, - strlen(in), &kdata.session, - &ctrl_addr, &his_addr)) == -1) { + if (clevel == PROT_P) + length = krb_mk_priv((unsigned char *)in, + (unsigned char *)out, + strlen(in), + schedule, &kdata.session, + &ctrl_addr, + &his_addr); + else + length = krb_mk_safe((unsigned char *)in, + (unsigned char *)out, + strlen(in), + &kdata.session, + &ctrl_addr, + &his_addr); + if (length == -1) { syslog(LOG_ERR, "krb_mk_%s failed for KERBEROS_V4", clevel == PROT_P ? "priv" : "safe"); @@ -1803,13 +1868,16 @@ reply(n, fmt, p0, p1, p2, p3, p4, p5) } #endif /* GSSAPI */ /* Other auth types go here ... */ - if (kerror = radix_encode(out, in, &length, 0)) { + if (length >= sizeof(in) / 4 * 3) { + syslog(LOG_ERR, "input to radix_encode too long"); + fputs(in, stdout); + } else if (kerror = radix_encode(out, in, &length, 0)) { syslog(LOG_ERR, "Couldn't encode reply (%s)", radix_error(kerror)); fputs(in,stdout); } else - printf("%s%c%s", clevel == PROT_P ? "632" : "631", - n ? cont_char : '-', in); + printf("%s%c%s", clevel == PROT_P ? "632" : "631", + n ? cont_char : '-', in); } else { if (n) printf("%d%c", n, cont_char); fputs(buf, stdout); @@ -1822,6 +1890,10 @@ reply(n, fmt, p0, p1, p2, p3, p4, p5) } } +/* + * XXX callers need to limit total length of output string to + * FTP_BUFSIZ + */ #ifdef STDARG lreply(int n, char *fmt, ...) #else @@ -1866,7 +1938,8 @@ yyerror(s) if (cp = strchr(cbuf,'\n')) *cp = '\0'; - reply(500, "'%s': command not understood.", cbuf); + reply(500, "'%.*s': command not understood.", + FTP_BUFSIZ - sizeof("'': command not understood."), cbuf); } delete_file(name) @@ -2123,7 +2196,8 @@ gunique(local) } if (cp) *cp = '/'; - (void) strcpy(new, local); + (void) strncpy(new, local, sizeof(new) - 1); + new[sizeof(new) - 1] = '\0'; cp = new + strlen(new); *cp++ = '.'; for (count = 1; count < 100; count++) { @@ -2142,7 +2216,23 @@ perror_reply(code, string) int code; char *string; { - reply(code, "%s: %s.", string, strerror(errno)); + char *err_string; + size_t extra_len; + + err_string = strerror(errno); + if (err_string == NULL) + err_string = "(unknown error)"; + extra_len = strlen(err_string) + sizeof("(truncated): ."); + + /* + * XXX knows about FTP_BUFSIZ in reply() + */ + if (strlen(string) + extra_len > FTP_BUFSIZ) { + reply(code, "(truncated)%.*s: %s.", + FTP_BUFSIZ - extra_len, string, err_string); + } else { + reply(code, "%s: %s.", string, err_string); + } } auth(type) @@ -2173,7 +2263,7 @@ char *data; int kerror, length; #ifdef KRB5_KRB4_COMPAT int i; - static char *service; + static char **service=NULL; char instance[INST_SZ]; u_long cksum; char buf[FTP_BUFSIZ]; @@ -2199,23 +2289,22 @@ char *data; } (void) memcpy((char *)ticket.dat, (char *)out_buf, ticket.length = length); strcpy(instance, "*"); - if (!service) { - char realm[REALM_SZ]; - des_cblock key; - - service = "ftp"; - if (krb_get_lrealm(realm, 1) == KSUCCESS && - read_service_key(service, instance, realm, 0, keyfile, key)) - service = "rcmd"; - else - (void) memset(key, 0, sizeof(key)); - } - if (kerror = krb_rd_req(&ticket, service, instance, - his_addr.sin_addr.s_addr, &kdata, keyfile)) { - secure_error("ADAT: Kerberos V4 krb_rd_req: %s", - krb_get_err_text(kerror)); - return(0); + + kerror = 255; + for (service = krb4_services; *service; service++) { + kerror = krb_rd_req(&ticket, *service, instance, + his_addr.sin_addr.s_addr, + &kdata, keyfile); + /* Success */ + if(!kerror) break; + } + /* rd_req failed.... */ + if(kerror) { + secure_error("ADAT: Kerberos V4 krb_rd_req: %s", + krb_get_err_text(kerror)); + return(0); } + /* add one to the (formerly) sealed checksum, and re-seal it */ cksum = kdata.checksum + 1; cksum = htonl(cksum); @@ -2225,6 +2314,10 @@ char *data; secure_error("ADAT: krb_mk_safe failed"); return(0); } + if (length >= (FTP_BUFSIZ - sizeof("ADAT=")) / 4 * 3) { + secure_error("ADAT: reply too long"); + return(0); + } if (kerror = radix_encode(out_buf, buf, &length, 0)) { secure_error("Couldn't encode ADAT reply (%s)", radix_error(kerror)); @@ -2287,7 +2380,8 @@ char *data; syslog(LOG_ERR, "Couldn't canonicalize local hostname"); return 0; } - strcpy(localname, hp->h_name); + strncpy(localname, hp->h_name, sizeof(localname) - 1); + localname[sizeof(localname) - 1] = '\0'; for (service = gss_services; *service; service++) { sprintf(service_name, "%s@%s", *service, localname); @@ -2358,6 +2452,16 @@ char *data; } if (out_tok.length) { + if (out_tok.length >= ((FTP_BUFSIZ - sizeof("ADAT=")) + / 4 * 3)) { + secure_error("ADAT: reply too long"); + syslog(LOG_ERR, "ADAT: reply too long"); + (void) gss_release_cred(&stat_min, &server_creds); + if (ret_flags & GSS_C_DELEG_FLAG) + (void) gss_release_cred(&stat_min, + &deleg_creds); + return(0); + } if (kerror = radix_encode(out_tok.value, gbuf, &out_tok.length, 0)) { secure_error("Couldn't encode ADAT reply (%s)", radix_error(kerror)); @@ -2456,6 +2560,9 @@ static char *onefile[] = { * n>=0 on success * -1 on error * -2 on security error + * + * XXX callers need to limit total length of output string to + * FTP_BUFSIZ */ #ifdef STDARG secure_fprintf(FILE *stream, char *fmt, ...) @@ -2573,6 +2680,15 @@ send_file_list(whichfiles) dir->d_name[2] == '\0') continue; + if (strlen(dirname) + strlen(dir->d_name) + + 1 /* slash */ + + 2 /* CRLF */ + + 1 > sizeof(nbuf)) { + syslog(LOG_ERR, + "send_file_list: pathname too long"); + ret = -2; /* XXX */ + goto data_err; + } sprintf(nbuf, "%s/%s", dirname, dir->d_name); /* diff --git a/src/appl/sample/sclient/ChangeLog b/src/appl/sample/sclient/ChangeLog index 7603506..7e9c4f4 100644 --- a/src/appl/sample/sclient/ChangeLog +++ b/src/appl/sample/sclient/ChangeLog @@ -1,3 +1,9 @@ +2001-01-30 Ezra Peisach + + * sclient.c (main): Do not free auth_context unless + set. (krb5-appl/895 from tim.mann@compaq.com) + + 2000-02-25 Ezra Peisach * sclient.c (main): Return type of main should by int, not void. diff --git a/src/appl/sample/sclient/sclient.c b/src/appl/sample/sclient/sclient.c index d2097b9..242092b 100644 --- a/src/appl/sample/sclient/sclient.c +++ b/src/appl/sample/sclient/sclient.c @@ -175,7 +175,7 @@ char *argv[]; krb5_free_principal(context, server); /* finished using it */ krb5_free_principal(context, client); krb5_cc_close(context, ccdef); - krb5_auth_con_free(context, auth_context); + if (auth_context) krb5_auth_con_free(context, auth_context); if (retval && retval != KRB5_SENDAUTH_REJECTED) { com_err(argv[0], retval, "while using sendauth"); diff --git a/src/appl/telnet/libtelnet/ChangeLog b/src/appl/telnet/libtelnet/ChangeLog index 67877b1..c4c8d42 100644 --- a/src/appl/telnet/libtelnet/ChangeLog +++ b/src/appl/telnet/libtelnet/ChangeLog @@ -1,3 +1,36 @@ +2002-03-29 Tom Yu + + * kerberos5.c, kerberos.c (Data): Don't overflow + buffer. [telnet/1073] [pullup and reindent from trunk] + +2001-02-21 Tom Yu + + * configure.in: Check for setenv, unsetenv, and getenv. Compile + setenv.c if at least of these is undefined. + + * setenv.c: Add conditionals for compilation of setenv, unsetenv, + and getenv such that they only get compiled if they don't already + exist. + +2000-05-11 Nalin Dahyabhai + + * gettytab.c (nchktc): Don't overflow tcname if tty type name is too + long + * kerberos.c (kerberos4_status): Make sure "UserNameRequested" is + always properly terminated. + * kerberos5.c (kerberos5_is): If bad principal name is too long to fit + in "errbuf", don't print it. + (kerberos5_status): Make sure "UserNameRequested" is always properly + terminated. + * spx.c (spx_status): Ditto. + +2000-04-28 Nalin Dahyabhai + + * kerberos5.c (kerberos5_is): Don't overflow buffer "errbuf". + * spx.c (spx_init, spx_send, spx_is): Don't overflow buffer + "targ_printable". + (spx_status): Don't overflow buffer "acl_file". + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/appl/telnet/libtelnet/configure.in b/src/appl/telnet/libtelnet/configure.in index 3bae866..9040a98 100644 --- a/src/appl/telnet/libtelnet/configure.in +++ b/src/appl/telnet/libtelnet/configure.in @@ -3,10 +3,14 @@ CONFIG_RULES AC_PROG_ARCHIVE AC_PROG_ARCHIVE_ADD AC_PROG_RANLIB -AC_REPLACE_FUNCS([strcasecmp strdup setenv setsid strerror strftime getopt herror parsetos]) -AC_CHECK_FUNCS(gettosbyname cgetent) +AC_REPLACE_FUNCS([strcasecmp strdup setsid strerror strftime getopt herror parsetos]) +AC_CHECK_FUNCS(setenv unsetenv getenv gettosbyname cgetent) AC_CHECK_HEADERS(stdlib.h string.h) LIBOBJS="$LIBOBJS getent.o" +if test $ac_cv_func_setenv = no || test $ac_cv_func_unsetenv = no \ + || test $ac_cv_func_getenv = no; then + LIBOBJS="$LIBOBJS setenv.o" +fi AC_CONST if test "$KRB4_LIB" = ''; then AC_MSG_RESULT(No Kerberos 4 authentication) diff --git a/src/appl/telnet/libtelnet/gettytab.c b/src/appl/telnet/libtelnet/gettytab.c index f6ffb7c..aaad43a 100644 --- a/src/appl/telnet/libtelnet/gettytab.c +++ b/src/appl/telnet/libtelnet/gettytab.c @@ -98,9 +98,10 @@ nchktc() /* p now points to beginning of last field */ if (p[0] != 't' || p[1] != 'c') return(1); - strcpy(tcname,p+3); + strncpy(tcname, p + 3, sizeof(tcname) - 1); + tcname[sizeof(tcname) - 1] = '\0'; q = tcname; - while (q && *q != ':') + while (*q && *q != ':') q++; *q = 0; if (++hopcount > MAXHOP) { diff --git a/src/appl/telnet/libtelnet/kerberos.c b/src/appl/telnet/libtelnet/kerberos.c index 734466e..0fda99b 100644 --- a/src/appl/telnet/libtelnet/kerberos.c +++ b/src/appl/telnet/libtelnet/kerberos.c @@ -141,6 +141,7 @@ Data(ap, type, d, c) { unsigned char *p = str_data + 4; unsigned char *cd = (unsigned char *)d; + size_t spaceleft = sizeof(str_data) - 4; if (c == -1) c = strlen((char *)cd); @@ -156,9 +157,16 @@ Data(ap, type, d, c) *p++ = ap->type; *p++ = ap->way; *p++ = type; + spaceleft -= 3; while (c-- > 0) { - if ((*p++ = *cd++) == IAC) - *p++ = IAC; + if ((*p++ = *cd++) == IAC) { + *p++ = IAC; + spaceleft--; + } + if ((--spaceleft < 4) && c) { + errno = ENOMEM; + return -1; + } } *p++ = IAC; *p++ = SE; @@ -602,7 +610,9 @@ kerberos4_status(ap, name, level) return(level); if (UserNameRequested && !kuserok(&adat, UserNameRequested)) { - strcpy(name, UserNameRequested); + /* the name buffer comes from telnetd/telnetd{-ktd}.c */ + strncpy(name, UserNameRequested, 255); + name[255] = '\0'; return(AUTH_VALID); } else return(AUTH_USER); diff --git a/src/appl/telnet/libtelnet/kerberos5.c b/src/appl/telnet/libtelnet/kerberos5.c index 6a62f36..18356a5 100644 --- a/src/appl/telnet/libtelnet/kerberos5.c +++ b/src/appl/telnet/libtelnet/kerberos5.c @@ -95,7 +95,7 @@ void kerberos5_forward(); #endif /* FORWARD */ -static unsigned char str_data[2048] = { IAC, SB, TELOPT_AUTHENTICATION, 0, +static unsigned char str_data[8192] = {IAC, SB, TELOPT_AUTHENTICATION, 0, AUTHTYPE_KERBEROS_V5, }; /*static unsigned char str_name[1024] = { IAC, SB, TELOPT_AUTHENTICATION, TELQUAL_NAME, };*/ @@ -136,6 +136,7 @@ Data(ap, type, d, c) { unsigned char *p = str_data + 4; unsigned char *cd = (unsigned char *)d; + size_t spaceleft = sizeof(str_data) - 4; if (c == -1) c = strlen((char *)cd); @@ -151,9 +152,16 @@ Data(ap, type, d, c) *p++ = ap->type; *p++ = ap->way; *p++ = type; + spaceleft -= 3; while (c-- > 0) { - if ((*p++ = *cd++) == IAC) - *p++ = IAC; + if ((*p++ = *cd++) == IAC) { + *p++ = IAC; + spaceleft--; + } + if ((--spaceleft < 4) && c) { + errno = ENOMEM; + return -1; + } } *p++ = IAC; *p++ = SE; @@ -423,7 +431,8 @@ kerberos5_is(ap, data, cnt) NULL, keytabid, NULL, &ticket); if (r) { (void) strcpy(errbuf, "krb5_rd_req failed: "); - (void) strcat(errbuf, error_message(r)); + errbuf[sizeof(errbuf) - 1] = '\0'; + (void) strncat(errbuf, error_message(r), sizeof(errbuf) - 1 - strlen(errbuf)); goto errout; } @@ -440,8 +449,12 @@ kerberos5_is(ap, data, cnt) princ[krb5_princ_component(telnet_context, ticket->server,0)->length] = '\0'; if (strcmp("host", princ)) { - (void) sprintf(errbuf, "incorrect service name: \"%s\" != \"%s\"", - princ, "host"); + if(strlen(princ) < sizeof(errbuf) - 39) { + (void) sprintf(errbuf, "incorrect service name: \"%s\" != \"host\"", + princ); + } else { + (void) sprintf(errbuf, "incorrect service name: principal != \"host\""); + } goto errout; } } else { @@ -455,7 +468,8 @@ kerberos5_is(ap, data, cnt) if (r) { (void) strcpy(errbuf, "krb5_auth_con_getauthenticator failed: "); - (void) strcat(errbuf, error_message(r)); + errbuf[sizeof(errbuf) - 1] = '\0'; + (void) strncat(errbuf, error_message(r), sizeof(errbuf) - 1 - strlen(errbuf)); goto errout; } if ((ap->way & AUTH_ENCRYPT_MASK) == AUTH_ENCRYPT_ON && @@ -476,7 +490,8 @@ kerberos5_is(ap, data, cnt) &key); if (r) { (void) strcpy(errbuf, "krb5_auth_con_getkey failed: "); - (void) strcat(errbuf, error_message(r)); + errbuf[sizeof(errbuf) - 1] = '\0'; + (void) strncat(errbuf, error_message(r), sizeof(errbuf) - 1 - strlen(errbuf)); goto errout; } r = krb5_verify_checksum(telnet_context, @@ -495,7 +510,8 @@ kerberos5_is(ap, data, cnt) if (r) { (void) strcpy(errbuf, "checksum verification failed: "); - (void) strcat(errbuf, error_message(r)); + errbuf[sizeof(errbuf) - 1] = '\0'; + (void) strncat(errbuf, error_message(r), sizeof(errbuf) - 1 - strlen(errbuf)); goto errout; } krb5_free_keyblock(telnet_context, key); @@ -506,7 +522,8 @@ kerberos5_is(ap, data, cnt) if ((r = krb5_mk_rep(telnet_context, auth_context, &outbuf))) { (void) strcpy(errbuf, "Make reply failed: "); - (void) strcat(errbuf, error_message(r)); + errbuf[sizeof(errbuf) - 1] = '\0'; + (void) strncat(errbuf, error_message(r), sizeof(errbuf) - 1 - strlen(errbuf)); goto errout; } @@ -560,7 +577,8 @@ kerberos5_is(ap, data, cnt) char errbuf[128]; (void) strcpy(errbuf, "Read forwarded creds failed: "); - (void) strcat(errbuf, error_message(r)); + errbuf[sizeof(errbuf) - 1] = '\0'; + (void) strncat(errbuf, error_message(r), sizeof(errbuf) - 1 - strlen(errbuf)); Data(ap, KRB_FORWARD_REJECT, errbuf, -1); if (auth_debug_mode) printf( @@ -586,7 +604,8 @@ kerberos5_is(ap, data, cnt) char eerrbuf[329]; strcpy(eerrbuf, "telnetd: "); - strcat(eerrbuf, errbuf); + eerrbuf[sizeof(eerrbuf) - 1] = '\0'; + strncat(eerrbuf, errbuf, sizeof(eerrbuf) - 1 - strlen(eerrbuf)); Data(ap, KRB_REJECT, eerrbuf, -1); } if (auth_debug_mode) @@ -706,7 +725,9 @@ kerberos5_status(ap, name, level) krb5_kuserok(telnet_context, ticket->enc_part2->client, UserNameRequested)) { - strcpy(name, UserNameRequested); + /* the name buffer comes from telnetd/telnetd{-ktd}.c */ + strncpy(name, UserNameRequested, 255); + name[255] = '\0'; return(AUTH_VALID); } else return(AUTH_USER); diff --git a/src/appl/telnet/libtelnet/setenv.c b/src/appl/telnet/libtelnet/setenv.c index 70695a3..bc4f22d 100644 --- a/src/appl/telnet/libtelnet/setenv.c +++ b/src/appl/telnet/libtelnet/setenv.c @@ -52,6 +52,7 @@ static char *__findenv __P((const char *, int *)); * Set the value of the environmental variable "name" to be * "value". If rewrite is set, replace any current value. */ +#ifndef HAVE_SETENV setenv(name, value, rewrite) register const char *name; register const char *value; @@ -102,11 +103,13 @@ setenv(name, value, rewrite) for (*c++ = '='; *c++ = *value++;); return (0); } +#endif /* * unsetenv(name) -- * Delete environmental variable "name". */ +#ifndef HAVE_UNSETENV void unsetenv(name) const char *name; @@ -120,11 +123,13 @@ unsetenv(name) if (!(*p = *(p + 1))) break; } +#endif /* * getenv -- * Returns ptr to value associated with name, if any, else NULL. */ +#ifndef HAVE_GETENV char * getenv(name) const char *name; @@ -133,6 +138,7 @@ getenv(name) return (__findenv(name, &offset)); } +#endif /* * __findenv -- diff --git a/src/appl/telnet/libtelnet/spx.c b/src/appl/telnet/libtelnet/spx.c index f23490f..7285d0d 100644 --- a/src/appl/telnet/libtelnet/spx.c +++ b/src/appl/telnet/libtelnet/spx.c @@ -173,7 +173,8 @@ spx_init(ap, server) str_data[3] = TELQUAL_REPLY; gethostname(lhostname, sizeof(lhostname)); strcpy(targ_printable, "SERVICE:rcmd@"); - strcat(targ_printable, lhostname); + strncat(targ_printable, lhostname, sizeof(targ_printable) - 1 - 13); + targ_printable[sizeof(targ_printable) - 1] = '\0'; input_name_buffer.length = strlen(targ_printable); input_name_buffer.value = targ_printable; major_status = gss_import_name(&status, @@ -216,7 +217,8 @@ spx_send(ap) printf("[ Trying SPX ... ]\n"); strcpy(targ_printable, "SERVICE:rcmd@"); - strcat(targ_printable, RemoteHostName); + strncat(targ_printable, RemoteHostName, sizeof(targ_printable) - 1 - 13); + targ_printable[sizeof(targ_printable) - 1] = '\0'; input_name_buffer.length = strlen(targ_printable); input_name_buffer.value = targ_printable; @@ -324,7 +326,8 @@ spx_is(ap, data, cnt) gethostname(lhostname, sizeof(lhostname)); strcpy(targ_printable, "SERVICE:rcmd@"); - strcat(targ_printable, lhostname); + strncat(targ_printable, lhostname, sizeof(targ_printable) - 1 - 13); + targ_printable[sizeof(targ_printable) - 1] = '\0'; input_name_buffer.length = strlen(targ_printable); input_name_buffer.value = targ_printable; @@ -479,7 +482,7 @@ spx_status(ap, name, level) gss_buffer_desc fullname_buffer, acl_file_buffer; gss_OID fullname_type; - char acl_file[160], fullname[160]; + char acl_file[MAXPATHLEN], fullname[160]; int major_status, status = 0; struct passwd *pwd; @@ -494,8 +497,9 @@ spx_status(ap, name, level) return(AUTH_USER); /* not authenticated */ } - strcpy(acl_file, pwd->pw_dir); - strcat(acl_file, "/.sphinx"); + acl_file[sizeof(acl_file) - 1] = '\0'; + strncpy(acl_file, pwd->pw_dir, sizeof(acl_file) - 1); + strncat(acl_file, "/.sphinx", sizeof(acl_file) - 1 - strlen(acl_file)); acl_file_buffer.value = acl_file; acl_file_buffer.length = strlen(acl_file); @@ -511,7 +515,9 @@ spx_status(ap, name, level) &acl_file_buffer); if (major_status == GSS_S_COMPLETE) { - strcpy(name, UserNameRequested); + /* the name buffer comes from telnetd/telnetd{-ktd}.c */ + strncpy(name, UserNameRequested, 255); + name[255] = '\0'; return(AUTH_VALID); } else { return(AUTH_USER); diff --git a/src/appl/telnet/telnet/ChangeLog b/src/appl/telnet/telnet/ChangeLog index e3cfb63..fb7cc9394 100644 --- a/src/appl/telnet/telnet/ChangeLog +++ b/src/appl/telnet/telnet/ChangeLog @@ -1,3 +1,18 @@ +2000-05-11 Nalin Dahyabhai + + * commands.c (makeargv): Don't overflow buffer "saveline". + (tn): Don't overflow buffer "_hostname". + (cmdrc): Don't overflow buffer "m1save". + * externs.h: Include the size of "tline", so that we can check for + overflows elsewhere. + * main.c(main, tn370): Don't overflow buffer "tline". + * utilities.c (SetNetTrace): Don't overflow buffer "NetTraceFile". + +2000-04-28 Nalin Dahyabhai + + * commands.c (cmdrc): Don't overflow buffer "rcbuf". + * tn3270.c (settranscom): Don't overflow buffer "transcom". + 2000-02-24 Ezra Peisach * configure.in: Remove dependency on libdes425 when krb4 support diff --git a/src/appl/telnet/telnet/commands.c b/src/appl/telnet/telnet/commands.c index 2c80b0b..8ffba2e 100644 --- a/src/appl/telnet/telnet/commands.c +++ b/src/appl/telnet/telnet/commands.c @@ -138,7 +138,9 @@ makeargv() margc = 0; cp = line; if (*cp == '!') { /* Special case shell escape */ - strcpy(saveline, line); /* save for shell command */ + strncpy(saveline, line, sizeof(saveline) - 1); + /* save for shell command */ + saveline[sizeof(saveline) - 1] = '\0'; *argp++ = "!"; /* No room in string to get this */ margc++; cp++; @@ -2450,7 +2452,8 @@ tn(argc, argv) if (temp & 0xffffffff != INADDR_NONE) { sin.sin_addr.s_addr = temp; sin.sin_family = AF_INET; - (void) strcpy(_hostname, hostp); + (void) strncpy(_hostname, hostp, sizeof(_hostname) - 1); + _hostname[sizeof(_hostname) - 1] = '\0'; hostname = _hostname; } else { host = gethostbyname(hostp); @@ -2855,16 +2858,18 @@ cmdrc(m1, m2) if (skiprc) return; - strcpy(m1save, m1); + strncpy(m1save, m1, sizeof(m1save) - 1); + m1save[sizeof(m1save) - 1] = '\0'; m1 = m1save; if (rcname == 0) { rcname = getenv("HOME"); if (rcname) - strcpy(rcbuf, rcname); + strncpy(rcbuf, rcname, sizeof(rcbuf) - 1); else rcbuf[0] = '\0'; - strcat(rcbuf, "/.telnetrc"); + rcbuf[sizeof(rcbuf) - 1] = '\0'; + strncat(rcbuf, "/.telnetrc", sizeof(rcbuf) - 1 - strlen(rcbuf)); rcname = rcbuf; } diff --git a/src/appl/telnet/telnet/externs.h b/src/appl/telnet/telnet/externs.h index e993986..f35cded 100644 --- a/src/appl/telnet/telnet/externs.h +++ b/src/appl/telnet/telnet/externs.h @@ -486,7 +486,7 @@ extern char *Ibackp, /* Oldest byte of 3270 data */ Ibuf[], /* 3270 buffer */ *Ifrontp, /* Where next 3270 byte goes */ - tline[], + tline[200], *transcom; /* Transparent command */ extern int diff --git a/src/appl/telnet/telnet/main.c b/src/appl/telnet/telnet/main.c index da98ae6..7696857 100644 --- a/src/appl/telnet/telnet/main.c +++ b/src/appl/telnet/telnet/main.c @@ -274,7 +274,8 @@ main(argc, argv) case 't': #if defined(TN3270) && defined(unix) transcom = tline; - (void)strcpy(transcom, optarg); + (void)strncpy(transcom, optarg, sizeof(tline) - 1); + tline[sizeof(tline) - 1] = '\0'; #else fprintf(stderr, "%s: Warning: -t ignored, no TN3270 support.\n", diff --git a/src/appl/telnet/telnet/tn3270.c b/src/appl/telnet/telnet/tn3270.c index 77aedaf..c46ae7e 100644 --- a/src/appl/telnet/telnet/tn3270.c +++ b/src/appl/telnet/telnet/tn3270.c @@ -397,10 +397,11 @@ settranscom(argc, argv) return 1; } transcom = tline; - (void) strcpy(transcom, argv[1]); + (void) strncpy(transcom, argv[1], sizeof(tline) - 1); + tline[sizeof(tline) - 1] = '\0'; for (i = 2; i < argc; ++i) { - (void) strcat(transcom, " "); - (void) strcat(transcom, argv[i]); + (void) strncat(transcom, " ", sizeof(tline) - 1 - (transcom - tline)); + (void) strncat(transcom, argv[i], sizeof(tline) - 1 - (transcom - tline)); } return 1; } diff --git a/src/appl/telnet/telnet/utilities.c b/src/appl/telnet/telnet/utilities.c index 19f503b..82ad841 100644 --- a/src/appl/telnet/telnet/utilities.c +++ b/src/appl/telnet/telnet/utilities.c @@ -113,13 +113,15 @@ SetNetTrace(file) if (file && (strcmp(file, "-") != 0)) { NetTrace = fopen(file, "w"); if (NetTrace) { - strcpy((char *)NetTraceFile, file); + strncpy((char *)NetTraceFile, file, sizeof(NetTraceFile) - 1); + NetTraceFile[sizeof(NetTraceFile) - 1] = '\0'; return; } fprintf(stderr, "Cannot open %s.\n", file); } NetTrace = stdout; - strcpy((char *)NetTraceFile, "(standard output)"); + strncpy((char *)NetTraceFile, "(standard output)", sizeof(NetTraceFile) - 1); + NetTraceFile[sizeof(NetTraceFile) - 1] = '\0'; } void diff --git a/src/appl/telnet/telnetd/ChangeLog b/src/appl/telnet/telnetd/ChangeLog index 040a9af..5ab914a 100644 --- a/src/appl/telnet/telnetd/ChangeLog +++ b/src/appl/telnet/telnetd/ChangeLog @@ -1,3 +1,70 @@ +2002-01-18 Tom Yu + + * ext.h: Make stdarg prototypes unconditional, to avoid annoying + mostly-ANSI compilers that don't define __STDC__. + +2001-10-15 Ken Raeburn + + * telnetd.c (valid_opts): Note that 'w' takes a parameter. + +2001-08-02 Tom Yu + + * authenc.c (net_write): Rewrite in terms of netwrite(). + + * configure.in: Check for vsnprintf(). + + * ext.h: New prototypes for netprintf, netprintf_urg, + netprintf_noflush, netwrite, netputs. + + * slc.c: Fix to use new NETOBUF-handling functions. + + * state.c: Fix to use new NETOBUF-handling functions. + + * telnetd.c: Fix to use new NETOBUF-handling functions. + + * termstat.c: Fix to use new NETOBUF-handling functions. + + * utility.c: General rework to be more paranoid about + bounds-checking of NETOBUF and NFRONTP. Abstract away + interactions with NETOBUF to eliminate explicit references to + NFRONTP in many places. + (netwrite): New function; copies a buffer to the + NETOBUF "ring buffer", checking bounds and calling netflush() if + needed. + (netputs): New function; calls netwrite() with a nul-terminated + string. + (netprintf, netprintf_ext): New function; wrap sprintf() with + bounds checking for use with NETOBUF. + (netprintf_urg): New function; like netprintf() except sets neturg + to point at last char written. + (netprintf_noflush): New function; like netprintf() except + silently fails if NETOBUF is full. + (ttloop, printoption, printsub, printdata): Fix to use new + NETOBUF-handling functions. + +2001-01-25 Tom Yu + + * state.c (envvarok): Disallow LC_* and NLSPATH. + +2000-06-19 Tom Yu + + * telnetd.c (doit): Change test for "no authentication" as per + Jeffrey Altman's patch. + +2000-05-11 Nalin Dahyabhai + + * sys_term.c (start_login, Solaris): forcefully terminate "termbuf" + in case the "TERM" environment variable isn't. + * telnet-ktd.c (getterminaltype): Don't overflow buffers "first" and + "netobuf". + (recv_ayt): Forcibly terminate buffer "netobuf". + +2000-03-20 Ken Raeburn + Jeffrey Altman + + * state.c (telrcv): Fix off-by-one error dealing with full + buffer. + 2000-02-24 Ezra Peisach * configure.in: Remove dependency on libdes425 when krb4 support diff --git a/src/appl/telnet/telnetd/authenc.c b/src/appl/telnet/telnetd/authenc.c index 5736698..4488954 100644 --- a/src/appl/telnet/telnetd/authenc.c +++ b/src/appl/telnet/telnetd/authenc.c @@ -37,20 +37,17 @@ #include "telnetd.h" #include - int +int net_write(str, len) unsigned char *str; int len; { - if (nfrontp + len < netobuf + BUFSIZ) { - memcpy((void *)nfrontp, (void *)str, len); - nfrontp += len; - return(len); - } - return(0); + if (len < 0) + return 0; + return netwrite(str, len); } - void +void net_encrypt() { #ifdef ENCRYPTION @@ -87,7 +84,3 @@ telnet_gets(prompt, result, length, echo) return((char *)0); } #endif /* defined(AUTHENTICATION) || defined(ENCRYPTION) */ - - - - diff --git a/src/appl/telnet/telnetd/configure.in b/src/appl/telnet/telnetd/configure.in index e11b270..2dc6099 100644 --- a/src/appl/telnet/telnetd/configure.in +++ b/src/appl/telnet/telnetd/configure.in @@ -23,7 +23,7 @@ fi fi AC_HEADER_TIME AC_CHECK_HEADERS(string.h arpa/nameser.h utmp.h sys/time.h sys/tty.h sac.h sys/ptyvar.h sys/filio.h sys/stream.h sys/utsname.h) -AC_CHECK_FUNCS(gettosbyname) +AC_CHECK_FUNCS(gettosbyname vsnprintf) dnl Make our operating system-specific security checks and definitions for dnl login. dnl diff --git a/src/appl/telnet/telnetd/ext.h b/src/appl/telnet/telnetd/ext.h index 2ff53e3..dc9fe5a 100644 --- a/src/appl/telnet/telnetd/ext.h +++ b/src/appl/telnet/telnetd/ext.h @@ -187,8 +187,13 @@ extern void tty_setsofttab P((int)), tty_tspeed P((int)), willoption P((int)), - wontoption P((int)), - writenet P((unsigned char *, int)); + wontoption P((int)); + +extern void netprintf(const char *, ...); +extern void netprintf_urg(const char *fmt, ...); +extern void netprintf_noflush(const char *fmt, ...); +extern int netwrite(const char *, size_t); +extern void netputs(const char *); #ifdef ENCRYPTION extern char *nclearto; diff --git a/src/appl/telnet/telnetd/slc.c b/src/appl/telnet/telnetd/slc.c index 1c68b95..613674b 100644 --- a/src/appl/telnet/telnetd/slc.c +++ b/src/appl/telnet/telnetd/slc.c @@ -198,7 +198,7 @@ end_slc(bufp) (void) sprintf((char *)slcptr, "%c%c", IAC, SE); slcptr += 2; len = slcptr - slcbuf; - writenet(slcbuf, len); + netwrite(slcbuf, len); netflush(); /* force it out immediately */ DIAG(TD_OPTIONS, printsub('>', slcbuf+2, len-2);); } diff --git a/src/appl/telnet/telnetd/state.c b/src/appl/telnet/telnetd/state.c index 0f3b161..d783ed6 100644 --- a/src/appl/telnet/telnetd/state.c +++ b/src/appl/telnet/telnetd/state.c @@ -86,7 +86,7 @@ static void sb_auth_complete() if (!auth_negotiated) { static char *error = "An environment option was sent before authentication negotiation completed.\r\nThis may create a security hazard. Connection dropped.\r\n"; - writenet(error, strlen(error)); + netputs(error); netflush(); exit(1); } @@ -102,7 +102,7 @@ telrcv() #endif while (ncc > 0) { - if ((&ptyobuf[BUFSIZ] - pfrontp) < 2) + if ((&ptyobuf[BUFSIZ] - pfrontp) < 1) break; c = *netip++ & 0377, ncc--; #ifdef ENCRYPTION @@ -209,9 +209,7 @@ gotiac: switch (c) { } netclear(); /* clear buffer back */ - *nfrontp++ = IAC; - *nfrontp++ = DM; - neturg = nfrontp-1; /* off by one XXX */ + netprintf_urg("%c%c", IAC, DM); DIAG(TD_OPTIONS, printoption("td: send IAC", DM)); break; @@ -381,9 +379,12 @@ gotiac: switch (c) { pfrontp = opfrontp; pfrontp += term_input(xptyobuf, pfrontp, n, BUFSIZ+NETSLOP, xbuf2, &oc, BUFSIZ); - for (cp = xbuf2; oc > 0; --oc) - if ((*nfrontp++ = *cp++) == IAC) - *nfrontp++ = IAC; + for (cp = xbuf2; oc > 0; --oc) { + if (*cp == IAC) + netprintf("%c%c", *cp++, IAC); + else + netprintf("%c", *cp++); + } } #endif /* defined(CRAY2) && defined(UNICOS5) */ } /* end of telrcv */ @@ -463,8 +464,7 @@ send_do(option, init) set_his_want_state_will(option); do_dont_resp[option]++; } - (void) sprintf(nfrontp, (char *)doopt, option); - nfrontp += sizeof (dont) - 2; + netprintf((char *)doopt, option); DIAG(TD_OPTIONS, printoption("td: send do", option)); } @@ -683,8 +683,7 @@ send_dont(option, init) set_his_want_state_wont(option); do_dont_resp[option]++; } - (void) sprintf(nfrontp, (char *)dont, option); - nfrontp += sizeof (doopt) - 2; + netprintf((char *)dont, option); DIAG(TD_OPTIONS, printoption("td: send dont", option)); } @@ -833,8 +832,7 @@ send_will(option, init) set_my_want_state_will(option); will_wont_resp[option]++; } - (void) sprintf(nfrontp, (char *)will, option); - nfrontp += sizeof (doopt) - 2; + netprintf((char *)will, option); DIAG(TD_OPTIONS, printoption("td: send will", option)); } @@ -993,8 +991,7 @@ send_wont(option, init) set_my_want_state_wont(option); will_wont_resp[option]++; } - (void) sprintf(nfrontp, (char *)wont, option); - nfrontp += sizeof (wont) - 2; + netprintf((char *)wont, option); DIAG(TD_OPTIONS, printoption("td: send wont", option)); } @@ -1393,10 +1390,8 @@ suboption() env_ovar_wrong: env_ovar = OLD_ENV_VALUE; env_ovalue = OLD_ENV_VAR; - DIAG(TD_OPTIONS, {sprintf(nfrontp, - "ENVIRON VALUE and VAR are reversed!\r\n"); - nfrontp += strlen(nfrontp);}); - + DIAG(TD_OPTIONS, + netputs("ENVIRON VALUE and VAR are reversed!\r\n")); } } SB_RESTORE(); @@ -1633,7 +1628,7 @@ send_status() ADD(IAC); ADD(SE); - writenet(statusbuf, ncp - statusbuf); + netwrite(statusbuf, ncp - statusbuf); netflush(); /* Send it on its way */ DIAG(TD_OPTIONS, @@ -1663,6 +1658,8 @@ static int envvarok(varp) strcmp(varp, "KRB_REALMS") && /* cns v4 */ strcmp(varp, "LIBPATH") && /* AIX */ strcmp(varp, "RESOLV_HOST_CONF") && /* linux */ + strcmp(varp, "NLSPATH") && /* locale stuff */ + strncmp(varp, "LC_", strlen("LC_")) && /* locale stuff */ strcmp(varp, "IFS")) { return 1; } else { diff --git a/src/appl/telnet/telnetd/sys_term.c b/src/appl/telnet/telnetd/sys_term.c index ee8d53d..b79209d 100644 --- a/src/appl/telnet/telnetd/sys_term.c +++ b/src/appl/telnet/telnetd/sys_term.c @@ -1257,6 +1257,7 @@ start_login(host, autologin, name) } else { strcpy(termbuf, "TERM="); strncat(termbuf, term, sizeof(termbuf) - 6); + termbuf[sizeof(termbuf) - 1] = '\0'; term = termbuf; } argv = addarg(argv, term); diff --git a/src/appl/telnet/telnetd/telnetd-ktd.c b/src/appl/telnet/telnetd/telnetd-ktd.c index 9ec608f..5936e3b 100644 --- a/src/appl/telnet/telnetd/telnetd-ktd.c +++ b/src/appl/telnet/telnetd/telnetd-ktd.c @@ -360,7 +360,7 @@ main(argc, argv) } (void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); - if (bind(s, (struct sockaddr *)&sin, sizeof sin) < 0) { + if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { perror("bind"); exit(1); } @@ -368,7 +368,7 @@ main(argc, argv) perror("listen"); exit(1); } - foo = sizeof sin; + foo = sizeof(sin); ns = accept(s, (struct sockaddr *)&sin, &foo); if (ns < 0) { perror("accept"); @@ -548,25 +548,33 @@ getterminaltype(name) if (his_state_is_will(TELOPT_TSPEED)) { static char sbbuf[] = { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE }; - memcpy(nfrontp, sbbuf, sizeof sbbuf); - nfrontp += sizeof sbbuf; + if(nfrontp - netobuf + sizeof(sbbuf) < sizeof(netobuf)) { + memcpy(nfrontp, sbbuf, sizeof(sbbuf)); + nfrontp += sizeof(sbbuf); + } } if (his_state_is_will(TELOPT_XDISPLOC)) { static char sbbuf[] = { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE }; - memcpy(nfrontp, sbbuf, sizeof sbbuf); - nfrontp += sizeof sbbuf; + if(nfrontp - netobuf + sizeof(sbbuf) < sizeof(netobuf)) { + memcpy(nfrontp, sbbuf, sizeof(sbbuf)); + nfrontp += sizeof(sbbuf); + } } if (his_state_is_will(TELOPT_ENVIRON)) { static char sbbuf[] = { IAC, SB, TELOPT_ENVIRON, TELQUAL_SEND, IAC, SE }; - memcpy(nfrontp, sbbuf, sizeof sbbuf); - nfrontp += sizeof sbbuf; + if(nfrontp - netobuf + sizeof(sbbuf) < sizeof(netobuf)) { + memcpy(nfrontp, sbbuf, sizeof(sbbuf)); + nfrontp += sizeof(sbbuf); + } } if (his_state_is_will(TELOPT_TTYPE)) { - memcpy(nfrontp, ttytype_sbbuf, sizeof ttytype_sbbuf); - nfrontp += sizeof ttytype_sbbuf; + if(nfrontp - netobuf + sizeof(ttytype_sbbuf) < sizeof(netobuf)) { + memcpy(nfrontp, ttytype_sbbuf, sizeof(ttytype_sbbuf)); + nfrontp += sizeof(ttytype_sbbuf); + } } if (his_state_is_will(TELOPT_TSPEED)) { while (sequenceIs(tspeedsubopt, baseline)) @@ -591,12 +599,14 @@ getterminaltype(name) * we have to just go with what we (might) have already gotten. */ if (his_state_is_will(TELOPT_TTYPE) && !terminaltypeok(terminaltype)) { - (void) strncpy(first, terminaltype, sizeof(first)); + (void) strncpy(first, terminaltype, sizeof(first) - 1); + first[sizeof(first) - 1] = '\0'; for(;;) { /* * Save the unknown name, and request the next name. */ - (void) strncpy(last, terminaltype, sizeof(last)); + (void) strncpy(last, terminaltype, sizeof(last) - 1); + last[sizeof(last) - 1] = '\0'; _gettermname(); if (terminaltypeok(terminaltype)) break; @@ -615,7 +625,8 @@ getterminaltype(name) */ _gettermname(); if (strncmp(first, terminaltype, sizeof(first)) != 0) - (void) strncpy(terminaltype, first, sizeof(first)); + (void) strncpy(terminaltype, first, sizeof(terminaltype) - 1); + terminaltype[sizeof(terminaltype) - 1] = '\0'; break; } } @@ -635,8 +646,8 @@ _gettermname() if (his_state_is_wont(TELOPT_TTYPE)) return; settimer(baseline); - memcpy(nfrontp, ttytype_sbbuf, sizeof ttytype_sbbuf); - nfrontp += sizeof ttytype_sbbuf; + memcpy(nfrontp, ttytype_sbbuf, sizeof(ttytype_sbbuf)); + nfrontp += sizeof(ttytype_sbbuf); while (sequenceIs(ttypesubopt, baseline)) ttloop(); } @@ -922,7 +933,7 @@ telnet(f, p, host) #if defined(SO_OOBINLINE) (void) setsockopt(net, SOL_SOCKET, SO_OOBINLINE, - (char *)&on, sizeof on); + (char *)&on, sizeof(on)); #endif /* defined(SO_OOBINLINE) */ #ifdef SIGTSTP @@ -989,8 +1000,10 @@ telnet(f, p, host) HE = getstr("he", &cp); HN = getstr("hn", &cp); IM = getstr("im", &cp); - if (HN && *HN) - (void) strcpy(host_name, HN); + if (HN && *HN) { + (void) strncpy(host_name, HN, sizeof(host_name) - 1); + host_name[sizeof(host_name) - 1] = '\0'; + } if (IM == 0) IM = ""; } else { @@ -1426,8 +1439,10 @@ recv_ayt() return; } #endif - (void) strcpy(nfrontp, "\r\n[Yes]\r\n"); + (void) strncpy(nfrontp, "\r\n[Yes]\r\n", + sizeof(netobuf) - 1 - (nfrontp - netobuf)); nfrontp += 9; + *nfrontp = '\0'; } void diff --git a/src/appl/telnet/telnetd/telnetd.c b/src/appl/telnet/telnetd/telnetd.c index 7267469..5588d1a 100644 --- a/src/appl/telnet/telnetd/telnetd.c +++ b/src/appl/telnet/telnetd/telnetd.c @@ -153,7 +153,7 @@ extern void usage P((void)); */ char valid_opts[] = { 'd', ':', 'h', 'k', 'L', ':', 'n', 'S', ':', 'U', - 'w', + 'w', ':', #ifdef AUTHENTICATION 'a', ':', 'X', ':', #endif @@ -522,7 +522,7 @@ main(argc, argv) } (void) setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); - if (bind(s, (struct sockaddr *)&sin, sizeof sin) < 0) { + if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { perror("bind"); exit(1); } @@ -530,7 +530,7 @@ main(argc, argv) perror("listen"); exit(1); } - foo = sizeof sin; + foo = sizeof(sin); ns = accept(s, (struct sockaddr *)&sin, &foo); if (ns < 0) { perror("accept"); @@ -693,7 +693,7 @@ static void encrypt_failure() char *error_message = "Encryption was not successfully negotiated. Goodbye.\r\n\r\n"; - writenet(error_message, strlen(error_message)); + netputs(error_message); netflush(); exit(1); } @@ -780,36 +780,26 @@ getterminaltype(name) if (his_state_is_will(TELOPT_TSPEED)) { static unsigned char sb[] = { IAC, SB, TELOPT_TSPEED, TELQUAL_SEND, IAC, SE }; - - memcpy(nfrontp, sb, sizeof sb); - nfrontp += sizeof sb; + netwrite(sb, sizeof(sb)); } if (his_state_is_will(TELOPT_XDISPLOC)) { static unsigned char sb[] = { IAC, SB, TELOPT_XDISPLOC, TELQUAL_SEND, IAC, SE }; - - memcpy(nfrontp, sb, sizeof sb); - nfrontp += sizeof sb; + netwrite(sb, sizeof(sb)); } if (his_state_is_will(TELOPT_NEW_ENVIRON)) { static unsigned char sb[] = { IAC, SB, TELOPT_NEW_ENVIRON, TELQUAL_SEND, IAC, SE }; - - memcpy(nfrontp, sb, sizeof sb); - nfrontp += sizeof sb; + netwrite(sb, sizeof(sb)); } else if (his_state_is_will(TELOPT_OLD_ENVIRON)) { static unsigned char sb[] = { IAC, SB, TELOPT_OLD_ENVIRON, TELQUAL_SEND, IAC, SE }; - - memcpy(nfrontp, sb, sizeof sb); - nfrontp += sizeof sb; + netwrite(sb, sizeof(sb)); } - if (his_state_is_will(TELOPT_TTYPE)) { + if (his_state_is_will(TELOPT_TTYPE)) + netwrite(ttytype_sbbuf, sizeof(ttytype_sbbuf)); - memcpy(nfrontp, ttytype_sbbuf, sizeof ttytype_sbbuf); - nfrontp += sizeof ttytype_sbbuf; - } if (his_state_is_will(TELOPT_TSPEED)) { while (sequenceIs(tspeedsubopt, baseline)) ttloop(); @@ -886,8 +876,7 @@ _gettermname() if (his_state_is_wont(TELOPT_TTYPE)) return; settimer(baseline); - memcpy(nfrontp, ttytype_sbbuf, sizeof ttytype_sbbuf); - nfrontp += sizeof ttytype_sbbuf; + netwrite(ttytype_sbbuf, sizeof(ttytype_sbbuf)); while (sequenceIs(ttypesubopt, baseline)) ttloop(); } @@ -1009,7 +998,7 @@ pty_init(); setenv("TERM", *terminaltype ? terminaltype : "network", 1); #if defined (AUTHENTICATION) - if (user_name[0] == '\0') { + if (level < 0 && auth_level > 0) { fatal (net, "No authentication provided"); exit (-1); } @@ -1159,9 +1148,7 @@ telnet(f, p, host) * mode, which we do not want. */ if (his_want_state_is_will(TELOPT_ECHO)) { - DIAG(TD_OPTIONS, - {sprintf(nfrontp, "td: simulating recv\r\n"); - nfrontp += strlen(nfrontp);}); + DIAG(TD_OPTIONS, netputs("td: simulating recv\r\n")); willoption(TELOPT_ECHO); } @@ -1205,7 +1192,7 @@ telnet(f, p, host) #if defined(SO_OOBINLINE) (void) setsockopt(net, SOL_SOCKET, SO_OOBINLINE, - (char *)&on, sizeof on); + (char *)&on, sizeof(on)); #endif /* defined(SO_OOBINLINE) */ #ifdef SIGTSTP @@ -1266,7 +1253,8 @@ telnet(f, p, host) HN = getstr("hn", &cp); IM = getstr("im", &cp); if (HN && *HN) - (void) strcpy(host_name, HN); + (void) strncpy(host_name, HN, sizeof(host_name) - 1); + host_name[sizeof(host_name) - 1] = '\0'; if (IM == 0) IM = ""; } else { @@ -1289,9 +1277,7 @@ telnet(f, p, host) localstat(); #endif /* LINEMODE */ - DIAG(TD_REPORT, - {sprintf(nfrontp, "td: Entering processing loop\r\n"); - nfrontp += strlen(nfrontp);}); + DIAG(TD_REPORT, netputs("td: Entering processing loop\r\n")); #ifdef convex startslave(host); @@ -1416,8 +1402,7 @@ telnet(f, p, host) netip = netibuf; } DIAG((TD_REPORT | TD_NETDATA), - {sprintf(nfrontp, "td: netread %d chars\r\n", ncc); - nfrontp += strlen(nfrontp);}); + netprintf("td: netread %d chars\r\n", ncc)); DIAG(TD_NETDATA, printdata("nd", netip, ncc)); } @@ -1464,9 +1449,7 @@ telnet(f, p, host) * royally if we send them urgent * mode data. */ - *nfrontp++ = IAC; - *nfrontp++ = DM; - neturg = nfrontp-1; /* off by one XXX */ + netprintf_urg("%c%c", IAC, DM); #endif } if (his_state_is_will(TELOPT_LFLOW) && @@ -1476,13 +1459,11 @@ telnet(f, p, host) ptyibuf[0] & TIOCPKT_DOSTOP ? 1 : 0; if (newflow != flowmode) { flowmode = newflow; - (void) sprintf(nfrontp, - "%c%c%c%c%c%c", + netprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, flowmode ? LFLOW_ON : LFLOW_OFF, IAC, SE); - nfrontp += 6; } } pcc--; @@ -1505,19 +1486,19 @@ telnet(f, p, host) break; c = *ptyip++ & 0377, pcc--; if (c == IAC) - *nfrontp++ = c; + netprintf("%c", c); #if defined(CRAY2) && defined(UNICOS5) else if (c == '\n' && my_state_is_wont(TELOPT_BINARY) && newmap) - *nfrontp++ = '\r'; + netputs("\r"); #endif /* defined(CRAY2) && defined(UNICOS5) */ - *nfrontp++ = c; + netprintf("%c", c); if ((c == '\r') && (my_state_is_wont(TELOPT_BINARY))) { if (pcc > 0 && ((*ptyip & 0377) == '\n')) { - *nfrontp++ = *ptyip++ & 0377; + netprintf("%c", *ptyip++ & 0377); pcc--; } else - *nfrontp++ = '\0'; + netprintf("%c", '\0'); } } #if defined(CRAY2) && defined(UNICOS5) @@ -1679,7 +1660,7 @@ sendsusp() * When we get an AYT, if ^T is enabled, use that. Otherwise, * just send back "[Yes]". */ - void +void recv_ayt() { #if defined(SIGINFO) && defined(TCSIG) @@ -1688,8 +1669,7 @@ recv_ayt() return; } #endif - (void) strcpy(nfrontp, "\r\n[Yes]\r\n"); - nfrontp += 9; + netputs("\r\n[Yes]\r\n"); } void diff --git a/src/appl/telnet/telnetd/termstat.c b/src/appl/telnet/telnetd/termstat.c index 824a1a6..531e167 100644 --- a/src/appl/telnet/telnetd/termstat.c +++ b/src/appl/telnet/telnetd/termstat.c @@ -283,10 +283,9 @@ localstat() # endif /* KLUDGELINEMODE */ send_do(TELOPT_LINEMODE, 1); /* send along edit modes */ - (void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB, + netprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode, IAC, SE); - nfrontp += 7; editmode = useeditmode; # ifdef KLUDGELINEMODE } @@ -312,10 +311,9 @@ localstat() /* * Send along appropriate edit mode mask. */ - (void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, SB, + (void) netprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode, IAC, SE); - nfrontp += 7; editmode = useeditmode; } @@ -359,20 +357,18 @@ flowstat() if (his_state_is_will(TELOPT_LFLOW)) { if (tty_flowmode() != flowmode) { flowmode = tty_flowmode(); - (void) sprintf(nfrontp, "%c%c%c%c%c%c", + netprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, flowmode ? LFLOW_ON : LFLOW_OFF, IAC, SE); - nfrontp += 6; } if (tty_restartany() != restartany) { restartany = tty_restartany(); - (void) sprintf(nfrontp, "%c%c%c%c%c%c", + netprintf("%c%c%c%c%c%c", IAC, SB, TELOPT_LFLOW, restartany ? LFLOW_RESTART_ANY : LFLOW_RESTART_XON, IAC, SE); - nfrontp += 6; } } } @@ -445,10 +441,9 @@ clientstat(code, parm1, parm2) useeditmode |= MODE_SOFT_TAB; if (tty_islitecho()) useeditmode |= MODE_LIT_ECHO; - (void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, + netprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, - useeditmode, IAC, SE); - nfrontp += 7; + useeditmode, IAC, SE); editmode = useeditmode; } @@ -504,11 +499,10 @@ clientstat(code, parm1, parm2) set_termbuf(); if (!ack) { - (void) sprintf(nfrontp, "%c%c%c%c%c%c%c", IAC, + netprintf("%c%c%c%c%c%c%c", IAC, SB, TELOPT_LINEMODE, LM_MODE, useeditmode|MODE_ACK, IAC, SE); - nfrontp += 7; } editmode = useeditmode; diff --git a/src/appl/telnet/telnetd/utility.c b/src/appl/telnet/telnetd/utility.c index 408c6f4..93a932d 100644 --- a/src/appl/telnet/telnetd/utility.c +++ b/src/appl/telnet/telnetd/utility.c @@ -33,6 +33,7 @@ /* based on @(#)utility.c 8.1 (Berkeley) 6/4/93 */ +#include #define PRINTOPTIONS #include "telnetd.h" @@ -58,8 +59,7 @@ ttloop() { void netflush(); - DIAG(TD_REPORT, {sprintf(nfrontp, "td: ttloop\r\n"); - nfrontp += strlen(nfrontp);}); + DIAG(TD_REPORT, netputs("td: ttloop\r\n")); if (nfrontp-nbackp) { netflush(); } @@ -74,8 +74,7 @@ read_again: syslog(LOG_INFO, "ttloop: peer died: %m"); exit(1); } - DIAG(TD_REPORT, {sprintf(nfrontp, "td: ttloop read %d chars\r\n", ncc); - nfrontp += strlen(nfrontp);}); + DIAG(TD_REPORT, netprintf("td: ttloop read %d chars\r\n", ncc)); netip = netibuf; telrcv(); /* state machine */ if (ncc > 0) { @@ -118,8 +117,7 @@ ptyflush() if ((n = pfrontp - pbackp) > 0) { DIAG((TD_REPORT | TD_PTYDATA), - { sprintf(nfrontp, "td: ptyflush %d chars\r\n", n); - nfrontp += strlen(nfrontp); }); + netprintf("td: ptyflush %d chars\r\n", n)); DIAG(TD_PTYDATA, printdata("pd", pbackp, n)); n = write(pty, pbackp, n); } @@ -244,18 +242,15 @@ netclear() * Send as much data as possible to the network, * handling requests for urgent data. */ - void +void netflush() { int n; extern int not42; if ((n = nfrontp - nbackp) > 0) { - DIAG(TD_REPORT, - { sprintf(nfrontp, "td: netflush %d chars\r\n", n); - n += strlen(nfrontp); /* get count first */ - nfrontp += strlen(nfrontp); /* then move pointer */ - }); + DIAG(TD_REPORT, {netprintf_noflush("td: netflush %d chars\r\n", n); + n = nfrontp - nbackp;}); #ifdef ENCRYPTION if (encrypt_output) { char *s = nclearto ? nclearto : nbackp; @@ -312,33 +307,131 @@ netflush() return; } /* end of netflush */ +/* + * L8_256(x) = log8(256**x), rounded up, including sign (for decimal + * strings too). log8(256) = 8/3, but we use integer math to round + * up. + */ +#define L8_256(x) (((x * 8 + 2) / 3) + 1) /* - * writenet + * netprintf * - * Just a handy little function to write a bit of raw data to the net. - * It will force a transmit of the buffer if necessary + * Do the equivalent of printf() to the NETOBUF "ring buffer", + * possibly calling netflush() if needed. * - * arguments - * ptr - A pointer to a character string to write - * len - How many bytes to write + * Thou shalt not call this with a "%s" format; use netputs instead. + * We also don't deal with floating point widths in here. */ - void -writenet(ptr, len) - register unsigned char *ptr; - register int len; +void +netprintf_ext(int noflush, int seturg, const char *fmt, va_list args) { - /* flush buffer if no room for new data) */ - if ((&netobuf[BUFSIZ] - nfrontp) < len) { - /* if this fails, don't worry, buffer is a little big */ - netflush(); + size_t remain; + size_t maxoutlen; + char buf[BUFSIZ]; + const char *cp; + int len; + + buf[0] = '\0'; /* nul-terminate */ + remain = sizeof(netobuf) - (nfrontp - netobuf); + for (maxoutlen = 0, cp = fmt; *cp; cp++) { + if (*cp == '%') + /* Ok so this is slightly overkill... */ + maxoutlen += L8_256(sizeof(long)); + else + maxoutlen++; } + if (maxoutlen >= sizeof(buf)) + return; /* highly unlikely */ - memcpy(nfrontp, ptr, len); +#ifdef HAVE_VSNPRINTF + len = vsnprintf(buf, sizeof(buf), fmt, args); +#else + len = vsprintf(buf, fmt, args); /* XXX need to fix for SunOS? */ +#endif + + /* + * The return value from sprintf()-like functions may be the + * number of characters that *would* have been output, not the + * number actually output. + */ + if (len <= 0 || len > sizeof(buf)) + return; + if (remain < len && !noflush) { + netflush(); + remain = sizeof(netobuf) - (nfrontp - netobuf); + } + if (remain < len) + return; /* still not enough space? */ + memcpy(nfrontp, buf, (size_t)len); nfrontp += len; + if (seturg) + neturg = nfrontp - 1; +} + +void +netprintf(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + netprintf_ext(0, 0, fmt, args); + va_end(args); +} + +void +netprintf_urg(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + netprintf_ext(0, 1, fmt, args); + va_end(args); +} + +void +netprintf_noflush(const char *fmt, ...) +{ + va_list args; -} /* end of writenet */ + va_start(args, fmt); + netprintf_ext(1, 0, fmt, args); + va_end(args); +} + +/* + * netwrite + * + * Copy BUF into the NETOBUF "ring buffer", possibly calling + * netflush() if needed. + */ +int +netwrite(const char *buf, size_t len) +{ + size_t remain; + + remain = sizeof(netobuf) - (nfrontp - netobuf); + if (remain < len) { + netflush(); + remain = sizeof(netobuf) - (nfrontp - netobuf); + } + if (remain < len) + return 0; + memcpy(nfrontp, buf, len); + nfrontp += len; + return len; +} +/* + * netputs + * + * Write S to the NETOBUF "ring buffer". Does not write a '\n'. + */ +void +netputs(const char *s) +{ + netwrite(s, strlen(s)); +} /* * miscellaneous functions doing a variety of little jobs follow ... @@ -522,22 +615,26 @@ putf(cp, where) /* * Print telnet options and commands in plain text, if possible. */ - void +void printoption(fmt, option) register char *fmt; register int option; { - if (TELOPT_OK(option)) - sprintf(nfrontp, "%s %s\r\n", fmt, TELOPT(option)); - else if (TELCMD_OK(option)) - sprintf(nfrontp, "%s %s\r\n", fmt, TELCMD(option)); - else - sprintf(nfrontp, "%s %d\r\n", fmt, option); - nfrontp += strlen(nfrontp); + netputs(fmt); + netputs(" "); + if (TELOPT_OK(option)) { + netputs(TELOPT(option)); + netputs("\r\n"); + } else if (TELCMD_OK(option)) { + netputs(TELCMD(option)); + netputs("\r\n"); + } else { + netprintf("%d\r\n", option); + } return; } - void +void printsub(direction, pointer, length) char direction; /* '<' or '>' */ unsigned char *pointer; /* where suboption data sits */ @@ -550,9 +647,9 @@ printsub(direction, pointer, length) return; if (direction) { - sprintf(nfrontp, "td: %s suboption ", - direction == '<' ? "recv" : "send"); - nfrontp += strlen(nfrontp); + netputs("td: "); + netputs(direction == '<' ? "recv" : "send"); + netputs(" suboption "); if (length >= 3) { register int j; @@ -560,261 +657,223 @@ printsub(direction, pointer, length) j = pointer[length-1]; if (i != IAC || j != SE) { - sprintf(nfrontp, "(terminated by "); - nfrontp += strlen(nfrontp); + netputs("(terminated by "); if (TELOPT_OK(i)) - sprintf(nfrontp, "%s ", TELOPT(i)); + netputs(TELOPT(i)); else if (TELCMD_OK(i)) - sprintf(nfrontp, "%s ", TELCMD(i)); + netputs(TELCMD(i)); else - sprintf(nfrontp, "%d ", i); - nfrontp += strlen(nfrontp); + netprintf("%d", i); + netputs(" "); if (TELOPT_OK(j)) - sprintf(nfrontp, "%s", TELOPT(j)); + netputs(TELOPT(j)); else if (TELCMD_OK(j)) - sprintf(nfrontp, "%s", TELCMD(j)); + netputs(TELCMD(j)); else - sprintf(nfrontp, "%d", j); - nfrontp += strlen(nfrontp); - sprintf(nfrontp, ", not IAC SE!) "); - nfrontp += strlen(nfrontp); + netprintf("%d", j); + netputs(", not IAC SE!) "); } } length -= 2; } if (length < 1) { - sprintf(nfrontp, "(Empty suboption??\?)"); - nfrontp += strlen(nfrontp); + netputs("(Empty suboption??\?)"); return; } switch (pointer[0]) { case TELOPT_TTYPE: - sprintf(nfrontp, "TERMINAL-TYPE "); - nfrontp += strlen(nfrontp); + netputs("TERMINAL-TYPE "); switch (pointer[1]) { case TELQUAL_IS: - sprintf(nfrontp, "IS \"%.*s\"", length-2, (char *)pointer+2); + netputs("IS \""); + netwrite((char *)pointer + 2, (size_t)(length - 2)); + netputs("\""); break; case TELQUAL_SEND: - sprintf(nfrontp, "SEND"); + netputs("SEND"); break; default: - sprintf(nfrontp, - "- unknown qualifier %d (0x%x).", - pointer[1], pointer[1]); + netprintf("- unknown qualifier %d (0x%x).", + pointer[1], pointer[1]); } - nfrontp += strlen(nfrontp); break; case TELOPT_TSPEED: - sprintf(nfrontp, "TERMINAL-SPEED"); - nfrontp += strlen(nfrontp); + netputs("TERMINAL-SPEED "); if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + netputs("(empty suboption??\?)"); break; } switch (pointer[1]) { case TELQUAL_IS: - sprintf(nfrontp, " IS %.*s", length-2, (char *)pointer+2); - nfrontp += strlen(nfrontp); + netputs("IS "); + netwrite((char *)pointer + 2, (size_t)(length - 2)); break; default: if (pointer[1] == 1) - sprintf(nfrontp, " SEND"); + netputs("SEND"); else - sprintf(nfrontp, " %d (unknown)", pointer[1]); - nfrontp += strlen(nfrontp); - for (i = 2; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); - } + netprintf("%d (unknown)", pointer[1]); + for (i = 2; i < length; i++) + netprintf(" ?%d?", pointer[i]); break; } break; case TELOPT_LFLOW: - sprintf(nfrontp, "TOGGLE-FLOW-CONTROL"); - nfrontp += strlen(nfrontp); + netputs("TOGGLE-FLOW-CONTROL "); if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + netputs("(empty suboption??\?)"); break; } switch (pointer[1]) { case LFLOW_OFF: - sprintf(nfrontp, " OFF"); break; + netputs("OFF"); break; case LFLOW_ON: - sprintf(nfrontp, " ON"); break; + netputs("ON"); break; case LFLOW_RESTART_ANY: - sprintf(nfrontp, " RESTART-ANY"); break; + netputs("RESTART-ANY"); break; case LFLOW_RESTART_XON: - sprintf(nfrontp, " RESTART-XON"); break; + netputs("RESTART-XON"); break; default: - sprintf(nfrontp, " %d (unknown)", pointer[1]); - } - nfrontp += strlen(nfrontp); - for (i = 2; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); + netprintf("%d (unknown)", pointer[1]); } + for (i = 2; i < length; i++) + netprintf(" ?%d?", pointer[i]); break; case TELOPT_NAWS: - sprintf(nfrontp, "NAWS"); - nfrontp += strlen(nfrontp); + netputs("NAWS"); if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + netputs(" (empty suboption??\?)"); break; } if (length == 2) { - sprintf(nfrontp, " ?%d?", pointer[1]); - nfrontp += strlen(nfrontp); + netprintf(" ?%d?", pointer[1]); break; } - sprintf(nfrontp, " %d %d (%d)", + netprintf(" %d %d (%d)", pointer[1], pointer[2], (int)((((unsigned int)pointer[1])<<8)|((unsigned int)pointer[2]))); - nfrontp += strlen(nfrontp); if (length == 4) { - sprintf(nfrontp, " ?%d?", pointer[3]); - nfrontp += strlen(nfrontp); + netprintf(" ?%d?", pointer[3]); break; } - sprintf(nfrontp, " %d %d (%d)", + netprintf(" %d %d (%d)", pointer[3], pointer[4], (int)((((unsigned int)pointer[3])<<8)|((unsigned int)pointer[4]))); - nfrontp += strlen(nfrontp); - for (i = 5; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); - } + for (i = 5; i < length; i++) + netprintf(" ?%d?", pointer[i]); break; case TELOPT_LINEMODE: - sprintf(nfrontp, "LINEMODE "); - nfrontp += strlen(nfrontp); + netputs("LINEMODE "); if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + netputs("(empty suboption??\?)"); break; } switch (pointer[1]) { case WILL: - sprintf(nfrontp, "WILL "); + netputs("WILL "); goto common; case WONT: - sprintf(nfrontp, "WONT "); + netputs("WONT "); goto common; case DO: - sprintf(nfrontp, "DO "); + netputs("DO "); goto common; case DONT: - sprintf(nfrontp, "DONT "); + netputs("DONT "); common: - nfrontp += strlen(nfrontp); if (length < 3) { - sprintf(nfrontp, "(no option??\?)"); - nfrontp += strlen(nfrontp); + netputs("(no option??\?)"); break; } switch (pointer[2]) { case LM_FORWARDMASK: - sprintf(nfrontp, "Forward Mask"); - nfrontp += strlen(nfrontp); - for (i = 3; i < length; i++) { - sprintf(nfrontp, " %x", pointer[i]); - nfrontp += strlen(nfrontp); - } + netputs("Forward Mask"); + for (i = 3; i < length; i++) + netprintf(" %x", pointer[i]); break; default: - sprintf(nfrontp, "%d (unknown)", pointer[2]); - nfrontp += strlen(nfrontp); - for (i = 3; i < length; i++) { - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); - } + netprintf("%d (unknown)", pointer[2]); + for (i = 3; i < length; i++) + netprintf(" %d", pointer[i]); break; } break; case LM_SLC: - sprintf(nfrontp, "SLC"); - nfrontp += strlen(nfrontp); + netputs("SLC"); for (i = 2; i < length - 2; i += 3) { - if (SLC_NAME_OK(pointer[i+SLC_FUNC])) - sprintf(nfrontp, " %s", SLC_NAME(pointer[i+SLC_FUNC])); - else - sprintf(nfrontp, " %d", pointer[i+SLC_FUNC]); - nfrontp += strlen(nfrontp); + if (SLC_NAME_OK(pointer[i+SLC_FUNC])) { + netputs(" "); + netputs(SLC_NAME(pointer[i+SLC_FUNC])); + } else + netprintf(" %d", pointer[i+SLC_FUNC]); switch (pointer[i+SLC_FLAGS]&SLC_LEVELBITS) { case SLC_NOSUPPORT: - sprintf(nfrontp, " NOSUPPORT"); break; + netputs(" NOSUPPORT"); break; case SLC_CANTCHANGE: - sprintf(nfrontp, " CANTCHANGE"); break; + netputs(" CANTCHANGE"); break; case SLC_VARIABLE: - sprintf(nfrontp, " VARIABLE"); break; + netputs(" VARIABLE"); break; case SLC_DEFAULT: - sprintf(nfrontp, " DEFAULT"); break; + netputs(" DEFAULT"); break; } - nfrontp += strlen(nfrontp); - sprintf(nfrontp, "%s%s%s", - pointer[i+SLC_FLAGS]&SLC_ACK ? "|ACK" : "", - pointer[i+SLC_FLAGS]&SLC_FLUSHIN ? "|FLUSHIN" : "", - pointer[i+SLC_FLAGS]&SLC_FLUSHOUT ? "|FLUSHOUT" : ""); - nfrontp += strlen(nfrontp); + netputs(pointer[i+SLC_FLAGS]&SLC_ACK + ? "|ACK" : ""); + netputs(pointer[i+SLC_FLAGS]&SLC_FLUSHIN + ? "|FLUSHIN" : ""); + netputs(pointer[i+SLC_FLAGS]&SLC_FLUSHOUT + ? "|FLUSHOUT" : ""); if (pointer[i+SLC_FLAGS]& ~(SLC_ACK|SLC_FLUSHIN| SLC_FLUSHOUT| SLC_LEVELBITS)) { - sprintf(nfrontp, "(0x%x)", pointer[i+SLC_FLAGS]); - nfrontp += strlen(nfrontp); + netprintf("(0x%x)", pointer[i+SLC_FLAGS]); } - sprintf(nfrontp, " %d;", pointer[i+SLC_VALUE]); - nfrontp += strlen(nfrontp); + netprintf(" %d;", pointer[i+SLC_VALUE]); if ((pointer[i+SLC_VALUE] == IAC) && (pointer[i+SLC_VALUE+1] == IAC)) i++; } - for (; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); - } + for (; i < length; i++) + netprintf(" ?%d?", pointer[i]); break; case LM_MODE: - sprintf(nfrontp, "MODE "); - nfrontp += strlen(nfrontp); + netputs("MODE "); if (length < 3) { - sprintf(nfrontp, "(no mode??\?)"); - nfrontp += strlen(nfrontp); + netputs("(no mode??\?)"); break; } { - char tbuf[32]; - sprintf(tbuf, "%s%s%s%s%s", - pointer[2]&MODE_EDIT ? "|EDIT" : "", - pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "", - pointer[2]&MODE_SOFT_TAB ? "|SOFT_TAB" : "", - pointer[2]&MODE_LIT_ECHO ? "|LIT_ECHO" : "", - pointer[2]&MODE_ACK ? "|ACK" : ""); - sprintf(nfrontp, "%s", tbuf[1] ? &tbuf[1] : "0"); - nfrontp += strlen(nfrontp); - } - if (pointer[2]&~(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)) { - sprintf(nfrontp, " (0x%x)", pointer[2]); - nfrontp += strlen(nfrontp); - } - for (i = 3; i < length; i++) { - sprintf(nfrontp, " ?0x%x?", pointer[i]); - nfrontp += strlen(nfrontp); + int wrotemode = 0; + +#define NETPUTS_MODE(x) \ +do { \ + if (pointer[2] & (MODE_##x)) { \ + if (wrotemode) netputs("|"); \ + netputs(#x); \ + wrotemode++; \ + } \ +} while (0) + NETPUTS_MODE(EDIT); + NETPUTS_MODE(TRAPSIG); + NETPUTS_MODE(SOFT_TAB); + NETPUTS_MODE(LIT_ECHO); + NETPUTS_MODE(ACK); +#undef NETPUTS_MODE + if (!wrotemode) + netputs("0"); } + if (pointer[2] & ~(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)) + netprintf(" (0x%x)", pointer[2]); + for (i = 3; i < length; i++) + netprintf(" ?0x%x?", pointer[i]); break; default: - sprintf(nfrontp, "%d (unknown)", pointer[1]); - nfrontp += strlen(nfrontp); - for (i = 2; i < length; i++) { - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); - } + netprintf("%d (unknown)", pointer[1]); + for (i = 2; i < length; i++) + netprintf(" %d", pointer[i]); } break; @@ -822,24 +881,19 @@ printsub(direction, pointer, length) register char *cp; register int j, k; - sprintf(nfrontp, "STATUS"); - nfrontp += strlen(nfrontp); + netputs("STATUS"); switch (pointer[1]) { default: if (pointer[1] == TELQUAL_SEND) - sprintf(nfrontp, " SEND"); + netputs(" SEND"); else - sprintf(nfrontp, " %d (unknown)", pointer[1]); - nfrontp += strlen(nfrontp); - for (i = 2; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); - } + netprintf(" %d (unknown)", pointer[1]); + for (i = 2; i < length; i++) + netprintf(" ?%d?", pointer[i]); break; case TELQUAL_IS: - sprintf(nfrontp, " IS\r\n"); - nfrontp += strlen(nfrontp); + netputs(" IS\r\n"); for (i = 2; i < length; i++) { switch(pointer[i]) { @@ -849,19 +903,19 @@ printsub(direction, pointer, length) case WONT: cp = "WONT"; goto common2; common2: i++; + netputs(" "); + netputs(cp); + netputs(" "); if (TELOPT_OK(pointer[i])) - sprintf(nfrontp, " %s %s", cp, TELOPT(pointer[i])); + netputs(TELOPT(pointer[i])); else - sprintf(nfrontp, " %s %d", cp, pointer[i]); - nfrontp += strlen(nfrontp); + netprintf("%d", pointer[i]); - sprintf(nfrontp, "\r\n"); - nfrontp += strlen(nfrontp); + netputs("\r\n"); break; case SB: - sprintf(nfrontp, " SB "); - nfrontp += strlen(nfrontp); + netputs(" SB "); i++; j = k = i; while (j < length) { @@ -877,20 +931,17 @@ printsub(direction, pointer, length) } printsub(0, &pointer[i], k - i); if (i < length) { - sprintf(nfrontp, " SE"); - nfrontp += strlen(nfrontp); + netputs(" SE"); i = j; } else i = j - 1; - sprintf(nfrontp, "\r\n"); - nfrontp += strlen(nfrontp); + netputs("\r\n"); break; default: - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); + netprintf(" %d", pointer[i]); break; } } @@ -900,86 +951,79 @@ printsub(direction, pointer, length) } case TELOPT_XDISPLOC: - sprintf(nfrontp, "X-DISPLAY-LOCATION "); - nfrontp += strlen(nfrontp); + netputs("X-DISPLAY-LOCATION "); switch (pointer[1]) { case TELQUAL_IS: - sprintf(nfrontp, "IS \"%.*s\"", length-2, (char *)pointer+2); + netputs("IS \""); + netwrite((char *)pointer + 2, (size_t)(length - 2)); + netputs("\""); break; case TELQUAL_SEND: - sprintf(nfrontp, "SEND"); + netputs("SEND"); break; default: - sprintf(nfrontp, "- unknown qualifier %d (0x%x).", - pointer[1], pointer[1]); + netprintf("- unknown qualifier %d (0x%x).", + pointer[1], pointer[1]); } - nfrontp += strlen(nfrontp); break; case TELOPT_NEW_ENVIRON: - sprintf(nfrontp, "NEW-ENVIRON "); + netputs("NEW-ENVIRON "); goto env_common1; case TELOPT_OLD_ENVIRON: - sprintf(nfrontp, "OLD-ENVIRON"); + netputs("OLD-ENVIRON "); env_common1: - nfrontp += strlen(nfrontp); switch (pointer[1]) { case TELQUAL_IS: - sprintf(nfrontp, "IS "); + netputs("IS "); goto env_common; case TELQUAL_SEND: - sprintf(nfrontp, "SEND "); + netputs("SEND "); goto env_common; case TELQUAL_INFO: - sprintf(nfrontp, "INFO "); + netputs("INFO "); env_common: - nfrontp += strlen(nfrontp); { register int noquote = 2; for (i = 2; i < length; i++ ) { switch (pointer[i]) { case NEW_ENV_VAR: - sprintf(nfrontp, "\" VAR " + noquote); - nfrontp += strlen(nfrontp); + netputs("\" VAR " + noquote); noquote = 2; break; case NEW_ENV_VALUE: - sprintf(nfrontp, "\" VALUE " + noquote); - nfrontp += strlen(nfrontp); + netputs("\" VALUE " + noquote); noquote = 2; break; case ENV_ESC: - sprintf(nfrontp, "\" ESC " + noquote); - nfrontp += strlen(nfrontp); + netputs("\" ESC " + noquote); noquote = 2; break; case ENV_USERVAR: - sprintf(nfrontp, "\" USERVAR " + noquote); - nfrontp += strlen(nfrontp); + netputs("\" USERVAR " + noquote); noquote = 2; break; default: if (isprint(pointer[i]) && pointer[i] != '"') { if (noquote) { - *nfrontp++ = '"'; + netputs("\""); noquote = 0; } - *nfrontp++ = pointer[i]; + netprintf("%c", pointer[i]); } else { - sprintf(nfrontp, "\" %03o " + noquote, - pointer[i]); - nfrontp += strlen(nfrontp); + netprintf("\" %03o " + noquote, + pointer[i]); noquote = 2; } break; } } if (!noquote) - *nfrontp++ = '"'; + netputs("\""); break; } } @@ -987,91 +1031,74 @@ printsub(direction, pointer, length) #if defined(AUTHENTICATION) case TELOPT_AUTHENTICATION: - sprintf(nfrontp, "AUTHENTICATION"); - nfrontp += strlen(nfrontp); + netputs("AUTHENTICATION"); if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + netputs(" (empty suboption??\?)"); break; } switch (pointer[1]) { case TELQUAL_REPLY: case TELQUAL_IS: - sprintf(nfrontp, " %s ", (pointer[1] == TELQUAL_IS) ? - "IS" : "REPLY"); - nfrontp += strlen(nfrontp); + netputs((pointer[1] == TELQUAL_IS) ? " IS " : " REPLY "); if (AUTHTYPE_NAME_OK(pointer[2])) - sprintf(nfrontp, "%s ", AUTHTYPE_NAME(pointer[2])); + netputs(AUTHTYPE_NAME(pointer[2])); else - sprintf(nfrontp, "%d ", pointer[2]); - nfrontp += strlen(nfrontp); + netprintf(" %d ", pointer[2]); if (length < 3) { - sprintf(nfrontp, "(partial suboption??\?)"); - nfrontp += strlen(nfrontp); + netputs("(partial suboption??\?)"); break; } - sprintf(nfrontp, "%s|%s%s", - ((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ? - "CLIENT" : "SERVER", - ((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ? - "MUTUAL" : "ONE-WAY", - ((pointer[3] & AUTH_ENCRYPT_MASK) == AUTH_ENCRYPT_ON) ? - "|ENCRYPT" : ""); - nfrontp += strlen(nfrontp); + netputs(((pointer[3] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) + ? "CLIENT|" : "SERVER|"); + netputs(((pointer[3] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) + ? "MUTUAL" : "ONE-WAY"); + netputs(((pointer[3] & AUTH_ENCRYPT_MASK) == AUTH_ENCRYPT_ON) + ? "|ENCRYPT" : ""); auth_printsub(&pointer[1], length - 1, buf, sizeof(buf)); - sprintf(nfrontp, "%s", buf); - nfrontp += strlen(nfrontp); + netputs(buf); break; case TELQUAL_SEND: i = 2; - sprintf(nfrontp, " SEND "); - nfrontp += strlen(nfrontp); + netputs(" SEND "); while (i < length) { if (AUTHTYPE_NAME_OK(pointer[i])) - sprintf(nfrontp, "%s ", AUTHTYPE_NAME(pointer[i])); + netputs(AUTHTYPE_NAME(pointer[i])); else - sprintf(nfrontp, "%d ", pointer[i]); - nfrontp += strlen(nfrontp); + netprintf("%d", pointer[i]); + netputs(" "); if (++i >= length) { - sprintf(nfrontp, "(partial suboption??\?)"); - nfrontp += strlen(nfrontp); + netputs("(partial suboption??\?)"); break; } - sprintf(nfrontp, "%s|%s%s ", - ((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) ? - "CLIENT" : "SERVER", - ((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) ? - "MUTUAL" : "ONE-WAY", - ((pointer[3] & AUTH_ENCRYPT_MASK) == AUTH_ENCRYPT_ON) ? - "|ENCRYPT" : ""); - nfrontp += strlen(nfrontp); + netputs(((pointer[i] & AUTH_WHO_MASK) == AUTH_WHO_CLIENT) + ? "CLIENT|" : "SERVER|"); + netputs(((pointer[i] & AUTH_HOW_MASK) == AUTH_HOW_MUTUAL) + ? "MUTUAL" : "ONE-WAY"); + if ((pointer[3] & AUTH_ENCRYPT_MASK) == AUTH_ENCRYPT_ON) + netputs("|ENCRYPT"); ++i; } break; case TELQUAL_NAME: i = 2; - sprintf(nfrontp, " NAME \""); - nfrontp += strlen(nfrontp); + netputs(" NAME \""); while (i < length) { if (isprint(pointer[i])) - *nfrontp++ = pointer[i++]; + netprintf("%c", pointer[i++]); else { - sprintf(nfrontp, "\"%03o",pointer[i++]); - nfrontp += strlen(nfrontp); + netprintf("\\%03o", pointer[i++]); } } - *nfrontp++ = '"'; + netputs("\""); break; default: - for (i = 2; i < length; i++) { - sprintf(nfrontp, " ?%d?", pointer[i]); - nfrontp += strlen(nfrontp); - } + for (i = 2; i < length; i++) + netprintf(" ?%d?", pointer[i]); break; } break; @@ -1079,87 +1106,72 @@ printsub(direction, pointer, length) #ifdef ENCRYPTION case TELOPT_ENCRYPT: - sprintf(nfrontp, "ENCRYPT"); - nfrontp += strlen(nfrontp); + netputs("ENCRYPT"); if (length < 2) { - sprintf(nfrontp, " (empty suboption??\?)"); - nfrontp += strlen(nfrontp); + netputs(" (empty suboption??\?)"); break; } switch (pointer[1]) { case ENCRYPT_START: - sprintf(nfrontp, " START"); - nfrontp += strlen(nfrontp); + netputs(" START"); break; case ENCRYPT_END: - sprintf(nfrontp, " END"); - nfrontp += strlen(nfrontp); + netputs(" END"); break; case ENCRYPT_REQSTART: - sprintf(nfrontp, " REQUEST-START"); - nfrontp += strlen(nfrontp); + netputs(" REQUEST-START"); break; case ENCRYPT_REQEND: - sprintf(nfrontp, " REQUEST-END"); - nfrontp += strlen(nfrontp); + netputs(" REQUEST-END"); break; case ENCRYPT_IS: case ENCRYPT_REPLY: - sprintf(nfrontp, " %s ", (pointer[1] == ENCRYPT_IS) ? - "IS" : "REPLY"); - nfrontp += strlen(nfrontp); + netputs((pointer[1] == ENCRYPT_IS) + ? " IS " : " REPLY "); if (length < 3) { - sprintf(nfrontp, " (partial suboption??\?)"); - nfrontp += strlen(nfrontp); + netputs(" (partial suboption??\?)"); break; } if (ENCTYPE_NAME_OK(pointer[2])) - sprintf(nfrontp, "%s ", ENCTYPE_NAME(pointer[2])); + netputs(ENCTYPE_NAME(pointer[2])); else - sprintf(nfrontp, " %d (unknown)", pointer[2]); - nfrontp += strlen(nfrontp); + netprintf("%d (unknown)", pointer[2]); + netputs(" "); encrypt_printsub(&pointer[1], length - 1, buf, sizeof(buf)); - sprintf(nfrontp, "%s", buf); - nfrontp += strlen(nfrontp); + netputs(buf); break; case ENCRYPT_SUPPORT: i = 2; - sprintf(nfrontp, " SUPPORT "); - nfrontp += strlen(nfrontp); + netputs(" SUPPORT "); while (i < length) { if (ENCTYPE_NAME_OK(pointer[i])) - sprintf(nfrontp, "%s ", ENCTYPE_NAME(pointer[i])); + netputs(ENCTYPE_NAME(pointer[i])); else - sprintf(nfrontp, "%d ", pointer[i]); - nfrontp += strlen(nfrontp); + netprintf("%d", pointer[i]); + netputs(" "); i++; } break; case ENCRYPT_ENC_KEYID: - sprintf(nfrontp, " ENC_KEYID", pointer[1]); - nfrontp += strlen(nfrontp); + netputs(" ENC_KEYID"); goto encommon; case ENCRYPT_DEC_KEYID: - sprintf(nfrontp, " DEC_KEYID", pointer[1]); - nfrontp += strlen(nfrontp); + netputs(" DEC_KEYID"); goto encommon; default: - sprintf(nfrontp, " %d (unknown)", pointer[1]); - nfrontp += strlen(nfrontp); + netprintf(" %d (unknown)", pointer[1]); encommon: - for (i = 2; i < length; i++) { - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); - } + for (i = 2; i < length; i++) + netprintf(" %d", pointer[i]); break; } break; @@ -1167,18 +1179,15 @@ printsub(direction, pointer, length) default: if (TELOPT_OK(pointer[0])) - sprintf(nfrontp, "%s (unknown)", TELOPT(pointer[0])); + netputs(TELOPT(pointer[0])); else - sprintf(nfrontp, "%d (unknown)", pointer[i]); - nfrontp += strlen(nfrontp); - for (i = 1; i < length; i++) { - sprintf(nfrontp, " %d", pointer[i]); - nfrontp += strlen(nfrontp); - } + netprintf("%d", pointer[0]); + netputs(" (unknown)"); + for (i = 1; i < length; i++) + netprintf(" %d", pointer[i]); break; } - sprintf(nfrontp, "\r\n"); - nfrontp += strlen(nfrontp); + netputs("\r\n"); } /* @@ -1194,32 +1203,25 @@ printdata(tag, ptr, cnt) char xbuf[30]; while (cnt) { - /* flush net output buffer if no room for new data) */ - if ((&netobuf[BUFSIZ] - nfrontp) < 80) { - netflush(); - } - /* add a line of output */ - sprintf(nfrontp, "%s: ", tag); - nfrontp += strlen(nfrontp); + netputs(tag); + netputs(": "); for (i = 0; i < 20 && cnt; i++) { - sprintf(nfrontp, "%02x", *ptr); - nfrontp += strlen(nfrontp); + netprintf("%02x", *ptr); if (isprint(*ptr)) { xbuf[i] = *ptr; } else { xbuf[i] = '.'; } - if (i % 2) { - *nfrontp = ' '; - nfrontp++; - } + if (i % 2) + netputs(" "); cnt--; ptr++; } xbuf[i] = '\0'; - sprintf(nfrontp, " %s\r\n", xbuf ); - nfrontp += strlen(nfrontp); + netputs(" "); + netputs(xbuf); + netputs("\r\n"); } } #endif /* DIAGNOSTICS */ diff --git a/src/clients/ChangeLog b/src/clients/ChangeLog index 2ab67bd..de83ed9 100644 --- a/src/clients/ChangeLog +++ b/src/clients/ChangeLog @@ -1,3 +1,13 @@ +2001-02-21 Tom Yu + + * configure.in: Add checks for unsetenv and getenv. Compile + setenv.o if any of setenv, unsetenv, or getenv are missing. + +2000-03-24 Ken Raeburn + + * configure.in: Check for alpha*-dec-osf* instead of + alpha-dec-osf*. + 2000-02-24 Ezra Peisach * configure.in: Test for include file for inet_ntop diff --git a/src/clients/configure.in b/src/clients/configure.in index bd2046d..5617168 100644 --- a/src/clients/configure.in +++ b/src/clients/configure.in @@ -3,8 +3,9 @@ CONFIG_RULES AC_PROG_INSTALL KRB5_BUILD_PROGRAM AC_HEADER_STDARG -AC_CHECK_FUNCS(getusershell lstat setenv inet_ntop getipnodebyaddr) -if test $ac_cv_func_setenv = no ; then +AC_CHECK_FUNCS(getusershell lstat setenv unsetenv getenv inet_ntop getipnodebyaddr) +if test $ac_cv_func_setenv = no || test $ac_cv_func_unsetenv = no \ + || test $ac_cv_func_getenv = no; then SETENVOBJ=setenv.o else SETENVOBJ= @@ -12,7 +13,7 @@ fi AC_SUBST(SETENVOBJ) AC_CHECK_HEADERS(unistd.h pwd.h arpa/inet.h) case $krb5_cv_host in -alpha-dec-osf*) +alpha*-dec-osf*) AC_CHECK_LIB(security,setluid, AC_DEFINE(HAVE_SETLUID) KSU_LIBS="$KSU_LIBS -lsecurity" diff --git a/src/clients/kinit/ChangeLog b/src/clients/kinit/ChangeLog index 8939718..e99ef3f 100644 --- a/src/clients/kinit/ChangeLog +++ b/src/clients/kinit/ChangeLog @@ -1,3 +1,8 @@ +2001-12-10 Danilo Almeida + + * kinit.c (main): Fix typo in #ifdef KRB5_KRB4_COMPAT. Thanks to + rbasch@mit.edu + 2000-03-16 Ezra Peisach * kinit.c (k4_kinit): Fix the code that was broken with diff --git a/src/clients/kinit/kinit.c b/src/clients/kinit/kinit.c index f9245a8..a277738 100644 --- a/src/clients/kinit/kinit.c +++ b/src/clients/kinit/kinit.c @@ -1095,7 +1095,7 @@ main(argc, argv) #endif if (!authed_k4) authed_k4 = k4_kinit(&opts, &k4, k5.ctx); -#ifdef KRB5_KRB4_COMPATH +#ifdef KRB5_KRB4_COMPAT memset(stash_password, 0, sizeof(stash_password)); #endif diff --git a/src/clients/klist/ChangeLog b/src/clients/klist/ChangeLog index 86686bb..1016287 100644 --- a/src/clients/klist/ChangeLog +++ b/src/clients/klist/ChangeLog @@ -1,3 +1,15 @@ +2001-09-25 Ken Raeburn + + * klist.c (flags_string): Display transit-policy-checked, + ok-as-delegate, and anonymous ticket flags. + +2000-04-19 Danilo Almeida + + * Makefile.in: Link in getopt library on Windows. + + * klist.c: Use getopt so that we can parse combined options (e.g., + -an or -45). + 2000-03-07 Danilo Almeida * klist.M: Get man page up-to-date. diff --git a/src/clients/klist/Makefile.in b/src/clients/klist/Makefile.in index c33a4d0..4e067ea 100644 --- a/src/clients/klist/Makefile.in +++ b/src/clients/klist/Makefile.in @@ -14,7 +14,7 @@ all-mac:: klist: klist.o $(KRB4COMPAT_DEPLIBS) $(CC_LINK) -o $@ klist.o $(KRB4COMPAT_LIBS) -$(OUTPRE)klist.exe: $(OUTPRE)klist.obj $(KLIB) $(CLIB) +$(OUTPRE)klist.exe: $(OUTPRE)klist.obj $(BUILDTOP)\util\windows\$(OUTPRE)getopt.lib $(KLIB) $(CLIB) link $(EXE_LINKOPTS) -out:$@ $** wsock32.lib clean-unix:: diff --git a/src/clients/klist/klist.c b/src/clients/klist/klist.c index de435c4..2d77f7f 100644 --- a/src/clients/klist/klist.c +++ b/src/clients/klist/klist.c @@ -1,7 +1,7 @@ /* * clients/klist/klist.c * - * Copyright 1990 by the Massachusetts Institute of Technology. + * Copyright 1990,2001 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -53,6 +53,8 @@ #include #endif +extern int optind; + int show_flags = 0, show_time = 0, status_only = 0, show_keys = 0; int show_etype = 0, show_addresses = 0, no_resolve = 0; char *defname; @@ -130,6 +132,7 @@ main(argc, argv) int argc; char **argv; { + int c; char *name; int mode; int use_k5 = 0, use_k4 = 0; @@ -141,14 +144,10 @@ main(argc, argv) progname = GET_PROGNAME(argv[0]); - argv++; name = NULL; mode = DEFAULT; - while (*argv) { - if ((*argv)[0] != '-') { - if (name) usage(); - name = *argv; - } else switch ((*argv)[1]) { + while ((c = getopt(argc, argv, "fetKsnack45")) != -1) { + switch (c) { case 'f': show_flags = 1; break; @@ -202,7 +201,6 @@ main(argc, argv) usage(); break; } - argv++; } if (no_resolve && !show_addresses) { @@ -217,6 +215,14 @@ main(argc, argv) usage(); } + if (argc - optind > 1) { + fprintf(stderr, "Extra arguments (starting with \"%s\").\n", + argv[optind+1]); + usage(); + } + + name = (optind == argc-1) ? argv[optind] : 0; + if (!use_k5 && !use_k4) { use_k5 = default_k5; @@ -514,6 +520,12 @@ flags_string(cred) buf[i++] = 'H'; if (cred->ticket_flags & TKT_FLG_PRE_AUTH) buf[i++] = 'A'; + if (cred->ticket_flags & TKT_FLG_TRANSIT_POLICY_CHECKED) + buf[i++] = 'T'; + if (cred->ticket_flags & TKT_FLG_OK_AS_DELEGATE) + buf[i++] = 'O'; /* D/d are taken. Use short strings? */ + if (cred->ticket_flags & TKT_FLG_ANONYMOUS) + buf[i++] = 'a'; buf[i] = '\0'; return(buf); } diff --git a/src/clients/ksu/ChangeLog b/src/clients/ksu/ChangeLog index f486004..0b964bb 100644 --- a/src/clients/ksu/ChangeLog +++ b/src/clients/ksu/ChangeLog @@ -1,3 +1,44 @@ +2001-10-18 Ken Raeburn + + Don't crash if .k[5]login file ownership is wrong. Patch from + Emily Ratliff, ratliff@austin.ibm.com. + * authorization.c (fowner): Don't close the file even on error. + (krb5_authorization): Close the file if fowner returns FALSE. + +2001-02-21 Tom Yu + + * setenv.c: Add conditionals for compilation of setenv, unsetenv, + and getenv such that they only get compiled if they don't already + exist. + +2000-05-22 Tom Yu + + * Makefile.in (OBJS): Put @SETENVOBJ@ on same line as xmalloc.o to + avoid trailing backslash on the end of the variable. + +2000-05-15 Ken Raeburn + + * ccache.c (krb5_ccache_copy): Modify conditionalized code block + slightly to make automatic indentation work better. + + * main.c (main): Complain and quit if prog_name is longer than 50 + characters. + +2000-04-26 Ken Raeburn + Nalin Dahyabhai + + * main.c (DEBUG): Don't define. + (usage): Remove -C option from description. + (sweep_up): Deleted second argument; all callers changed. + (main): Support -D option only if DEBUG is defined. Initialize + ruid on entry. Set effective uid to ruid before processing + argument list. Removed -C option from -z/-Z conflict messages. + Report errors trying to stat source ccache using com_err. Verify + that getpwuid's returned data for source user has correct uid. + Eliminate use_source_cache variable. + + * ksu.M: Updates for removal of -C option. + 2000-01-27 Ken Raeburn * main.c (print_status): Now static. Add format attribute if diff --git a/src/clients/ksu/Makefile.in b/src/clients/ksu/Makefile.in index c96de37..915d4b2 100644 --- a/src/clients/ksu/Makefile.in +++ b/src/clients/ksu/Makefile.in @@ -23,8 +23,7 @@ OBJS = \ authorization.o \ main.o \ heuristic.o \ - xmalloc.o \ - @SETENVOBJ@ + xmalloc.o @SETENVOBJ@ all:: ksu diff --git a/src/clients/ksu/authorization.c b/src/clients/ksu/authorization.c index a2e5409..d184993 100644 --- a/src/clients/ksu/authorization.c +++ b/src/clients/ksu/authorization.c @@ -40,12 +40,10 @@ krb5_boolean fowner(fp, uid) * the user himself, or by root. Otherwise, don't grant access. */ if (fstat(fileno(fp), &sbuf)) { - fclose(fp); return(FALSE); } if ((sbuf.st_uid != uid) && sbuf.st_uid) { - fclose(fp); return(FALSE); } @@ -102,8 +100,10 @@ krb5_error_code krb5_authorization(context, principal, luser, if (!k5login_flag){ if ((login_fp = fopen(k5login_path, "r")) == NULL) return 0; - if ( fowner(login_fp, pwd->pw_uid) == FALSE) + if ( fowner(login_fp, pwd->pw_uid) == FALSE) { + fclose(login_fp); return 0; + } } if (!k5users_flag){ @@ -111,6 +111,7 @@ krb5_error_code krb5_authorization(context, principal, luser, return 0; } if ( fowner(users_fp, pwd->pw_uid) == FALSE){ + fclose(users_fp); return 0; } } diff --git a/src/clients/ksu/ccache.c b/src/clients/ksu/ccache.c index be77456..97a2084 100644 --- a/src/clients/ksu/ccache.c +++ b/src/clients/ksu/ccache.c @@ -75,7 +75,6 @@ struct stat st_temp; cc_def_name = krb5_cc_get_name(context, cc_def); cc_other_name = krb5_cc_get_name(context, *cc_other); - if ( ! stat(cc_def_name, &st_temp)){ if((retval = krb5_get_nonexp_tkts(context,cc_def,&cc_def_creds_arr))){ return retval; @@ -86,12 +85,11 @@ struct stat st_temp; primary_principal); #ifdef HAVE_LSTAT - if (!lstat( cc_other_name, &st_temp)) { + if (!lstat( cc_other_name, &st_temp)) #else /*HAVE_LSTAT*/ - if (!stat( cc_other_name, &st_temp)) { + if (!stat( cc_other_name, &st_temp)) #endif return EINVAL; - } if (krb5_seteuid(0)||krb5_seteuid(target_uid)) { return errno; diff --git a/src/clients/ksu/ksu.M b/src/clients/ksu/ksu.M index 2eea2a0..325d2e8 100644 --- a/src/clients/ksu/ksu.M +++ b/src/clients/ksu/ksu.M @@ -37,9 +37,6 @@ ksu \- Kerberized super-user .B \-c .I source_cache_name ] [ -.B \-C -.I target_cache_name -] [ .B \-k ] [ .B \-D @@ -169,10 +166,8 @@ The real and effective user ID are changed to that of the target user. The target user's shell is then invoked (the shell name is specified in the password file). Upon termination of the shell, ksu deletes the target cache (unless -ksu is invoked with -.B \-k - or ' -.B \-C .' options). +ksu is invoked with the +.B \-k option). This is implemented by first doing a fork and then an exec, instead of just exec, as done by su. .br @@ -287,19 +282,7 @@ option is not used then the name is obtained from KRB5CCNAME environment variable. If KRB5CCNAME is not defined the source cache name is set to krb5cc_. -.TP 10 -\fB\-C \fItarget_cache_name -Specify the target cache name (e.g. -.B \-C -FILE:/tmp/target_cache). -If '.' is specified (e.g. ksu -\-C .) ksu uses the source -cache and does not create a new target cache. Note: -this case requires both source and target user -to have read and write permissions for the source cache. -If -.B \-C -option is not used, the default target cache name is +The target cache name is automatically set to krb5cc_.(gen_sym()), where gen_sym generates a new number such that the resulting cache does not already exist. @@ -313,8 +296,7 @@ target shell or a command ( command). Without .B \-k, -ksu deletes the target cache -(unless ksu was invoked with '-C .' option). +ksu deletes the target cache. .TP 10 \fB\-D turn on debug mode. @@ -359,7 +341,7 @@ if you want the tickets for other then the default principal. Note that the .B \-z option is mutually -exclusive with '-C .' and -Z options. +exclusive with the -Z option. .TP 10 \fB\-Z Don't copy any tickets from the source cache to the @@ -368,7 +350,7 @@ where the default principal name of the cache is initialized to the target principal name. Note that .B \-Z option is mutually -exclusive with '-C .' and -z options. +exclusive with the -z option. .TP 10 \fB\-q suppress the printing of status messages. diff --git a/src/clients/ksu/main.c b/src/clients/ksu/main.c index 77a4996..58d3031 100644 --- a/src/clients/ksu/main.c +++ b/src/clients/ksu/main.c @@ -42,7 +42,7 @@ int quiet = 0; #define _DEF_CSH "/bin/csh" static int set_env_var PROTOTYPE((char *, char *)); -static void sweep_up PROTOTYPE((krb5_context, int, krb5_ccache)); +static void sweep_up PROTOTYPE((krb5_context, krb5_ccache)); static char * ontty PROTOTYPE((void)); #ifdef HAVE_STDARG_H static void print_status( const char *fmt, ...) @@ -61,7 +61,6 @@ char * get_dir_of_file(); void usage (){ fprintf(stderr, "Usage: %s [target user] [-n principal] [-c source cachename] [-C target cachename] [-k] [-D] [-r time] [-pf] [-l lifetime] [-zZ] [-q] [-e command [args... ] ] [-a [args... ] ]\n", prog_name); - } /* for Ultrix and friends ... */ @@ -69,8 +68,6 @@ void usage (){ #define MAXHOSTNAMELEN 64 #endif -#define DEBUG - /* These are file static so sweep_up can get to them*/ static uid_t source_uid, target_uid; @@ -86,7 +83,6 @@ char *localhostname = NULL; opt_info options; int option=0; int statusp=0; -int use_source_cache = 0; krb5_error_code retval = 0; krb5_principal client = NULL; krb5_ccache cc_target = NULL; @@ -106,7 +102,7 @@ krb5_boolean auth_val; krb5_boolean authorization_val = FALSE; int path_passwd = 0; int done =0,i,j; -uid_t ruid; +uid_t ruid = getuid (); struct passwd *pwd=NULL, *target_pwd ; char * shell; char ** params; @@ -142,6 +138,11 @@ char * dir_of_cc_source; if (strrchr(argv[0], '/')) argv[0] = strrchr(argv[0], '/')+1; prog_name = argv[0]; + if (strlen (prog_name) > 50) { + /* this many chars *after* last / ?? */ + com_err(prog_name, 0, "program name too long - quitting to avoid triggering system logging bugs"); + exit (1); + } #ifndef LOG_NDELAY @@ -176,7 +177,10 @@ char * dir_of_cc_source; } } - + if (krb5_seteuid (ruid)) { + com_err (prog_name, errno, "while setting euid to source user"); + exit (1); + } while(!done && ((option = getopt(pargc, pargv,"n:c:r:a:zZDfpkql:e:")) != -1)){ switch (option) { case 'r': @@ -232,22 +236,24 @@ char * dir_of_cc_source; options.princ = 1; break; +#ifdef DEBUG case 'D': auth_debug = 1; - break; + break; +#endif case 'z': some_rest_copy = 1; - if(all_rest_copy || use_source_cache){ + if(all_rest_copy) { fprintf(stderr, - "-z option is mutually exclusive with -Z and -C .\n"); + "-z option is mutually exclusive with -Z.\n"); errflg++; } break; case 'Z': all_rest_copy = 1; - if(some_rest_copy || use_source_cache){ + if(some_rest_copy) { fprintf(stderr, - "-Z option is mutually exclusive with -z and -C .\n"); + "-Z option is mutually exclusive with -z.\n"); errflg++; } break; @@ -258,10 +264,10 @@ char * dir_of_cc_source; cc_source_tag_tmp = strchr(cc_source_tag, ':') + 1; if( stat( cc_source_tag_tmp, &st_temp)){ - fprintf(stderr,"File %s does not exist\n", - cc_source_tag_tmp); - errflg++; - + com_err (prog_name, errno, + "while looking for credentials file %s", + cc_source_tag_tmp); + exit (1); } } else { @@ -313,10 +319,9 @@ char * dir_of_cc_source; } /***********************************/ - ruid = getuid(); source_user = getlogin(); /*checks for the the login name in /etc/utmp*/ - /* verify that that the user exists and get his passwd structure */ + /* verify that that the user exists and get his passwd structure */ if (source_user == NULL ||(pwd = getpwnam(source_user)) == NULL || pwd->pw_uid != ruid){ @@ -327,6 +332,12 @@ char * dir_of_cc_source; fprintf(stderr, "ksu: who are you?\n"); exit(1); } + if (pwd->pw_uid != ruid) { + fprintf (stderr, "Your uid doesn't match your passwd entry?!\n"); + exit (1); + } + /* Okay, now we have *some* passwd entry that matches the + current real uid. */ /* allocate space and copy the usernamane there */ source_user = xstrdup(pwd->pw_name); @@ -357,23 +368,17 @@ char * dir_of_cc_source; else cc_source_tag_tmp++; } - if (krb5_seteuid(source_uid)) { - com_err ( prog_name, errno, "while setting euid to source user"); - exit(1); - } - + /* get a handle for the cache */ if ((retval = krb5_cc_resolve(ksu_context, cc_source_tag, &cc_source))){ com_err(prog_name, retval,"while getting source cache"); exit(1); } - if(!use_source_cache) { - if (((retval = krb5_cc_set_flags(ksu_context, cc_source, 0x0)) != 0) - && (retval != KRB5_FCC_NOFILE)) { + if (((retval = krb5_cc_set_flags(ksu_context, cc_source, 0x0)) != 0) + && (retval != KRB5_FCC_NOFILE)) { com_err(prog_name, retval, "while opening ccache"); exit(1); - } } if ((retval = get_best_princ_for_target(ksu_context, source_uid, target_uid, source_user, target_user, cc_source, @@ -409,29 +414,6 @@ char * dir_of_cc_source; exit(1); } - if (stat(cc_source_tag_tmp, &st_temp)){ - if (use_source_cache){ - - dir_of_cc_source = get_dir_of_file(cc_source_tag_tmp); - - - if (access(dir_of_cc_source, R_OK | W_OK )){ - fprintf(stderr, - "%s does not have correct permissions for %s\n", - source_user, cc_source_tag); - exit(1); - } - - if ((retval = krb5_cc_initialize(ksu_context, cc_source, - client))){ - com_err(prog_name, retval, - "while initializing source cache"); - exit(1); - } - } - } - - if (cc_target_tag == NULL) { cc_target_tag = (char *)xcalloc(KRB5_SEC_BUFFSIZE ,sizeof(char)); @@ -450,8 +432,7 @@ char * dir_of_cc_source; } - dir_of_cc_target = get_dir_of_file( use_source_cache ? - cc_source_tag_tmp: cc_target_tag_tmp); + dir_of_cc_target = get_dir_of_file(cc_target_tag_tmp); if (access(dir_of_cc_target, R_OK | W_OK )){ fprintf(stderr, @@ -475,48 +456,33 @@ char * dir_of_cc_source; The cache is owned by the target user.*/ - if (! use_source_cache){ - - /* if root ksu's to a regular user, then - then only the credentials for that particular user - should be copied */ + /* if root ksu's to a regular user, then + then only the credentials for that particular user + should be copied */ - if ((source_uid == 0) && (target_uid != 0)) { + if ((source_uid == 0) && (target_uid != 0)) { - if ((retval = krb5_ccache_copy_restricted(ksu_context, cc_source, - cc_target_tag, client, &cc_target, &stored, target_uid))){ - com_err (prog_name, retval, - "while copying cache %s to %s", - krb5_cc_get_name(ksu_context, cc_source),cc_target_tag); - exit(1); - } - - } else{ - if ((retval = krb5_ccache_copy(ksu_context, cc_source, cc_target_tag, - client,&cc_target, &stored, target_uid))){ - com_err (prog_name, retval, - "while copying cache %s to %s", - krb5_cc_get_name(ksu_context, cc_source), - cc_target_tag); - exit(1); - } - - } - - } - else{ - cc_target = cc_source; - cc_target_tag = (char *) cc_source_tag; - cc_target_tag_tmp = (char *) cc_source_tag_tmp; - - if ((retval=krb5_find_princ_in_cache(ksu_context, cc_target,client, &stored))){ - com_err (prog_name, retval, - "while searching for client in source ccache"); - exit(1); - } + if ((retval = krb5_ccache_copy_restricted(ksu_context, cc_source, + cc_target_tag, client, &cc_target, &stored, target_uid))){ + com_err (prog_name, retval, + "while copying cache %s to %s", + krb5_cc_get_name(ksu_context, cc_source),cc_target_tag); + exit(1); + } + } else { + if ((retval = krb5_ccache_copy(ksu_context, cc_source, cc_target_tag, + client,&cc_target, &stored, target_uid))) { + com_err (prog_name, retval, + "while copying cache %s to %s", + krb5_cc_get_name(ksu_context, cc_source), + cc_target_tag); + exit(1); + } + } - /* Become root for authentication*/ + + /* Become root for authentication*/ if (krb5_seteuid(0)) { com_err(prog_name, errno, "while reclaiming root uid"); @@ -532,7 +498,7 @@ char * dir_of_cc_source; &kdc_server))){ com_err(prog_name, retval, "while creating tgt for local realm"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } @@ -544,8 +510,7 @@ char * dir_of_cc_source; if (zero_password == FALSE){ fprintf(stderr,"Goodbye\n"); - sweep_up(ksu_context, use_source_cache, - cc_target); + sweep_up(ksu_context, cc_target); exit(1); } @@ -574,7 +539,7 @@ char * dir_of_cc_source; syslog(LOG_WARNING, "'%s %s' authentication failed for %s%s", prog_name,target_user,source_user,ontty()); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } @@ -585,7 +550,7 @@ char * dir_of_cc_source; to properly handle races in chown if this code is ever re-enabled. */ /* cache the tickets if possible in the source cache */ - if (!path_passwd && !use_source_cache){ + if (!path_passwd){ if ((retval = krb5_ccache_overwrite(ksu_context, cc_target, cc_source, client))){ @@ -593,7 +558,7 @@ char * dir_of_cc_source; "while copying cache %s to %s", krb5_cc_get_name(ksu_context, cc_target), krb5_cc_get_name(ksu_context, cc_source)); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } if (chown(cc_source_tag_tmp, source_uid, source_gid)){ @@ -607,7 +572,7 @@ char * dir_of_cc_source; if ((retval = krb5_unparse_name(ksu_context, client, &client_name))) { com_err (prog_name, retval, "When unparsing name"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } @@ -619,7 +584,7 @@ char * dir_of_cc_source; /* Run authorization as target.*/ if (krb5_seteuid(target_uid)) { com_err(prog_name, errno, "while switching to target for authorization check"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } @@ -627,13 +592,13 @@ char * dir_of_cc_source; cmd, &authorization_val, &exec_cmd))){ com_err(prog_name,retval,"while checking authorization"); krb5_seteuid(0); /*So we have some chance of sweeping up*/ - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } if (krb5_seteuid(0)) { com_err(prog_name, errno, "while switching back from target after authorization check"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } if (authorization_val == TRUE){ @@ -678,7 +643,7 @@ krb5_seteuid(0); /*So we have some chance of sweeping up*/ } - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } } @@ -686,7 +651,7 @@ krb5_seteuid(0); /*So we have some chance of sweeping up*/ if( some_rest_copy){ if ((retval = krb5_ccache_filter(ksu_context, cc_target, client))){ com_err(prog_name,retval,"while calling cc_filter"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } } @@ -715,7 +680,7 @@ krb5_seteuid(0); /*So we have some chance of sweeping up*/ if (!standard_shell(target_pwd->pw_shell) && source_uid) { fprintf(stderr, "ksu: permission denied (shell).\n"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } #endif /* HAVE_GETUSERSHELL */ @@ -724,20 +689,20 @@ krb5_seteuid(0); /*So we have some chance of sweeping up*/ if(set_env_var("USER", target_pwd->pw_name)){ fprintf(stderr,"ksu: couldn't set environment variable USER\n"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } } if(set_env_var( "HOME", target_pwd->pw_dir)){ fprintf(stderr,"ksu: couldn't set environment variable USER\n"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } if(set_env_var( "SHELL", shell)){ fprintf(stderr,"ksu: couldn't set environment variable USER\n"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } @@ -746,26 +711,21 @@ krb5_seteuid(0); /*So we have some chance of sweeping up*/ if(set_env_var( KRB5_ENV_CCNAME, cc_target_tag)){ fprintf(stderr,"ksu: couldn't set environment variable %s\n", KRB5_ENV_CCNAME); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } - - if (!use_source_cache){ - - } - /* set permissions */ if (setgid(target_pwd->pw_gid) < 0) { perror("ksu: setgid"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } if (initgroups(target_user, target_pwd->pw_gid)) { fprintf(stderr, "ksu: initgroups failed.\n"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } @@ -785,14 +745,14 @@ krb5_seteuid(0); /*So we have some chance of sweeping up*/ */ if (setluid((uid_t) pwd->pw_uid) < 0) { perror("setluid"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } #endif /* HAVE_SETLUID */ if (setuid(target_pwd->pw_uid) < 0) { perror("ksu: setuid"); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); } @@ -827,11 +787,11 @@ krb5_seteuid(0); /*So we have some chance of sweeping up*/ fprintf(stderr, "program to be execed %s\n",params[0]); } - if( keep_target_cache || use_source_cache ) { + if( keep_target_cache ) { execv(params[0], params); com_err(prog_name, errno, "while trying to execv %s", params[0]); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit(1); }else{ statusp = 1; @@ -858,11 +818,11 @@ krb5_seteuid(0); /*So we have some chance of sweeping up*/ if (ret_pid == -1) { com_err(prog_name, errno, "while calling waitpid"); } - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit (statusp); case -1: com_err(prog_name, errno, "while trying to fork."); - sweep_up(ksu_context, use_source_cache, cc_target); + sweep_up(ksu_context, cc_target); exit (1); case 0: execv(params[0], params); @@ -920,27 +880,24 @@ char * env_var_buf; } -static void sweep_up(context, use_source_cache, cc) +static void sweep_up(context, cc) krb5_context context; - int use_source_cache; krb5_ccache cc; { -krb5_error_code retval; -char * cc_name; -struct stat st_temp; + krb5_error_code retval; + char * cc_name; + struct stat st_temp; -krb5_seteuid(0); -krb5_seteuid(target_uid); + krb5_seteuid(0); + krb5_seteuid(target_uid); -if (! use_source_cache){ - cc_name = krb5_cc_get_name(context, cc); - if ( ! stat(cc_name, &st_temp)){ - if ((retval = krb5_cc_destroy(context, cc))){ - com_err(prog_name, retval, - "while destroying cache"); - } - } + cc_name = krb5_cc_get_name(context, cc); + if ( ! stat(cc_name, &st_temp)){ + if ((retval = krb5_cc_destroy(context, cc))){ + com_err(prog_name, retval, + "while destroying cache"); } + } } /***************************************************************** get_params is to be called for the -a option or -e option to diff --git a/src/clients/ksu/setenv.c b/src/clients/ksu/setenv.c index 96d4a1e..2633a9d 100644 --- a/src/clients/ksu/setenv.c +++ b/src/clients/ksu/setenv.c @@ -25,6 +25,7 @@ * Set the value of the environmental variable "name" to be * "value". If rewrite is set, replace any current value. */ +#ifndef HAVE_SETENV setenv(name, value, rewrite) register char *name, *value; int rewrite; @@ -77,11 +78,13 @@ setenv(name, value, rewrite) for (*C++ = '='; *C++ = *value++;); return(0); } +#endif /* * unsetenv(name) -- * Delete environmental variable "name". */ +#ifndef HAVE_UNSETENV void unsetenv(name) char *name; @@ -96,6 +99,7 @@ unsetenv(name) if (!(*P = *(P + 1))) break; } +#endif /* * Copyright (c) 1987 Regents of the University of California. * All rights reserved. @@ -119,6 +123,7 @@ unsetenv(name) * getenv -- * Returns ptr to value associated with name, if any, else NULL. */ +#ifndef HAVE_GETENV char * getenv(name) char *name; @@ -128,6 +133,7 @@ getenv(name) return(_findenv(name, &offset)); } +#endif /* * _findenv -- @@ -136,9 +142,8 @@ getenv(name) * environmental array, for use by setenv(3) and unsetenv(3). * Explicitly removes '=' in argument name. * - * This routine *should* be a static; don't use it. */ -char * +static char * _findenv(name, offset) register char *name; int *offset; diff --git a/src/config-files/ChangeLog b/src/config-files/ChangeLog index 198614d..ef47129 100644 --- a/src/config-files/ChangeLog +++ b/src/config-files/ChangeLog @@ -1,3 +1,13 @@ +2001-01-30 Ken Raeburn + + * krb5.conf.M: Update description of safe_checksum_type for recent + changes. + +2000-05-31 Ken Raeburn + + * krb5.conf.M: Added description of v4_realm from Booker + C. Bense. + 2000-01-21 Ken Raeburn * krb5.conf: Put primary KDC for Cygnus first. Add GNU.ORG diff --git a/src/config-files/krb5.conf.M b/src/config-files/krb5.conf.M index 143601e..3ca1a6a 100644 --- a/src/config-files/krb5.conf.M +++ b/src/config-files/krb5.conf.M @@ -136,15 +136,18 @@ earlier. This allows you to set the checksum type used in the authenticator of KRB_AP_REQ messages. The default value for this type is CKSUMTYPE_RSA_MD5. For compatibility with applications linked against -DCE Kerberos libraries, use a value of 2 to use the CKSUMTYPE_RSA_MD4 -instead. This applies to DCE 1.1 and earlier. +DCE version 1.1 or earlier Kerberos libraries, use a value of 2 to use +the CKSUMTYPE_RSA_MD4 +instead. .IP safe_checksum_type -This allows you to set the keyed-checksum type used in KRB_SAFE +This allows you to set the preferred keyed-checksum type for use in KRB_SAFE messages. The default value for this type is CKSUMTYPE_RSA_MD5_DES. -For compatibility with applications linked against DCE Kerberos +For compatibility with applications linked against DCE version 1.1 or +earlier Kerberos libraries, use a value of 3 to use the CKSUMTYPE_RSA_MD4_DES -instead. This applies to DCE 1.1 and earlier. +instead. This field is ignored when its value is incompatible with +the session key type. .IP ccache_type User this parameter on systems which are DCE clients, to specify the @@ -179,6 +182,7 @@ subsection define the properties of that particular realm. For example: mit = mit.edu lithium = lithium.lcs.mit.edu } + v4_realm = LCS.MIT.EDU } .in -1i .fi @@ -208,6 +212,13 @@ default_domain mapping rule. It contains V4 instances (the tag name) which should be translated to some specific hostname (the tag value) as the second component in a Kerberos V5 principal name. +.IP v4_realm +This relation is used by the krb524 library routines when converting +a V5 principal name to a V4 principal name. It is used when V4 realm +name and the V5 realm are not the same, but still share the same +principal names and passwords. The tag value is the Kerberos V4 realm +name. + .SH DOMAIN_REALM SECTION The [domain_realm] section provides a translation from a hostname to the @@ -397,8 +408,6 @@ would look like this: NERSC.GOV = ANL.GOV NERSC.GOV = ES.NET } - - } .in -1i .fi .sp diff --git a/src/config/ChangeLog b/src/config/ChangeLog index 97bce15..56c3d9a 100644 --- a/src/config/ChangeLog +++ b/src/config/ChangeLog @@ -1,3 +1,29 @@ +2002-04-17 Danilo Almeida + + * win-pre.in: the proper #define is KRB5_DNS_LOOKUP_REALM + and not KRB5_DNS_LOOKUP_REALMS + (pullup from trunk - jaltman@columbia.edu) + +2002-04-05 Danilo Almeida + + * win-pre.in: Define KRB5_PRIVATE=1. + +2000-06-21 Danilo Almeida + + * win-pre.in: Fix up DNS build flags to correspond to new DNS + build flags. Add support for not using wshelper. + +2000-06-08 Tom Yu + + * config.guess: Update to 2000-05-30 from FSF. + + * config.sub: Update to 2000-05-30 from FSF. + +2000-05-03 Tom Yu + + * libobj.in, pre.in: Put $(LOCALINCLUDES) after $(CPPFLAGS) since + $(CPPFLAGS) should have its includes show up first. + 2000-03-01 Tom Yu * pre.in (INSTALL_SHLIB): New variable. diff --git a/src/config/config.guess b/src/config/config.guess index 98fea7b..b4faaed 100644 --- a/src/config/config.guess +++ b/src/config/config.guess @@ -1,7 +1,10 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright (C) 1992, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc. -# +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 +# Free Software Foundation, Inc. + +version='2000-05-30' + # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or @@ -22,7 +25,7 @@ # the same distribution terms that you use for the rest of that program. # Written by Per Bothner . -# The master version of this file is at the FSF in /home/gd/gnu/lib. +# Please send patches to . # # This script attempts to guess a canonical system name similar to # config.sub. If it succeeds, it prints the system name on stdout, and @@ -35,6 +38,60 @@ # (but try to keep the structure clean). # +me=`echo "$0" | sed -e 's,.*/,,'` + +usage="\ +Usage: $0 [OPTION] + +Output the configuration name of this system. + +Operation modes: + -h, --help print this help, then exit + -V, --version print version number, then exit" + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case "$1" in + --version | --vers* | -V ) + echo "$version" ; exit 0 ;; + --help | --h* | -h ) + echo "$usage"; exit 0 ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + exec >&2 + echo "$me: invalid option $1" + echo "$help" + exit 1 ;; + * ) + break ;; + esac +done + +if test $# != 0; then + echo "$me: too many arguments$help" >&2 + exit 1 +fi + +# Use $HOST_CC if defined. $CC may point to a cross-compiler +if test x"$CC_FOR_BUILD" = x; then + if test x"$HOST_CC" != x; then + CC_FOR_BUILD="$HOST_CC" + else + if test x"$CC" != x; then + CC_FOR_BUILD="$CC" + else + CC_FOR_BUILD=cc + fi + fi +fi + + # This is needed to find uname on a Pyramid OSx when run in the BSD universe. # (ghazi@noc.rutgers.edu 8/24/94.) if (test -f /.attbin/uname) >/dev/null 2>&1 ; then @@ -46,11 +103,49 @@ UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown -trap 'rm -f dummy.c dummy.o dummy; exit 1' 1 2 15 +dummy=dummy-$$ +trap 'rm -f $dummy.c $dummy.o $dummy; exit 1' 1 2 15 # Note: order is significant - the case branches are not exclusive. case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + *:NetBSD:*:*) + # Netbsd (nbsd) targets should (where applicable) match one or + # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, + # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently + # switched to ELF, *-*-netbsd* would select the old + # object file format. This provides both forward + # compatibility and a consistent mechanism for selecting the + # object file format. + # Determine the machine/vendor (is the vendor relevant). + case "${UNAME_MACHINE}" in + amiga) machine=m68k-cbm ;; + arm32) machine=arm-unknown ;; + atari*) machine=m68k-atari ;; + sun3*) machine=m68k-sun ;; + mac68k) machine=m68k-apple ;; + macppc) machine=powerpc-apple ;; + hp3[0-9][05]) machine=m68k-hp ;; + ibmrt|romp-ibm) machine=romp-ibm ;; + *) machine=${UNAME_MACHINE}-unknown ;; + esac + # The Operating System including object format. + if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ + | grep __ELF__ >/dev/null + then + # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). + # Return netbsd for either. FIX? + os=netbsd + else + os=netbsdelf + fi + # The OS release + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: + # contains redundant information, the shorter form: + # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. + echo "${machine}-${os}${release}" + exit 0 ;; alpha:OSF1:*:*) if test $UNAME_RELEASE = "V4.0"; then UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` @@ -59,46 +154,62 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - cat <dummy.s + cat <$dummy.s + .data +\$Lformat: + .byte 37,100,45,37,120,10,0 # "%d-%x\n" + + .text .globl main + .align 4 .ent main main: - .frame \$30,0,\$26,0 - .prologue 0 - .long 0x47e03d80 # implver $0 - lda \$2,259 - .long 0x47e20c21 # amask $2,$1 - srl \$1,8,\$2 - sll \$2,2,\$2 - sll \$0,3,\$0 - addl \$1,\$0,\$0 - addl \$2,\$0,\$0 - ret \$31,(\$26),1 + .frame \$30,16,\$26,0 + ldgp \$29,0(\$27) + .prologue 1 + .long 0x47e03d80 # implver \$0 + lda \$2,-1 + .long 0x47e20c21 # amask \$2,\$1 + lda \$16,\$Lformat + mov \$0,\$17 + not \$1,\$18 + jsr \$26,printf + ldgp \$29,0(\$26) + mov 0,\$16 + jsr \$26,exit .end main EOF - ${CC-cc} dummy.s -o dummy 2>/dev/null + $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null if test "$?" = 0 ; then - ./dummy - case "$?" in - 7) + case `./$dummy` in + 0-0) UNAME_MACHINE="alpha" ;; - 15) + 1-0) UNAME_MACHINE="alphaev5" ;; - 14) + 1-1) UNAME_MACHINE="alphaev56" ;; - 10) + 1-101) UNAME_MACHINE="alphapca56" ;; - 16) + 2-303) UNAME_MACHINE="alphaev6" ;; + 2-307) + UNAME_MACHINE="alphaev67" + ;; esac fi - rm -f dummy.s dummy - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr [[A-Z]] [[a-z]]` + rm -f $dummy.s $dummy + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + exit 0 ;; + Alpha\ *:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # Should we change UNAME_MACHINE based on the output of uname instead + # of the specific Alpha model? + echo alpha-pc-interix exit 0 ;; 21064:Windows_NT:50:3) echo alpha-dec-winnt3.5 @@ -106,9 +217,6 @@ EOF Amiga*:UNIX_System_V:4.0:*) echo m68k-cbm-sysv4 exit 0;; - amiga:NetBSD:*:*) - echo m68k-cbm-netbsd${UNAME_RELEASE} - exit 0 ;; amiga:OpenBSD:*:*) echo m68k-unknown-openbsd${UNAME_RELEASE} exit 0 ;; @@ -133,16 +241,16 @@ EOF wgrisc:OpenBSD:*:*) echo mipsel-unknown-openbsd${UNAME_RELEASE} exit 0 ;; + *:OS/390:*:*) + echo i370-ibm-openedition + exit 0 ;; arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) echo arm-acorn-riscix${UNAME_RELEASE} exit 0;; - arm32:NetBSD:*:*) - echo arm-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` - exit 0 ;; SR2?01:HI-UX/MPP:*:*) echo hppa1.1-hitachi-hiuxmpp exit 0;; - Pyramid*:OSx*:*:*|MIS*:OSx*:*:*|MIS*:SMP_DC-OSx*:*:*) + Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. if test "`(/bin/universe) 2>/dev/null`" = att ; then echo pyramid-pyramid-sysv3 @@ -150,7 +258,7 @@ EOF echo pyramid-pyramid-bsd fi exit 0 ;; - NILE:*:*:dcosx) + NILE*:*:*:dcosx) echo pyramid-pyramid-svr4 exit 0 ;; sun4H:SunOS:5.*:*) @@ -195,21 +303,38 @@ EOF aushp:SunOS:*:*) echo sparc-auspex-sunos${UNAME_RELEASE} exit 0 ;; - atari*:NetBSD:*:*) - echo m68k-atari-netbsd${UNAME_RELEASE} - exit 0 ;; atari*:OpenBSD:*:*) echo m68k-unknown-openbsd${UNAME_RELEASE} exit 0 ;; - sun3*:NetBSD:*:*) - echo m68k-sun-netbsd${UNAME_RELEASE} + # The situation for MiNT is a little confusing. The machine name + # can be virtually everything (everything which is not + # "atarist" or "atariste" at least should have a processor + # > m68000). The system name ranges from "MiNT" over "FreeMiNT" + # to the lowercase version "mint" (or "freemint"). Finally + # the system name "TOS" denotes a system which is actually not + # MiNT. But MiNT is downward compatible to TOS, so this should + # be no problem. + atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} + exit 0 ;; + *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) + echo m68k-atari-mint${UNAME_RELEASE} exit 0 ;; + milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) + echo m68k-milan-mint${UNAME_RELEASE} + exit 0 ;; + hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) + echo m68k-hades-mint${UNAME_RELEASE} + exit 0 ;; + *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) + echo m68k-unknown-mint${UNAME_RELEASE} + exit 0 ;; sun3*:OpenBSD:*:*) echo m68k-unknown-openbsd${UNAME_RELEASE} exit 0 ;; - mac68k:NetBSD:*:*) - echo m68k-apple-netbsd${UNAME_RELEASE} - exit 0 ;; mac68k:OpenBSD:*:*) echo m68k-unknown-openbsd${UNAME_RELEASE} exit 0 ;; @@ -222,9 +347,6 @@ EOF powerpc:machten:*:*) echo powerpc-apple-machten${UNAME_RELEASE} exit 0 ;; - macppc:NetBSD:*:*) - echo powerpc-apple-netbsd${UNAME_RELEASE} - exit 0 ;; RISC*:Mach:*:*) echo mips-dec-mach_bsd4.3 exit 0 ;; @@ -234,12 +356,17 @@ EOF VAX*:ULTRIX*:*:*) echo vax-dec-ultrix${UNAME_RELEASE} exit 0 ;; - 2020:CLIX:*:*) + 2020:CLIX:*:* | 2430:CLIX:*:*) echo clipper-intergraph-clix${UNAME_RELEASE} exit 0 ;; mips:*:*:UMIPS | mips:*:*:RISCos) - sed 's/^ //' << EOF >dummy.c - int main (argc, argv) int argc; char **argv; { + sed 's/^ //' << EOF >$dummy.c +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif #if defined (host_mips) && defined (MIPSEB) #if defined (SYSTYPE_SYSV) printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); @@ -254,10 +381,10 @@ EOF exit (-1); } EOF - ${CC-cc} dummy.c -o dummy \ - && ./dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ - && rm dummy.c dummy && exit 0 - rm -f dummy.c dummy + $CC_FOR_BUILD $dummy.c -o $dummy \ + && ./$dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ + && rm $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy echo mips-mips-riscos${UNAME_RELEASE} exit 0 ;; Night_Hawk:Power_UNIX:*:*) @@ -275,15 +402,18 @@ EOF AViiON:dgux:*:*) # DG/UX returns AViiON for all architectures UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 -o $UNAME_PROCESSOR = mc88110 ] ; then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx \ - -o ${TARGET_BINARY_INTERFACE}x = x ] ; then + if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] + then + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ + [ ${TARGET_BINARY_INTERFACE}x = x ] + then echo m88k-dg-dgux${UNAME_RELEASE} - else + else echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + else + echo i586-dg-dgux${UNAME_RELEASE} fi - else echo i586-dg-dgux${UNAME_RELEASE} - fi exit 0 ;; M88*:DolphinOS:*:*) # DolphinOS (SVR3) echo m88k-dolphin-sysv3 @@ -309,7 +439,7 @@ EOF exit 0 ;; *:AIX:2:3) if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then - sed 's/^ //' << EOF >dummy.c + sed 's/^ //' << EOF >$dummy.c #include main() @@ -320,8 +450,8 @@ EOF exit(0); } EOF - ${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0 - rm -f dummy.c dummy + $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy echo rs6000-ibm-aix3.2.5 elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then echo rs6000-ibm-aix3.2.4 @@ -349,7 +479,7 @@ EOF ibmrt:4.4BSD:*|romp-ibm:BSD:*) echo romp-ibm-bsd4.4 exit 0 ;; - ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC NetBSD and + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to exit 0 ;; # report: romp-ibm BSD 4.3 *:BOSX:*:*) @@ -368,25 +498,27 @@ EOF case "${UNAME_MACHINE}" in 9000/31? ) HP_ARCH=m68000 ;; 9000/[34]?? ) HP_ARCH=m68k ;; - 9000/6?? | 9000/7?? | 9000/80[24] | 9000/8?[13679] | 9000/892 ) - sed 's/^ //' << EOF >dummy.c + 9000/[678][0-9][0-9]) + sed 's/^ //' << EOF >$dummy.c + + #define _HPUX_SOURCE #include #include - + int main () { #if defined(_SC_KERNEL_BITS) long bits = sysconf(_SC_KERNEL_BITS); - #endif + #endif long cpu = sysconf (_SC_CPU_VERSION); - - switch (cpu) + + switch (cpu) { case CPU_PA_RISC1_0: puts ("hppa1.0"); break; case CPU_PA_RISC1_1: puts ("hppa1.1"); break; - case CPU_PA_RISC2_0: + case CPU_PA_RISC2_0: #if defined(_SC_KERNEL_BITS) - switch (bits) + switch (bits) { case 64: puts ("hppa2.0w"); break; case 32: puts ("hppa2.0n"); break; @@ -394,20 +526,20 @@ EOF } break; #else /* !defined(_SC_KERNEL_BITS) */ puts ("hppa2.0"); break; - #endif + #endif default: puts ("hppa1.0"); break; } exit (0); } EOF - (${CC-cc} dummy.c -o dummy 2>/dev/null ) && HP_ARCH=`./dummy` - rm -f dummy.c dummy + (CCOPTS= $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null ) && HP_ARCH=`./$dummy` + rm -f $dummy.c $dummy esac HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` echo ${HP_ARCH}-hp-hpux${HPUX_REV} exit 0 ;; 3050*:HI-UX:*:*) - sed 's/^ //' << EOF >dummy.c + sed 's/^ //' << EOF >$dummy.c #include int main () @@ -432,8 +564,8 @@ EOF exit (0); } EOF - ${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0 - rm -f dummy.c dummy + $CC_FOR_BUILD $dummy.c -o $dummy && ./$dummy && rm $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy echo unknown-hitachi-hiuxwe2 exit 0 ;; 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) @@ -442,6 +574,9 @@ EOF 9000/8??:4.3bsd:*:*) echo hppa1.0-hp-bsd exit 0 ;; + *9??*:MPE/iX:*:*) + echo hppa1.0-hp-mpeix + exit 0 ;; hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) echo hppa1.1-hp-osf exit 0 ;; @@ -458,6 +593,9 @@ EOF parisc*:Lites*:*:*) echo hppa1.1-hp-lites exit 0 ;; + hppa*:OpenBSD:*:*) + echo hppa-unknown-openbsd + exit 0 ;; C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) echo c1-convex-bsd exit 0 ;; @@ -488,37 +626,40 @@ EOF -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ exit 0 ;; CRAY*TS:*:*:*) - echo t90-cray-unicos${UNAME_RELEASE} + echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*T3E:*:*:*) + echo alpha-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' + exit 0 ;; + CRAY*SV1:*:*:*) + echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit 0 ;; CRAY-2:*:*:*) echo cray2-cray-unicos exit 0 ;; F300:UNIX_System_V:*:*) - FUJITSU_SYS=`uname -p | tr [A-Z] [a-z] | sed -e 's/\///'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` echo "f300-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit 0 ;; F301:UNIX_System_V:*:*) echo f301-fujitsu-uxpv`echo $UNAME_RELEASE | sed 's/ .*//'` exit 0 ;; - hp3[0-9][05]:NetBSD:*:*) - echo m68k-hp-netbsd${UNAME_RELEASE} - exit 0 ;; hp300:OpenBSD:*:*) echo m68k-unknown-openbsd${UNAME_RELEASE} exit 0 ;; + i?86:BSD/386:*:* | i?86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) + echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + exit 0 ;; sparc*:BSD/OS:*:*) echo sparc-unknown-bsdi${UNAME_RELEASE} exit 0 ;; - i?86:BSD/386:*:* | *:BSD/OS:*:*) - echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} + *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} exit 0 ;; *:FreeBSD:*:*) echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` exit 0 ;; - *:NetBSD:*:*) - echo ${UNAME_MACHINE}-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` - exit 0 ;; *:OpenBSD:*:*) echo ${UNAME_MACHINE}-unknown-openbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` exit 0 ;; @@ -528,6 +669,15 @@ EOF i*:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 exit 0 ;; + i*:Windows_NT*:* | Pentium*:Windows_NT*:*) + # How do we know it's Interix rather than the generic POSIX subsystem? + # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we + # UNAME_MACHINE based on the output of uname instead of i386? + echo i386-pc-interix + exit 0 ;; + i*:UWIN*:*) + echo ${UNAME_MACHINE}-pc-uwin + exit 0 ;; p*:CYGWIN*:*) echo powerpcle-unknown-cygwin exit 0 ;; @@ -538,15 +688,11 @@ EOF echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` exit 0 ;; *:Linux:*:*) - # uname on the ARM produces all sorts of strangeness, and we need to - # filter it out. - case "$UNAME_MACHINE" in - arm* | sa110*) UNAME_MACHINE="arm" ;; - esac # The BFD linker knows what the default object file format is, so - # first see if it will tell us. - ld_help_string=`ld --help 2>&1` + # first see if it will tell us. cd to the root directory to prevent + # problems with other programs or directories called `ld' in the path. + ld_help_string=`cd /; ld --help 2>&1` ld_supported_emulations=`echo $ld_help_string \ | sed -ne '/supported emulations:/!d s/[ ][ ]*/ /g @@ -554,68 +700,146 @@ EOF s/ .*// p'` case "$ld_supported_emulations" in - i?86linux) echo "${UNAME_MACHINE}-pc-linux-gnuaout" ; exit 0 ;; - i?86coff) echo "${UNAME_MACHINE}-pc-linux-gnucoff" ; exit 0 ;; - sparclinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;; - armlinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;; - m68klinux) echo "${UNAME_MACHINE}-unknown-linux-gnuaout" ; exit 0 ;; - elf32ppc) echo "powerpc-unknown-linux-gnu" ; exit 0 ;; + *ia64) + echo "${UNAME_MACHINE}-unknown-linux" + exit 0 + ;; + i?86linux) + echo "${UNAME_MACHINE}-pc-linux-gnuaout" + exit 0 + ;; + elf_i?86) + echo "${UNAME_MACHINE}-pc-linux" + exit 0 + ;; + i?86coff) + echo "${UNAME_MACHINE}-pc-linux-gnucoff" + exit 0 + ;; + sparclinux) + echo "${UNAME_MACHINE}-unknown-linux-gnuaout" + exit 0 + ;; + armlinux) + echo "${UNAME_MACHINE}-unknown-linux-gnuaout" + exit 0 + ;; + elf32arm*) + echo "${UNAME_MACHINE}-unknown-linux-gnuoldld" + exit 0 + ;; + armelf_linux*) + echo "${UNAME_MACHINE}-unknown-linux-gnu" + exit 0 + ;; + m68klinux) + echo "${UNAME_MACHINE}-unknown-linux-gnuaout" + exit 0 + ;; + elf32ppc | elf32ppclinux) + # Determine Lib Version + cat >$dummy.c < +#if defined(__GLIBC__) +extern char __libc_version[]; +extern char __libc_release[]; +#endif +main(argc, argv) + int argc; + char *argv[]; +{ +#if defined(__GLIBC__) + printf("%s %s\n", __libc_version, __libc_release); +#else + printf("unkown\n"); +#endif + return 0; +} +EOF + LIBC="" + $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null + if test "$?" = 0 ; then + ./$dummy | grep 1\.99 > /dev/null + if test "$?" = 0 ; then + LIBC="libc1" + fi + fi + rm -f $dummy.c $dummy + echo powerpc-unknown-linux-gnu${LIBC} + exit 0 + ;; + shelf_linux) + echo "${UNAME_MACHINE}-unknown-linux-gnu" + exit 0 + ;; esac if test "${UNAME_MACHINE}" = "alpha" ; then - sed 's/^ //' <dummy.s - .globl main - .ent main - main: - .frame \$30,0,\$26,0 - .prologue 0 - .long 0x47e03d80 # implver $0 - lda \$2,259 - .long 0x47e20c21 # amask $2,$1 - srl \$1,8,\$2 - sll \$2,2,\$2 - sll \$0,3,\$0 - addl \$1,\$0,\$0 - addl \$2,\$0,\$0 - ret \$31,(\$26),1 - .end main + cat <$dummy.s + .data + \$Lformat: + .byte 37,100,45,37,120,10,0 # "%d-%x\n" + + .text + .globl main + .align 4 + .ent main + main: + .frame \$30,16,\$26,0 + ldgp \$29,0(\$27) + .prologue 1 + .long 0x47e03d80 # implver \$0 + lda \$2,-1 + .long 0x47e20c21 # amask \$2,\$1 + lda \$16,\$Lformat + mov \$0,\$17 + not \$1,\$18 + jsr \$26,printf + ldgp \$29,0(\$26) + mov 0,\$16 + jsr \$26,exit + .end main EOF LIBC="" - ${CC-cc} dummy.s -o dummy 2>/dev/null + $CC_FOR_BUILD $dummy.s -o $dummy 2>/dev/null if test "$?" = 0 ; then - ./dummy - case "$?" in - 7) + case `./$dummy` in + 0-0) UNAME_MACHINE="alpha" ;; - 15) + 1-0) UNAME_MACHINE="alphaev5" ;; - 14) + 1-1) UNAME_MACHINE="alphaev56" ;; - 10) + 1-101) UNAME_MACHINE="alphapca56" ;; - 16) + 2-303) UNAME_MACHINE="alphaev6" ;; - esac + 2-307) + UNAME_MACHINE="alphaev67" + ;; + esac - objdump --private-headers dummy | \ + objdump --private-headers $dummy | \ grep ld.so.1 > /dev/null if test "$?" = 0 ; then LIBC="libc1" fi - fi - rm -f dummy.s dummy + fi + rm -f $dummy.s $dummy echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} ; exit 0 elif test "${UNAME_MACHINE}" = "mips" ; then - cat >dummy.c <$dummy.c < /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif #ifdef __MIPSEB__ printf ("%s-unknown-linux-gnu\n", argv[1]); #endif @@ -625,8 +849,10 @@ main(argc, argv) return 0; } EOF - ${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0 - rm -f dummy.c dummy + $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy + elif test "${UNAME_MACHINE}" = "s390"; then + echo s390-ibm-linux && exit 0 else # Either a pre-BFD a.out linker (linux-gnuoldld) # or one that does not give us useful --help. @@ -645,12 +871,14 @@ EOF ;; esac # Determine whether the default compiler is a.out or elf - cat >dummy.c <$dummy.c < -main(argc, argv) - int argc; - char *argv[]; -{ +#ifdef __cplusplus +#include /* for printf() prototype */ + int main (int argc, char *argv[]) { +#else + int main (argc, argv) int argc; char *argv[]; { +#endif #ifdef __ELF__ # ifdef __GLIBC__ # if __GLIBC__ >= 2 @@ -667,8 +895,8 @@ main(argc, argv) return 0; } EOF - ${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy "${UNAME_MACHINE}" && rm dummy.c dummy && exit 0 - rm -f dummy.c dummy + $CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy "${UNAME_MACHINE}" && rm $dummy.c $dummy && exit 0 + rm -f $dummy.c $dummy fi ;; # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. earlier versions # are messed up and put the nodename in both sysname and nodename. @@ -684,10 +912,20 @@ EOF echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} exit 0 ;; i?86:*:4.*:* | i?86:SYSTEM_V:4.*:*) + UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - echo ${UNAME_MACHINE}-univel-sysv${UNAME_RELEASE} + echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} + else + echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} + fi + exit 0 ;; + i?86:*:5:7*) + # Fixed at (any) Pentium or better + UNAME_MACHINE=i586 + if [ ${UNAME_SYSTEM} = "UnixWare" ] ; then + echo ${UNAME_MACHINE}-sco-sysv${UNAME_RELEASE}uw${UNAME_VERSION} else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_RELEASE} + echo ${UNAME_MACHINE}-pc-sysv${UNAME_RELEASE} fi exit 0 ;; i?86:*:3.2:*) @@ -699,19 +937,20 @@ EOF (/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486 (/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \ && UNAME_MACHINE=i586 + (/bin/uname -X|egrep '^Machine.*Pent ?II' >/dev/null) \ + && UNAME_MACHINE=i686 + (/bin/uname -X|egrep '^Machine.*Pentium Pro' >/dev/null) \ + && UNAME_MACHINE=i686 echo ${UNAME_MACHINE}-pc-sco$UNAME_REL else echo ${UNAME_MACHINE}-pc-sysv32 fi exit 0 ;; - i?86:UnixWare:*:*) - if /bin/uname -X 2>/dev/null >/dev/null ; then - (/bin/uname -X|egrep '^Machine.*Pentium' >/dev/null) \ - && UNAME_MACHINE=i586 - fi - echo ${UNAME_MACHINE}-unixware-${UNAME_RELEASE}-${UNAME_VERSION} + i?86:*DOS:*:*) + echo ${UNAME_MACHINE}-pc-msdosdjgpp exit 0 ;; pc:*:*:*) + # Left here for compatibility: # uname -m prints for DJGPP always 'pc', but it prints nothing about # the processor, so we play safe by assuming i386. echo i386-pc-msdosdjgpp @@ -752,7 +991,7 @@ EOF mc68030:UNIX_System_V:4.*:*) echo m68k-atari-sysv4 exit 0 ;; - i?86:LynxOS:2.*:*) + i?86:LynxOS:2.*:* | i?86:LynxOS:3.[01]*:*) echo i386-unknown-lynxos${UNAME_RELEASE} exit 0 ;; TSUNAMI:LynxOS:2.*:*) @@ -764,6 +1003,9 @@ EOF SM[BE]S:UNIX_SV:*:*) echo mips-dde-sysv${UNAME_RELEASE} exit 0 ;; + RM*:ReliantUNIX-*:*:*) + echo mips-sni-sysv4 + exit 0 ;; RM*:SINIX-*:*:*) echo mips-sni-sysv4 exit 0 ;; @@ -794,7 +1036,7 @@ EOF news*:NEWS-OS:*:6*) echo mips-sony-newsos6 exit 0 ;; - R3000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R4000:UNIX_SV:*:*) + R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) if [ -d /usr/nec ]; then echo mips-nec-sysv${UNAME_RELEASE} else @@ -810,28 +1052,45 @@ EOF BePC:BeOS:*:*) # BeOS running on Intel PC compatible. echo i586-pc-beos exit 0 ;; -# MIT addition - Power\ Macintosh:Rhapsody:*:*) - echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit 0 ;; -# MIT addition - powerpc:Rhapsody:*:*) - echo powerpc-unknown-rhapsody${UNAME_RELEASE} - exit 0 ;; -# MIT addition - i?86:Rhapsody:*:*) - echo i386-unknown-rhapsody${UNAME_RELEASE} - exit 0 ;; -# MIT addition - Power\ Macintosh:Mac\ OS:*:*) - echo powerpc-apple-macos${UNAME_RELEASE} + SX-4:SUPER-UX:*:*) + echo sx4-nec-superux${UNAME_RELEASE} + exit 0 ;; + SX-5:SUPER-UX:*:*) + echo sx5-nec-superux${UNAME_RELEASE} + exit 0 ;; + Power*:Rhapsody:*:*) + echo powerpc-apple-rhapsody${UNAME_RELEASE} + exit 0 ;; + *:Rhapsody:*:*) + echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} + exit 0 ;; + *:Darwin:*:*) + echo `uname -p`-apple-darwin${UNAME_RELEASE} + exit 0 ;; + *:procnto*:*:* | *:QNX:[0123456789]*:*) + if test "${UNAME_MACHINE}" = "x86pc"; then + UNAME_MACHINE=pc + fi + echo `uname -p`-${UNAME_MACHINE}-nto-qnx + exit 0 ;; + *:QNX:*:4*) + echo i386-pc-qnx + exit 0 ;; + NSR-W:NONSTOP_KERNEL:*:*) + echo nsr-tandem-nsk${UNAME_RELEASE} + exit 0 ;; + BS2000:POSIX*:*:*) + echo bs2000-siemens-sysv + exit 0 ;; + DS/*:UNIX_System_V:*:*) + echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} exit 0 ;; esac #echo '(No uname command or uname output not recognized.)' 1>&2 #echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 -cat >dummy.c <$dummy.c < # include @@ -869,7 +1128,10 @@ main () #endif int version; version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; - printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + if (version < 4) + printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); + else + printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); exit (0); #endif @@ -929,8 +1191,8 @@ main () } EOF -${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy && rm dummy.c dummy && exit 0 -rm -f dummy.c dummy +$CC_FOR_BUILD $dummy.c -o $dummy 2>/dev/null && ./$dummy && rm $dummy.c $dummy && exit 0 +rm -f $dummy.c $dummy # Apollos put the system type in the environment. @@ -962,6 +1224,47 @@ then esac fi -#echo '(Unable to guess system type)' 1>&2 +cat >&2 < in order to provide the needed +information to handle your system. + +config.guess version = $version + +uname -m = `(uname -m) 2>/dev/null || echo unknown` +uname -r = `(uname -r) 2>/dev/null || echo unknown` +uname -s = `(uname -s) 2>/dev/null || echo unknown` +uname -v = `(uname -v) 2>/dev/null || echo unknown` + +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` +/bin/uname -X = `(/bin/uname -X) 2>/dev/null` + +hostinfo = `(hostinfo) 2>/dev/null` +/bin/universe = `(/bin/universe) 2>/dev/null` +/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` +/bin/arch = `(/bin/arch) 2>/dev/null` +/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` + +UNAME_MACHINE = ${UNAME_MACHINE} +UNAME_RELEASE = ${UNAME_RELEASE} +UNAME_SYSTEM = ${UNAME_SYSTEM} +UNAME_VERSION = ${UNAME_VERSION} +EOF exit 1 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "version='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/src/config/config.sub b/src/config/config.sub index 9952634..cb86fe1 100644 --- a/src/config/config.sub +++ b/src/config/config.sub @@ -1,6 +1,10 @@ #! /bin/sh # Configuration validation subroutine script, version 1.1. -# Copyright (C) 1991, 92-97, 1998 Free Software Foundation, Inc. +# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000 +# Free Software Foundation, Inc. + +version='2000-05-31' + # This file is (in principle) common to ALL GNU software. # The presence of a machine in this file suggests that SOME GNU software # can handle that machine. It does not imply ALL GNU software can. @@ -25,6 +29,9 @@ # configuration script generated by Autoconf, you may include it under # the same distribution terms that you use for the rest of that program. +# Written by Per Bothner . +# Please send patches to . +# # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. # If it is invalid, we print an error message on stderr and exit with code 1. @@ -45,30 +52,61 @@ # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM # It is wrong to echo any other type of specification. -if [ x$1 = x ] -then - echo Configuration name missing. 1>&2 - echo "Usage: $0 CPU-MFR-OPSYS" 1>&2 - echo "or $0 ALIAS" 1>&2 - echo where ALIAS is a recognized configuration type. 1>&2 - exit 1 -fi +me=`echo "$0" | sed -e 's,.*/,,'` -# First pass through any local machine types. -case $1 in - *local*) - echo $1 - exit 0 - ;; - *) - ;; +usage="\ +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS + +Canonicalize a configuration name. + +Operation modes: + -h, --help print this help, then exit + -V, --version print version number, then exit" + +help=" +Try \`$me --help' for more information." + +# Parse command line +while test $# -gt 0 ; do + case "$1" in + --version | --vers* | -V ) + echo "$version" ; exit 0 ;; + --help | --h* | -h ) + echo "$usage"; exit 0 ;; + -- ) # Stop option processing + shift; break ;; + - ) # Use stdin as input. + break ;; + -* ) + exec >&2 + echo "$me: invalid option $1" + echo "$help" + exit 1 ;; + + *local*) + # First pass through any local machine types. + echo $1 + exit 0;; + + * ) + break ;; + esac +done + +case $# in + 0) echo "$me: missing argument$help" >&2 + exit 1;; + 1) ;; + *) echo "$me: too many arguments$help" >&2 + exit 1;; esac # Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). # Here we must recognize all the valid KERNEL-OS combinations. maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` case $maybe_os in - linux-gnu*) + nto-qnx* | linux-gnu*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` ;; @@ -98,11 +136,21 @@ case $os in os= basic_machine=$1 ;; + -sim | -cisco | -oki | -wec | -winbond) + os= + basic_machine=$1 + ;; + -scout) + ;; + -wrs) + os=-vxworks + basic_machine=$1 + ;; -hiux*) os=-hiuxwe2 ;; -sco5) - os=sco3.2v5 + os=-sco3.2v5 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; -sco4) @@ -121,6 +169,9 @@ case $os in os=-sco3.2v2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` ;; + -udk*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` + ;; -isc) os=-isc2.2 basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` @@ -143,22 +194,36 @@ case $os in -psos*) os=-psos ;; + -mint | -mint[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; esac # Decode aliases for certain CPU-COMPANY combinations. case $basic_machine in # Recognize the basic CPU types without company name. # Some are omitted here because they have special meanings below. - tahoe | i860 | m32r | m68k | m68000 | m88k | ns32k | arc | arm \ + tahoe | i860 | ia64 | m32r | m68k | m68000 | m88k | ns32k | arc | arm \ | arme[lb] | pyramid | mn10200 | mn10300 | tron | a29k \ - | 580 | i960 | h8300 | hppa | hppa1.0 | hppa1.1 | hppa2.0 \ - | alpha | alphaev5 | alphaev56 | we32k | ns16k | clipper \ - | i370 | sh | powerpc | powerpcle | 1750a | dsp16xx | pdp11 \ - | mips64 | mipsel | mips64el | mips64orion | mips64orionel \ - | mipstx39 | mipstx39el \ - | sparc | sparclet | sparclite | sparc64 | v850) + | 580 | i960 | h8300 \ + | x86 | ppcbe | mipsbe | mipsle | shbe | shle | armbe | armle \ + | hppa | hppa1.0 | hppa1.1 | hppa2.0 | hppa2.0w | hppa2.0n \ + | hppa64 \ + | alpha | alphaev[4-8] | alphaev56 | alphapca5[67] \ + | alphaev6[78] \ + | we32k | ns16k | clipper | i370 | sh | powerpc | powerpcle \ + | 1750a | dsp16xx | pdp11 | mips16 | mips64 | mipsel | mips64el \ + | mips64orion | mips64orionel | mipstx39 | mipstx39el \ + | mips64vr4300 | mips64vr4300el | mips64vr4100 | mips64vr4100el \ + | mips64vr5000 | miprs64vr5000el | mcore \ + | sparc | sparclet | sparclite | sparc64 | sparcv9 | v850 | c4x \ + | thumb | d10v | fr30 | avr) basic_machine=$basic_machine-unknown ;; + m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | z8k | v70 | h8500 | w65 | pj | pjl) + ;; + # We use `pc' rather than `unknown' # because (1) that's what they normally are, and # (2) the word "unknown" tends to confuse beginning users. @@ -171,27 +236,49 @@ case $basic_machine in exit 1 ;; # Recognize the basic CPU types with company name. - vax-* | tahoe-* | i[34567]86-* | i860-* | m32r-* | m68k-* | m68000-* \ + # FIXME: clean up the formatting here. + vax-* | tahoe-* | i[34567]86-* | i860-* | ia64-* | m32r-* | m68k-* | m68000-* \ | m88k-* | sparc-* | ns32k-* | fx80-* | arc-* | arm-* | c[123]* \ | mips-* | pyramid-* | tron-* | a29k-* | romp-* | rs6000-* \ - | power-* | none-* | 580-* | cray2-* | h8300-* | i960-* \ - | xmp-* | ymp-* | hppa-* | hppa1.0-* | hppa1.1-* | hppa2.0-* \ - | alpha-* | alphaev5-* | alphaev56-* | we32k-* | cydra-* \ - | ns16k-* | pn-* | np1-* | xps100-* | clipper-* | orion-* \ + | power-* | none-* | 580-* | cray2-* | h8300-* | h8500-* | i960-* \ + | xmp-* | ymp-* \ + | x86-* | ppcbe-* | mipsbe-* | mipsle-* | shbe-* | shle-* | armbe-* | armle-* \ + | hppa-* | hppa1.0-* | hppa1.1-* | hppa2.0-* | hppa2.0w-* \ + | hppa2.0n-* | hppa64-* \ + | alpha-* | alphaev[4-8]-* | alphaev56-* | alphapca5[67]-* \ + | alphaev6[78]-* \ + | we32k-* | cydra-* | ns16k-* | pn-* | np1-* | xps100-* \ + | clipper-* | orion-* \ | sparclite-* | pdp11-* | sh-* | powerpc-* | powerpcle-* \ - | sparc64-* | mips64-* | mipsel-* \ - | mips64el-* | mips64orion-* | mips64orionel-* \ - | mipstx39-* | mipstx39el-* \ - | f301-*) + | sparc64-* | sparcv9-* | sparc86x-* | mips16-* | mips64-* | mipsel-* \ + | mips64el-* | mips64orion-* | mips64orionel-* \ + | mips64vr4100-* | mips64vr4100el-* | mips64vr4300-* | mips64vr4300el-* \ + | mipstx39-* | mipstx39el-* | mcore-* \ + | f301-* | armv*-* | s390-* | sv1-* | t3e-* \ + | m88110-* | m680[01234]0-* | m683?2-* | m68360-* | z8k-* | d10v-* \ + | thumb-* | v850-* | d30v-* | tic30-* | c30-* | fr30-* \ + | bs2000-*) ;; # Recognize the various machine names and aliases which stand # for a CPU type and a company and sometimes even an OS. + 386bsd) + basic_machine=i386-unknown + os=-bsd + ;; 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) basic_machine=m68000-att ;; 3b*) basic_machine=we32k-att ;; + a29khif) + basic_machine=a29k-amd + os=-udi + ;; + adobe68k) + basic_machine=m68010-adobe + os=-scout + ;; alliant | fx80) basic_machine=fx80-alliant ;; @@ -221,6 +308,10 @@ case $basic_machine in basic_machine=m68k-apollo os=-sysv ;; + apollo68bsd) + basic_machine=m68k-apollo + os=-bsd + ;; aux) basic_machine=m68k-apple os=-aux @@ -297,6 +388,10 @@ case $basic_machine in encore | umax | mmax) basic_machine=ns32k-encore ;; + es1800 | OSE68k | ose68k | ose | OSE) + basic_machine=m68k-ericsson + os=-ose + ;; fx2800) basic_machine=i860-alliant ;; @@ -315,6 +410,14 @@ case $basic_machine in basic_machine=h8300-hitachi os=-hms ;; + h8300xray) + basic_machine=h8300-hitachi + os=-xray + ;; + h8500hms) + basic_machine=h8500-hitachi + os=-hms + ;; harris) basic_machine=m88k-harris os=-sysv3 @@ -330,13 +433,30 @@ case $basic_machine in basic_machine=m68k-hp os=-hpux ;; + hp3k9[0-9][0-9] | hp9[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; hp9k2[0-9][0-9] | hp9k31[0-9]) basic_machine=m68000-hp ;; hp9k3[2-9][0-9]) basic_machine=m68k-hp ;; - hp9k7[0-9][0-9] | hp7[0-9][0-9] | hp9k8[0-9]7 | hp8[0-9]7) + hp9k6[0-9][0-9] | hp6[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + hp9k7[0-79][0-9] | hp7[0-79][0-9]) + basic_machine=hppa1.1-hp + ;; + hp9k78[0-9] | hp78[0-9]) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) + # FIXME: really hppa2.0-hp + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][13679] | hp8[0-9][13679]) basic_machine=hppa1.1-hp ;; hp9k8[0-9][0-9] | hp8[0-9][0-9]) @@ -345,9 +465,16 @@ case $basic_machine in hppa-next) os=-nextstep3 ;; + hppaosf) + basic_machine=hppa1.1-hp + os=-osf + ;; + hppro) + basic_machine=hppa1.1-hp + os=-proelf + ;; i370-ibm* | ibm*) basic_machine=i370-ibm - os=-mvs ;; # I'm not sure what "Sysv32" means. Should this be sysv3.2? i[34567]86v32) @@ -366,6 +493,22 @@ case $basic_machine in basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` os=-solaris2 ;; + i386mach) + basic_machine=i386-mach + os=-mach + ;; + i386-vsta | vsta) + basic_machine=i386-unknown + os=-vsta + ;; + i386-go32 | go32) + basic_machine=i386-unknown + os=-go32 + ;; + i386-mingw32 | mingw32) + basic_machine=i386-unknown + os=-mingw32 + ;; iris | iris4d) basic_machine=mips-sgi case $os in @@ -394,6 +537,10 @@ case $basic_machine in miniframe) basic_machine=m68000-convergent ;; + *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) + basic_machine=m68k-atari + os=-mint + ;; mipsel*-linux*) basic_machine=mipsel-unknown os=-linux-gnu @@ -408,10 +555,34 @@ case $basic_machine in mips3*) basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown ;; + mmix*) + basic_machine=mmix-knuth + os=-mmixware + ;; + monitor) + basic_machine=m68k-rom68k + os=-coff + ;; + msdos) + basic_machine=i386-unknown + os=-msdos + ;; + mvs) + basic_machine=i370-ibm + os=-mvs + ;; ncr3000) basic_machine=i486-ncr os=-sysv4 ;; + netbsd386) + basic_machine=i386-unknown + os=-netbsd + ;; + netwinder) + basic_machine=armv4l-rebel + os=-linux + ;; news | news700 | news800 | news900) basic_machine=m68k-sony os=-newsos @@ -424,6 +595,10 @@ case $basic_machine in basic_machine=mips-sony os=-newsos ;; + necv70) + basic_machine=v70-nec + os=-sysv + ;; next | m*-next ) basic_machine=m68k-next case $os in @@ -449,9 +624,28 @@ case $basic_machine in basic_machine=i960-intel os=-nindy ;; + mon960) + basic_machine=i960-intel + os=-mon960 + ;; np1) basic_machine=np1-gould ;; + nsr-tandem) + basic_machine=nsr-tandem + ;; + op50n-* | op60c-*) + basic_machine=hppa1.1-oki + os=-proelf + ;; + OSE68000 | ose68000) + basic_machine=m68000-ericsson + os=-ose + ;; + os68k) + basic_machine=m68k-none + os=-os68k + ;; pa-hitachi) basic_machine=hppa1.1-hitachi os=-hiuxwe2 @@ -469,19 +663,19 @@ case $basic_machine in pc532 | pc532-*) basic_machine=ns32k-pc532 ;; - pentium | p5 | k5 | nexen) + pentium | p5 | k5 | k6 | nexen) basic_machine=i586-pc ;; - pentiumpro | p6 | k6 | 6x86) + pentiumpro | p6 | 6x86 | athlon) basic_machine=i686-pc ;; pentiumii | pentium2) basic_machine=i786-pc ;; - pentium-* | p5-* | k5-* | nexen-*) + pentium-* | p5-* | k5-* | k6-* | nexen-*) basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` ;; - pentiumpro-* | p6-* | k6-* | 6x86-*) + pentiumpro-* | p6-* | 6x86-* | athlon-*) basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` ;; pentiumii-* | pentium2-*) @@ -505,12 +699,20 @@ case $basic_machine in ps2) basic_machine=i386-ibm ;; + rom68k) + basic_machine=m68k-rom68k + os=-coff + ;; rm[46]00) basic_machine=mips-siemens ;; rtpc | rtpc-*) basic_machine=romp-ibm ;; + sa29200) + basic_machine=a29k-amd + os=-udi + ;; sequent) basic_machine=i386-sequent ;; @@ -518,6 +720,10 @@ case $basic_machine in basic_machine=sh-hitachi os=-hms ;; + sparclite-wrs) + basic_machine=sparclite-wrs + os=-vxworks + ;; sps7) basic_machine=m68k-bull os=-sysv2 @@ -525,6 +731,13 @@ case $basic_machine in spur) basic_machine=spur-unknown ;; + st2000) + basic_machine=m68k-tandem + ;; + stratus) + basic_machine=i860-stratus + os=-sysv4 + ;; sun2) basic_machine=m68000-sun ;; @@ -565,10 +778,18 @@ case $basic_machine in sun386 | sun386i | roadrunner) basic_machine=i386-sun ;; + sv1) + basic_machine=sv1-cray + os=-unicos + ;; symmetry) basic_machine=i386-sequent os=-dynix ;; + t3e) + basic_machine=t3e-cray + os=-unicos + ;; tx39) basic_machine=mipstx39-unknown ;; @@ -586,6 +807,10 @@ case $basic_machine in basic_machine=a29k-nyu os=-sym1 ;; + v810 | necv810) + basic_machine=v810-nec + os=-none + ;; vaxv) basic_machine=vax-dec os=-sysv @@ -609,6 +834,14 @@ case $basic_machine in basic_machine=a29k-wrs os=-vxworks ;; + w65*) + basic_machine=w65-wdc + os=-none + ;; + w89k-*) + basic_machine=hppa1.1-winbond + os=-proelf + ;; xmp) basic_machine=xmp-cray os=-unicos @@ -616,6 +849,10 @@ case $basic_machine in xps | xps100) basic_machine=xps100-honeywell ;; + z8k-*-coff) + basic_machine=z8k-unknown + os=-sim + ;; none) basic_machine=none-none os=-none @@ -623,6 +860,15 @@ case $basic_machine in # Here we handle the default manufacturer of certain CPU types. It is in # some cases the only manufacturer, in others, it is the most popular. + w89k) + basic_machine=hppa1.1-winbond + ;; + op50n) + basic_machine=hppa1.1-oki + ;; + op60c) + basic_machine=hppa1.1-oki + ;; mips) if [ x$os = x-linux-gnu ]; then basic_machine=mips-unknown @@ -645,7 +891,7 @@ case $basic_machine in we32k) basic_machine=we32k-att ;; - sparc) + sparc | sparcv9) basic_machine=sparc-sun ;; cydra) @@ -657,6 +903,16 @@ case $basic_machine in orion105) basic_machine=clipper-highlevel ;; + mac | mpw | mac-mpw) + basic_machine=m68k-apple + ;; + pmac | pmac-mpw) + basic_machine=powerpc-apple + ;; + c4x*) + basic_machine=c4x-none + os=-coff + ;; *) echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 exit 1 @@ -710,13 +966,34 @@ case $os in | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \ - | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* \ + | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -macos* | -rhapsody*) + | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ + | -interix* | -uwin* | -rhapsody* | -darwin* | -opened* \ + | -openstep* | -oskit*) # Remember, each alternative MUST END IN *, to match a version number. ;; + -qnx*) + case $basic_machine in + x86-* | i[34567]86-*) + ;; + *) + os=-nto$os + ;; + esac + ;; + -nto*) + os=-nto-qnx + ;; + -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ + | -windows* | -osx | -abug | -netware* | -os9* | -beos* \ + | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) + ;; + -mac*) + os=`echo $os | sed -e 's|mac|macos|'` + ;; -linux*) os=`echo $os | sed -e 's|linux|linux-gnu|'` ;; @@ -726,6 +1003,12 @@ case $os in -sunos6*) os=`echo $os | sed -e 's|sunos6|solaris3|'` ;; + -opened*) + os=-openedition + ;; + -wince*) + os=-wince + ;; -osfrose*) os=-osfrose ;; @@ -741,12 +1024,18 @@ case $os in -acis*) os=-aos ;; + -386bsd) + os=-bsd + ;; -ctix* | -uts*) os=-sysv ;; -ns2 ) os=-nextstep2 ;; + -nsk) + os=-nsk + ;; # Preserve the version number of sinix5. -sinix5.*) os=`echo $os | sed -e 's|sinix|sysv|'` @@ -772,9 +1061,18 @@ case $os in # This must come after -sysvr4. -sysv*) ;; + -ose*) + os=-ose + ;; + -es1800*) + os=-ose + ;; -xenix) os=-xenix ;; + -*mint | -*MiNT) + os=-mint + ;; -none) ;; *) @@ -800,6 +1098,9 @@ case $basic_machine in *-acorn) os=-riscix1.2 ;; + arm*-rebel) + os=-linux + ;; arm*-semi) os=-aout ;; @@ -821,6 +1122,15 @@ case $basic_machine in # default. # os=-sunos4 ;; + m68*-cisco) + os=-aout + ;; + mips*-cisco) + os=-elf + ;; + mips*-*) + os=-elf + ;; *-tti) # must be before sparc entry or we get the wrong os. os=-sysv3 ;; @@ -833,6 +1143,15 @@ case $basic_machine in *-ibm) os=-aix ;; + *-wec) + os=-proelf + ;; + *-winbond) + os=-proelf + ;; + *-oki) + os=-proelf + ;; *-hp) os=-hpux ;; @@ -896,6 +1215,18 @@ case $basic_machine in f301-fujitsu) os=-uxpv ;; + *-rom68k) + os=-coff + ;; + *-*bug) + os=-coff + ;; + *-apple) + os=-macos + ;; + *-atari*) + os=-mint + ;; *) os=-none ;; @@ -917,9 +1248,15 @@ case $basic_machine in -aix*) vendor=ibm ;; + -beos*) + vendor=be + ;; -hpux*) vendor=hp ;; + -mpeix*) + vendor=hp + ;; -hiux*) vendor=hitachi ;; @@ -935,7 +1272,7 @@ case $basic_machine in -genix*) vendor=ns ;; - -mvs*) + -mvs* | -opened*) vendor=ibm ;; -ptx*) @@ -947,9 +1284,26 @@ case $basic_machine in -aux*) vendor=apple ;; + -hms*) + vendor=hitachi + ;; + -mpw* | -macos*) + vendor=apple + ;; + -*mint | -*MiNT) + vendor=atari + ;; esac basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` ;; esac echo $basic_machine$os +exit 0 + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "version='" +# time-stamp-format: "%:y-%02m-%02d" +# time-stamp-end: "'" +# End: diff --git a/src/config/libobj.in b/src/config/libobj.in index 5e2a2c1..0c85a59 100644 --- a/src/config/libobj.in +++ b/src/config/libobj.in @@ -29,10 +29,10 @@ PICFLAGS=@PICFLAGS@ PROFFLAGS=@PROFFLAGS@ .SUFFIXES: .c .so .po .c.so: - $(CC) $(DEFS) $(DEFINES) $(LOCALINCLUDES) $(PICFLAGS) $(CPPFLAGS) $(CFLAGS) -c $< -o $*.so.o && \ + $(CC) $(DEFS) $(DEFINES) $(PICFLAGS) $(CPPFLAGS) $(LOCALINCLUDES) $(CFLAGS) -c $< -o $*.so.o && \ $(MV) $*.so.o $*.so .c.po: - $(CC) $(DEFS) $(DEFINES) $(LOCALINCLUDES) $(PROFFLAGS) $(CPPFLAGS) $(CFLAGS) -c $< -o $*.po.o && \ + $(CC) $(DEFS) $(DEFINES) $(PROFFLAGS) $(CPPFLAGS) $(LOCALINCLUDES) $(CFLAGS) -c $< -o $*.po.o && \ $(MV) $*.po.o $*.po # rules to generate object file lists diff --git a/src/config/pre.in b/src/config/pre.in index abc3dff..cb97a47 100644 --- a/src/config/pre.in +++ b/src/config/pre.in @@ -70,7 +70,7 @@ SRCTOP = @srcdir@/$(BUILDTOP) VPATH = @srcdir@ CONFIG_RELTOPDIR = @CONFIG_RELTOPDIR@ -ALL_CFLAGS = $(DEFS) $(DEFINES) $(LOCALINCLUDES) $(CPPFLAGS) $(CFLAGS) +ALL_CFLAGS = $(DEFS) $(DEFINES) $(CPPFLAGS) $(LOCALINCLUDES) $(CFLAGS) CFLAGS = @CCOPTS@ CPPFLAGS = @CPPFLAGS@ DEFS = @DEFS@ diff --git a/src/config/win-pre.in b/src/config/win-pre.in index 73fdb2e..049ca54 100644 --- a/src/config/win-pre.in +++ b/src/config/win-pre.in @@ -83,17 +83,29 @@ C=.^\ srcdir = . SRCTOP = $(srcdir)\$(BUILDTOP) -!if defined(KRB5_USE_DNS) +!if defined(KRB5_USE_DNS) || defined(KRB5_USE_DNS_KDC) || defined(KRB5_USE_DNS_REALMS) +!if defined(KRB5_NO_WSHELPER) +DNSMSG=resolver +!else +DNSMSG=wshelper +DNSFLAGS=-DWSHELPER=1 +!endif !if !defined(DNS_INC) -!message Must define DNS_INC to point to wshelper includes dir! +!message Must define DNS_INC to point to $(DNSMSG) includes dir! !error !endif !if !defined(DNS_LIB) -!message Must define DNS_LIB to point to wshelper library! +!message Must define DNS_LIB to point to $(DNSMSG) library! !error !endif DNSLIBS=$(DNS_LIB) -DNSFLAGS=-I$(DNS_INC) -DKRB5_DNS_LOOKUP -DWSHELPER +DNSFLAGS=-I$(DNS_INC) $(DNSFLAGS) -DKRB5_DNS_LOOKUP=1 +!if defined(KRB5_USE_DNS_KDC) +DNSFLAGS=$(DNSFLAGS) -DKRB5_DNS_LOOKUP_KDC=1 +!endif +!if defined(KRB5_USE_DNS_REALMS) +DNSFLAGS=$(DNSFLAGS) -DKRB5_DNS_LOOKUP_REALM=1 +!endif !else DNSLIBS= DNSFLAGS= @@ -105,7 +117,7 @@ DNSFLAGS= CC=cl PDB_OPTS=-Fd$(OUTPRE)\ -FD -CPPFLAGS=-I$(SRCTOP)\include -I$(SRCTOP)\include\krb5 $(DNSFLAGS) +CPPFLAGS=-I$(SRCTOP)\include -I$(SRCTOP)\include\krb5 $(DNSFLAGS) -DKRB5_PRIVATE=1 CCOPTS=-nologo /W3 $(PDB_OPTS) $(DLL_FILE_DEF) LOPTS=-nologo -incremental:no diff --git a/src/configure.in b/src/configure.in index 3200c32..4516fa4 100644 --- a/src/configure.in +++ b/src/configure.in @@ -1,6 +1,15 @@ AC_INIT(aclocal.m4) CONFIG_RULES dnl +dnl Determine version from patchlevel.h +eval `sed 's/#define \([A-Z0-9_]*\)[ \t]*\(.*\)/\1=\2/' < $srcdir/patchlevel.h` +KRB5_VERSION="$KRB5_MAJOR_RELEASE.$KRB5_MINOR_RELEASE.$KRB5_PATCHLEVEL" +AC_SUBST(KRB5_VERSION) +dnl +dnl This causes us to *always* set CPP, instead of doing it below only +dnl when krb5_cv_prog_gcc isn't set. +AC_REQUIRE_CPP +dnl dnl dnl We cannot use the autoconf form as it is too generic and sets other dnl variables. This is only for the purpose of changing the link options. @@ -50,6 +59,7 @@ AC_PROG_RANLIB AC_CHECK_FUNCS(memmove) KRB5_BUILD_LIBOBJS KRB5_BUILD_LIBRARY +KRB5_BUILD_PROGRAM dnl dnl For util/makeshlib. (Is SHLIB_TAIL_COMP still necessary?!?) dnl @@ -65,6 +75,9 @@ AC_SUBST(SHLIB_TAIL_COMP) dnl dnl AC_CONFIG_SUBDIRS(util/et util/ss util/profile util/pty util/db2 include lib/crypto lib/krb5 lib/des425 $libkrb4 lib/krb5util lib/kdb lib/gssapi lib/rpc lib/kadm5 $krb524 kdc kadmin slave clients appl tests) +AC_OUTPUT_COMMANDS([chmod +x krb5-config]) +AC_OUTPUT_COMMANDS([echo timestamp > krb5-stamp-h]) +K5_GEN_FILE(krb5-config) K5_GEN_MAKEFILE(.) K5_GEN_MAKEFILE(util) K5_GEN_MAKEFILE(util/send-pr) diff --git a/src/include/ChangeLog b/src/include/ChangeLog index 928ecb1..6cb6e7b 100644 --- a/src/include/ChangeLog +++ b/src/include/ChangeLog @@ -1,3 +1,168 @@ +2002-04-16 Danilo Almeida + + * krb5.hin: Make krb5_get_host_realm() and krb5_free_host_realm() + public. + + * win-mac.h: Since this file is now only Win32, remove non-Win32 + stuff to make it easier to read. Never used __declspec(dllexport) + so that we do not accidentally export symbols. + +2002-04-05 Alexandra Ellwood + * krb5.hin: Conditionalize KRB5_CALLCONV_WRONG separately + because gssapi.h defines KRB5_CALLCONV but doesn't need + KRB5_CALLCONV_WRONG + +2002-04-05 Danilo Almeida + + * win-mac.h: Add KRB5_CALLCONV_WRONG. + + * krb5.hin: Rename krb5_kt_free_entry_contents as + krb5_free_keytab_entry_contents to make it consistent with rest of + API. Add KRB5_CALLCONV_WRONG. Fix up various calling + conventions. For Win32, add KT an CC accessors and default to not + PRIVATE. + +2002-04-03 Danilo Almeida + + * krb5.hin: Make krb5_build_principal_va() KRB5_CALLCONV. + +2002-04-03 Alexandra Ellwood + * krb5.hin: When KRB5_KEYTAB_ACCESSOR_FUNCTIONS is defined, + we still need actual definitions for krb5_kt_ops, etc defined + because krb5_kt_register uses it as a type. + Updated macros to define krb5_kt_ops when KRB5_PRIVATE is 1. + Also added a call to KRB5INT_BEGIN_DECLS so there isn't + a dangling }; in krb5.h when compiling C++ + * k5-int.h: Added krb5_kt_dfl_ops for KRB5_KEYTAB_ACCESSOR_FUNCTIONS + +2002-04-02 Ken Raeburn + + * krb5.hin (krb5_c_valid_enctype, krb5_c_valid_cksumtype, + krb5_c_is_coll_proof_cksum, krb5_c_is_keyed_cksum, + krb5_kt_free_entry_contents): New decls. + (valid_enctype, valid_cksumtype, is_coll_proof_cksum, + is_keyed_cksum, krb5_kt_free_entry): Conditionalize on + KRB5_PRIVATE. + +2002-04-02 Tom Yu + + * krb5.hin: Allow override of KRB5_PRIVATE and KRB5_DEPRECATED on + compiler command line. Make KRB5INT_BEGIN_DECLS and + KRB5INT_END_DECLS macros for C++ to keep indentation happy. Make + krb5_{enc_priv_part,priv,safe} private. Make most of rcache + functions and structs private. Hide keytab structs if + KRB5_KEYTAB_ACCESSOR_FUNCTIONS is true. + (krb5_auth_con_getcksumtype): Remove declaration for unimplemented + function. + +2002-04-02 Sam Hartman + + * krb5.hin: Merge krb5_init_keyblock from mainline + +2002-04-01 Tom Yu + + * krb5.hin: Move a whole bunch of stuff under KRB5_DEPRECATED or + KRB5_PRIVATE as a first pass for cleaning up the API. [merge from + trunk] Note that KRB5_DEPRECATED=1 by default, and KRB5_PRIVATE=1 + on all but MacOS X. + +2000-04-01 Miro Jurisic + * krb5.hin: Conditionalized krb5_kt_* macros vs. functions with + KRB5_KEYTAB_ACCESSOR_FUNCTIONS + +2002-03-28 Alexandra Ellwood + * krb5.hin: Conditionalized pragmas for Metrowerks + +2002-03-07 Alexandra Ellwood + * krb5.hin: Added check for CFM compiles. Removed dependency on + PRAGMA_* macros. + +2002-02-28 Alexandra Ellwood + * krb5.hin: Updated Mac OS X headers to new framework layout + * k5-int.h: Removed conditionals now defined in prefix files + and updated header paths + +2001-12-19 Miro Jurisic + * win-mac.h: Fixed EFBIG #define + +2001-10-29 Miro Jurisic + * pullup from krb5-1-2 branch after krb5-1-2-2-bp + * krb5.hin, k5-int.h: Condintionally use cc_* macros or functions + * krb5.hin: Changed KerberosConditionalMacros.h to + KerberosSupport.h + * k5-int.h: Rearranged the #ifdef macintosh section to + work on Mac OS 9 and X + * win-mac.h, k5-int.h, krb5.hin: Updated Mac OS #defines + and #includes for new header layout and Mac OS X frameworks + +2001-09-25 Ken Raeburn + + * krb5.hin (TKT_FLG_TRANSIT_POLICY_CHECKED, + TKT_FLG_OK_AS_DELEGATE, TKT_FLG_ANONYMOUS): New macros. + (KDC_OPT_REQUEST_ANONYMOUS, KDC_OPT_DISABLE_TRANSITED_CHECK): + Likewise. + (krb5_check_transited_list): Pointed-to krb5_data structures are + now all const. + +2000-10-16 Miro Jurisic + + * win-mac.h: #include on Mac OS + +2000-10-02 Alexandra Ellwood + + * krb5-int.h: Added warning comment about #define macintosh + +2000-09-19 Miro Jurisic + + * win-mac.h: Put #include back in + +2000-06-02 Danilo Almeida + + * krb5.hin (krb5_get_tgs_ktypes, krb5_free_ktypes): Fix linkage to + be KRB5_CALLCONV. + + * k5-int.h (krb5int_cc_default): Fix linkage to be consistent with + code. (Note: We should dump KRB5_DLLIMP.) + +2000-05-31 Ken Raeburn + + * krb5.hin (krb5_recvauth_version): Declare. + +2000-5-19 Alexandra Ellwood + + * krb5-int.h: Added krb5int_cc_default. This function supports the + Kerberos Login Library and pops up a dialog if the cache does not + contain valid tickets. This is used to automatically get a tgt before + obtaining service tickets. Note that this should be an internal function + because callers don't expect krb5_cc_default to pop up a dialog! + (We found this out the hard way :-) + +2000-05-15 Jeffrey Altman + + * krb5.hin -- Added prototypes for new public functions + + krb5_appdefault_string + krb5_appdefault_boolean + +2000-04-18 Ken Raeburn + + * krb5.hin: Declare krb5_free_ktypes. + +2000-4-13 Alexandra Ellwood + + * krb5-int.h: Added support to store a krb5_principal in the os_context + along with the default ccache name (if known, this principal is the same + as the last time we looked at the ccache. + * win-mac.h: Set up the macintosh build to use KerberosLogin. + +2000-03-25 Miro Jurisic + + * k5-int.h: Fixed protos for krb5_locate_srv_* (naddrs is int*) + +2000-03-20 Miro Jurisic + + * krb5.hin: Add krb5_free_default_realm + 2000-03-15 Danilo Almeida * krb5.hin: Add krb5_get_prompt_types() and related defs.. diff --git a/src/include/k5-int.h b/src/include/k5-int.h index 1c48809..64c2667 100644 --- a/src/include/k5-int.h +++ b/src/include/k5-int.h @@ -92,14 +92,9 @@ * Machine-type definitions: PC Clone 386 running Microloss Windows */ -#if defined(_MSDOS) || defined(_WIN32) || defined(macintosh) +#if defined(_MSDOS) || defined(_WIN32) #include "win-mac.h" -#if defined(macintosh) && defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__) -#pragma import on -#endif -#endif -#if defined(_MSDOS) || defined(_WIN32) /* Kerberos Windows initialization file */ #define KERBEROS_INI "kerberos.ini" #define INI_FILES "Files" @@ -109,10 +104,12 @@ #define ANSI_STDIO #endif - -#ifndef macintosh -#if defined(__MWERKS__) || defined(applec) || defined(THINK_C) +/* Note, this may shoot us in the foot if we switch to CW compilers for Mach-o builds */ +#if !defined(macintosh) && (defined(__MWERKS__) || defined(applec) || defined(THINK_C)) #define macintosh +#endif + +#ifdef macintosh #define SIZEOF_INT 4 #define SIZEOF_SHORT 2 #define HAVE_SRAND @@ -120,15 +117,11 @@ #define HAVE_LABS /*#define ENOMEM -1*/ #define ANSI_STDIO -#ifndef _SIZET -typedef unsigned int size_t; -#define _SIZET -#endif +#include #include #include +#include #endif -#endif - #ifndef KRB5_AUTOCONF__ #define KRB5_AUTOCONF__ @@ -511,7 +504,7 @@ krb5_error_code krb5_sendto_kdc const krb5_data *, const krb5_data *, krb5_data *, - int *)); + int)); krb5_error_code krb5_get_krbhst KRB5_PROTOTYPE((krb5_context, const krb5_data *, @@ -555,9 +548,8 @@ krb5_error_code krb5_locate_srv_conf const krb5_data *, const char *, struct sockaddr **, - int *, - int *, - int *)); + int*, + int)); /* no context? */ krb5_error_code krb5_locate_srv_dns @@ -565,7 +557,7 @@ krb5_error_code krb5_locate_srv_dns const char *, const char *, struct sockaddr **, - int *)); + int*)); #endif /* KRB5_LIBOS_PROTO__ */ @@ -788,11 +780,12 @@ KRB5_PROTOTYPE((krb5_context context, krb5_const krb5_keyblock *key, #define KRB5_LIBOS__ typedef struct _krb5_os_context { - krb5_magic magic; - krb5_int32 time_offset; - krb5_int32 usec_offset; - krb5_int32 os_flags; - char * default_ccname; + krb5_magic magic; + krb5_int32 time_offset; + krb5_int32 usec_offset; + krb5_int32 os_flags; + char * default_ccname; + krb5_principal default_ccprincipal; } *krb5_os_context; /* @@ -965,7 +958,7 @@ KRB5_PROTOTYPE((krb5_context context, krb5_get_init_creds_opt *options, krb5_gic_get_as_key_fct gak, void *gak_data, - int *master, + int master, krb5_kdc_rep **as_reply)); @@ -998,7 +991,12 @@ KRB5_DLLIMP void KRB5_CALLCONV krb5_free_pa_enc_ts KRB5_PROTOTYPE((krb5_context, krb5_pa_enc_ts FAR *)); /* #include "krb5/wordsize.h" -- comes in through base-defs.h. */ +#if TARGET_OS_MAC +#include +#include /* Not included by Kerberos/profile.h */ +#else #include "profile.h" +#endif struct _krb5_context { krb5_magic magic; @@ -1506,6 +1504,8 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_ser_unpack_bytes krb5_octet FAR * FAR *, size_t FAR *)); +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5int_cc_default + KRB5_PROTOTYPE((krb5_context, krb5_ccache FAR *)); krb5_error_code KRB5_CALLCONV krb5_cc_retrieve_cred_default KRB5_PROTOTYPE((krb5_context, krb5_ccache, krb5_flags, @@ -1529,4 +1529,53 @@ int krb5_seteuid KRB5_PROTOTYPE((int)); /* to keep lint happy */ #define krb5_xfree(val) free((char FAR *)(val)) +#if KRB5_CCACHE_ACCESSOR_FUNCTIONS +/* temporary -- this should be under lib/krb5/ccache somewhere */ + +struct _krb5_ccache { + krb5_magic magic; + struct _krb5_cc_ops FAR *ops; + krb5_pointer data; +}; + +struct _krb5_cc_ops { + krb5_magic magic; + char FAR *prefix; + char FAR * (KRB5_CALLCONV *get_name) KRB5_NPROTOTYPE((krb5_context, krb5_ccache)); + krb5_error_code (KRB5_CALLCONV *resolve) KRB5_NPROTOTYPE((krb5_context, krb5_ccache FAR *, + const char FAR *)); + krb5_error_code (KRB5_CALLCONV *gen_new) KRB5_NPROTOTYPE((krb5_context, krb5_ccache FAR *)); + krb5_error_code (KRB5_CALLCONV *init) KRB5_NPROTOTYPE((krb5_context, krb5_ccache, + krb5_principal)); + krb5_error_code (KRB5_CALLCONV *destroy) KRB5_NPROTOTYPE((krb5_context, krb5_ccache)); + krb5_error_code (KRB5_CALLCONV *close) KRB5_NPROTOTYPE((krb5_context, krb5_ccache)); + krb5_error_code (KRB5_CALLCONV *store) KRB5_NPROTOTYPE((krb5_context, krb5_ccache, + krb5_creds FAR *)); + krb5_error_code (KRB5_CALLCONV *retrieve) KRB5_NPROTOTYPE((krb5_context, krb5_ccache, + krb5_flags, krb5_creds FAR *, + krb5_creds FAR *)); + krb5_error_code (KRB5_CALLCONV *get_princ) KRB5_NPROTOTYPE((krb5_context, krb5_ccache, + krb5_principal FAR *)); + krb5_error_code (KRB5_CALLCONV *get_first) KRB5_NPROTOTYPE((krb5_context, krb5_ccache, + krb5_cc_cursor FAR *)); + krb5_error_code (KRB5_CALLCONV *get_next) KRB5_NPROTOTYPE((krb5_context, krb5_ccache, + krb5_cc_cursor FAR *, krb5_creds FAR *)); + krb5_error_code (KRB5_CALLCONV *end_get) KRB5_NPROTOTYPE((krb5_context, krb5_ccache, + krb5_cc_cursor FAR *)); + krb5_error_code (KRB5_CALLCONV *remove_cred) KRB5_NPROTOTYPE((krb5_context, krb5_ccache, + krb5_flags, krb5_creds FAR *)); + krb5_error_code (KRB5_CALLCONV *set_flags) KRB5_NPROTOTYPE((krb5_context, krb5_ccache, + krb5_flags)); +}; + +extern krb5_cc_ops *krb5_cc_dfl_ops; +#endif /* KRB5_CCACHE_ACCESSOR_FUNCTIONS */ + +#if KRB5_KEYTAB_ACCESSOR_FUNCTIONS +/* temporary -- this should be under lib/krb5/keytab somewhere */ +/* structures defined in krb5.h when KRB5_PRIVATE is 1 */ +extern krb5_kt_ops krb5_kt_dfl_ops; +#endif /* KRB5_KEYTAB_ACCESSOR_FUNCTIONS */ + + #endif /* _KRB5_INT_H */ diff --git a/src/include/kerberosIV/ChangeLog b/src/include/kerberosIV/ChangeLog index 767d835..9954dca 100644 --- a/src/include/kerberosIV/ChangeLog +++ b/src/include/kerberosIV/ChangeLog @@ -1,3 +1,18 @@ +2000-06-02 Ken Raeburn + + * krb.h (krb4_swab16): Mask upper byte of input after shifting, in + case the input value is a signed short. + +2000-05-18 Ken Raeburn + + * krb.h (krb4_swab32): Mask high byte of input value after + shifting, to avoid "time out of bounds" error when byte orders are + different and low byte of timestamp has its high bit set and the + timestamp is stored as a signed value. + + * krb.h (krb_get_err_text): Don't use "errno" as an argument + name. + Mon Mar 15 15:58:34 1999 Tom Yu * des.h: Fix GSS_DLLIMP. diff --git a/src/include/kerberosIV/krb.h b/src/include/kerberosIV/krb.h index fe8830b..4e2b675 100644 --- a/src/include/kerberosIV/krb.h +++ b/src/include/kerberosIV/krb.h @@ -340,8 +340,8 @@ typedef struct msg_dat MSG_DAT; /* * New byte swapping routines, much cleaner */ -#define krb4_swab16(val) (((val) >> 8) | ((val) << 8)) -#define krb4_swab32(val) (((val)>>24) | (((val)>>8)&0xFF00) | \ +#define krb4_swab16(val) ((((val) >> 8)&0xFF) | ((val) << 8)) +#define krb4_swab32(val) ((((val)>>24)&0xFF) | (((val)>>8)&0xFF00) | \ (((val)<<8)&0xFF0000) | ((val)<<24)) /* Kerberos ticket flag field bit definitions */ @@ -466,7 +466,7 @@ KRB5_DLLIMP int KRB5_CALLCONV dest_tkt PROTOTYPE((void)); /* err_txt.c */ KRB5_DLLIMP const char FAR * KRB5_CALLCONV krb_get_err_text - PROTOTYPE((int errno)); + PROTOTYPE((int errnum)); /* g_ad_tkt.c */ int get_ad_tkt PROTOTYPE((char *service, char *sinst, char *realm, int lifetime)); diff --git a/src/include/krb5.hin b/src/include/krb5.hin index ea8f93e..7caf42c 100644 --- a/src/include/krb5.hin +++ b/src/include/krb5.hin @@ -1,7 +1,7 @@ /* * include/krb5.h * - * Copyright 1989,1990,1995 by the Massachusetts Institute of Technology. + * Copyright 1989,1990,1995,2001 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -56,15 +56,40 @@ #ifndef KRB5_GENERAL__ #define KRB5_GENERAL__ -#if defined(_MSDOS) || defined(_WIN32) || defined(macintosh) -#include -/* Macintoh CFM-68K magic incantation */ -#if defined(macintosh) && defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__) -#pragma import on +#ifndef KRB5_DEPRECATED +#define KRB5_DEPRECATED 1 /* Expose deprecated things for now. */ +#endif + +#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__)) + #include + #if TARGET_RT_MAC_CFM + #error "Use KfM 4.0 SDK headers for CFM compilation." + #endif + + /* This is an API divergence in 1.2.3 needed for proper functioning + on Mac OS X. This will be reconciled in 1.3 */ + #define KRB5_CCACHE_ACCESSOR_FUNCTIONS 1 + #define KRB5_KEYTAB_ACCESSOR_FUNCTIONS 1 + #ifndef KRB5_PRIVATE /* Allow e.g. build system to override */ + #define KRB5_PRIVATE 0 + #endif +#else +#if defined(_WIN32) + #ifndef KRB5_PRIVATE + #define KRB5_PRIVATE 0 + #endif + #define KRB5_CCACHE_ACCESSOR_FUNCTIONS 1 + #define KRB5_KEYTAB_ACCESSOR_FUNCTIONS 1 +#else + #ifndef KRB5_PRIVATE + #define KRB5_PRIVATE 1 + #endif + #define KRB5_CCACHE_ACCESSOR_FUNCTIONS 0 + #define KRB5_KEYTAB_ACCESSOR_FUNCTIONS 0 #endif #endif -#if defined(_MSDOS) || defined(_WIN32) || defined(macintosh) +#if defined(_MSDOS) || defined(_WIN32) #include #endif @@ -80,6 +105,10 @@ #endif /* !KRB5_CALLCONV */ #endif /* !KRB5_CONFIG__ */ +#ifndef KRB5_CALLCONV_WRONG +#define KRB5_CALLCONV_WRONG +#endif + #ifndef THREEPARAMOPEN #define THREEPARAMOPEN(x,y,z) open(x,y,z) #endif @@ -95,15 +124,34 @@ * begin "error_def.h" */ -#include +#if TARGET_OS_MAC + #include +#else + #include +#endif + #include /* * end "error_def.h" */ -#ifdef __cplusplus -extern "C" { +#if defined(__cplusplus) && !defined(KRB5INT_BEGIN_DECLS) +#define KRB5INT_BEGIN_DECLS extern "C" { +#define KRB5INT_END_DECLS } +#else +#define KRB5INT_BEGIN_DECLS +#define KRB5INT_END_DECLS +#endif + +KRB5INT_BEGIN_DECLS + +#if TARGET_OS_MAC + #if defined(__MWERKS__) + #pragma import on + #pragma enumsalwaysint on + #endif + #pragma options align=mac68k #endif /* @@ -498,7 +546,17 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV #define KRB5_KEYUSAGE_GSS_TOK_WRAP_INTEG 23 #define KRB5_KEYUSAGE_GSS_TOK_WRAP_PRIV 24 +KRB5_DLLIMP krb5_boolean KRB5_CALLCONV krb5_c_valid_enctype + KRB5_PROTOTYPE((krb5_const krb5_enctype ktype)); +KRB5_DLLIMP krb5_boolean KRB5_CALLCONV krb5_c_valid_cksumtype + KRB5_PROTOTYPE((krb5_const krb5_cksumtype ctype)); +KRB5_DLLIMP krb5_boolean KRB5_CALLCONV krb5_c_is_coll_proof_cksum + KRB5_PROTOTYPE((krb5_const krb5_cksumtype ctype)); +KRB5_DLLIMP krb5_boolean KRB5_CALLCONV krb5_c_is_keyed_cksum + KRB5_PROTOTYPE((krb5_const krb5_cksumtype ctype)); +#if KRB5_PRIVATE +/* use the above four instead */ KRB5_DLLIMP krb5_boolean KRB5_CALLCONV valid_enctype KRB5_PROTOTYPE((krb5_const krb5_enctype ktype)); KRB5_DLLIMP krb5_boolean KRB5_CALLCONV valid_cksumtype @@ -507,6 +565,7 @@ KRB5_DLLIMP krb5_boolean KRB5_CALLCONV is_coll_proof_cksum KRB5_PROTOTYPE((krb5_const krb5_cksumtype ctype)); KRB5_DLLIMP krb5_boolean KRB5_CALLCONV is_keyed_cksum KRB5_PROTOTYPE((krb5_const krb5_cksumtype ctype)); +#endif #ifdef KRB5_OLD_CRYPTO /* @@ -580,6 +639,7 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_verify_checksum krb5_const krb5_pointer in, krb5_const size_t in_length, krb5_const krb5_pointer seed, krb5_const size_t seed_length)); +#if KRB5_PRIVATE KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_random_confounder KRB5_PROTOTYPE((size_t, krb5_pointer)); @@ -592,6 +652,7 @@ krb5_error_code krb5_decrypt_data KRB5_PROTOTYPE((krb5_context context, krb5_keyblock *key, krb5_pointer ivec, krb5_enc_data *data, krb5_data *enc_data)); +#endif #endif /* KRB5_OLD_CRYPTO */ @@ -620,7 +681,7 @@ krb5_error_code krb5_decrypt_data /* #define KDC_OPT_RESERVED 0x00100000 */ /* #define KDC_OPT_RESERVED 0x00080000 */ /* #define KDC_OPT_RESERVED 0x00040000 */ -/* #define KDC_OPT_RESERVED 0x00020000 */ +#define KDC_OPT_REQUEST_ANONYMOUS 0x00020000 /* #define KDC_OPT_RESERVED 0x00010000 */ /* #define KDC_OPT_RESERVED 0x00008000 */ /* #define KDC_OPT_RESERVED 0x00004000 */ @@ -632,7 +693,7 @@ krb5_error_code krb5_decrypt_data /* #define KDC_OPT_RESERVED 0x00000100 */ /* #define KDC_OPT_RESERVED 0x00000080 */ /* #define KDC_OPT_RESERVED 0x00000040 */ -/* #define KDC_OPT_RESERVED 0x00000020 */ +#define KDC_OPT_DISABLE_TRANSITED_CHECK 0x00000020 #define KDC_OPT_RENEWABLE_OK 0x00000010 #define KDC_OPT_ENC_TKT_IN_SKEY 0x00000008 /* #define KDC_OPT_UNUSED 0x00000004 */ @@ -708,9 +769,9 @@ krb5_error_code krb5_decrypt_data #define TKT_FLG_INITIAL 0x00400000 #define TKT_FLG_PRE_AUTH 0x00200000 #define TKT_FLG_HW_AUTH 0x00100000 -/* #define TKT_FLG_RESERVED 0x00080000 */ -/* #define TKT_FLG_RESERVED 0x00040000 */ -/* #define TKT_FLG_RESERVED 0x00020000 */ +#define TKT_FLG_TRANSIT_POLICY_CHECKED 0x00080000 +#define TKT_FLG_OK_AS_DELEGATE 0x00040000 +#define TKT_FLG_ANONYMOUS 0x00020000 /* #define TKT_FLG_RESERVED 0x00010000 */ /* #define TKT_FLG_RESERVED 0x00008000 */ /* #define TKT_FLG_RESERVED 0x00004000 */ @@ -1022,6 +1083,7 @@ typedef struct _krb5_response { krb5_timestamp request_time; /* When we made the request */ } krb5_response; +#if KRB5_PRIVATE typedef struct _krb5_safe { krb5_magic magic; krb5_data user_data; /* user data */ @@ -1048,6 +1110,7 @@ typedef struct _krb5_priv_enc_part { krb5_address FAR *s_address; /* sender address */ krb5_address FAR *r_address; /* recipient address, optional */ } krb5_priv_enc_part; +#endif typedef struct _krb5_cred_info { krb5_magic magic; @@ -1126,6 +1189,12 @@ typedef struct krb5_replay_data { typedef krb5_pointer krb5_cc_cursor; /* cursor for sequential lookup */ +#if KRB5_CCACHE_ACCESSOR_FUNCTIONS +struct _krb5_ccache; +typedef struct _krb5_ccache FAR *krb5_ccache; +struct _krb5_cc_ops; +typedef struct _krb5_cc_ops krb5_cc_ops; +#else typedef struct _krb5_ccache { krb5_magic magic; struct _krb5_cc_ops FAR *ops; @@ -1161,6 +1230,7 @@ typedef struct _krb5_cc_ops { krb5_error_code (KRB5_CALLCONV *set_flags) KRB5_NPROTOTYPE((krb5_context, krb5_ccache, krb5_flags)); } krb5_cc_ops; +#endif /* KRB5_CCACHE_ACCESSOR_FUNCTIONS */ /* for retrieve_cred */ #define KRB5_TC_MATCH_TIMES 0x00000001 @@ -1177,6 +1247,58 @@ typedef struct _krb5_cc_ops { /* for set_flags and other functions */ #define KRB5_TC_OPENCLOSE 0x00000001 +#if KRB5_CCACHE_ACCESSOR_FUNCTIONS +KRB5_DLLIMP const char FAR * KRB5_CALLCONV +krb5_cc_get_name (krb5_context context, krb5_ccache cache); + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_gen_new (krb5_context context, krb5_ccache FAR *cache); + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_initialize(krb5_context context, krb5_ccache cache, + krb5_principal principal); + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_destroy (krb5_context context, krb5_ccache cache); + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_close (krb5_context context, krb5_ccache cache); + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_store_cred (krb5_context context, krb5_ccache cache, + krb5_creds FAR *creds); + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_retrieve_cred (krb5_context context, krb5_ccache cache, + krb5_flags flags, krb5_creds FAR *mcreds, + krb5_creds FAR *creds); + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_get_principal (krb5_context context, krb5_ccache cache, + krb5_principal FAR *principal); + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_start_seq_get (krb5_context context, krb5_ccache cache, + krb5_cc_cursor FAR *cursor); + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_next_cred (krb5_context context, krb5_ccache cache, + krb5_cc_cursor FAR *cursor, krb5_creds FAR *creds); + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_end_seq_get (krb5_context context, krb5_ccache cache, + krb5_cc_cursor FAR *cursor); + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_remove_cred (krb5_context context, krb5_ccache cache, krb5_flags flags, + krb5_creds FAR *creds); + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_cc_set_flags (krb5_context context, krb5_ccache cache, krb5_flags flags); + +KRB5_DLLIMP const char * KRB5_CALLCONV +krb5_cc_get_type (krb5_context context, krb5_ccache cache); +#else #define krb5_cc_initialize(context, cache, principal) krb5_x ((cache)->ops->init,(context, cache, principal)) #define krb5_cc_gen_new(context, cache) krb5_x ((*cache)->ops->gen_new,(context, cache)) #define krb5_cc_destroy(context, cache) krb5_x ((cache)->ops->destroy,(context, cache)) @@ -1193,6 +1315,7 @@ typedef struct _krb5_cc_ops { #define krb5_cc_get_type(context, cache) ((cache)->ops->prefix) extern krb5_cc_ops *krb5_cc_dfl_ops; +#endif /* KRB5_CCACHE_ACCESSOR_FUNCTIONS */ /* * end "ccache.h" @@ -1202,12 +1325,18 @@ extern krb5_cc_ops *krb5_cc_dfl_ops; * begin "rcache.h" */ +#if KRB5_PRIVATE typedef struct krb5_rc_st { krb5_magic magic; struct _krb5_rc_ops FAR *ops; krb5_pointer data; } FAR *krb5_rcache; +#else +struct krb5_rc_st; +typedef struct krb5_rc_st FAR *krb5_rcache; +#endif +#if KRB5_PRIVATE typedef struct _krb5_donot_replay { krb5_magic magic; char FAR *server; /* null-terminated */ @@ -1275,6 +1404,7 @@ krb5_error_code krb5_auth_to_rep #define krb5_rc_resolve(context, id, name) krb5_x((id)->ops->resolve,(context, id, name)) extern krb5_rc_ops krb5_rc_dfl_ops; +#endif /* * end "rcache.h" @@ -1298,14 +1428,18 @@ typedef struct krb5_keytab_entry_st { krb5_keyblock key; /* the secret key */ } krb5_keytab_entry; - +#if KRB5_KEYTAB_ACCESSOR_FUNCTIONS && !KRB5_PRIVATE +/* Opaque definitions for krb5_kt_* functions */ +struct _krb5_kt; +typedef struct _krb5_kt FAR *krb5_keytab; +#else +struct _krb5_kt_ops; typedef struct _krb5_kt { krb5_magic magic; struct _krb5_kt_ops FAR *ops; krb5_pointer data; } FAR *krb5_keytab; - typedef struct _krb5_kt_ops { krb5_magic magic; char FAR *prefix; @@ -1355,7 +1489,30 @@ typedef struct _krb5_kt_ops { /* Handle for serializer */ void * serializer; } krb5_kt_ops; - +#endif /* !KRB5_KEYTAB_ACCESSOR_FUNCTIONS || KRB5_PRIVATE */ + +#if KRB5_KEYTAB_ACCESSOR_FUNCTIONS +char * KRB5_CALLCONV +krb5_kt_get_type (krb5_context, krb5_keytab keytab); +krb5_error_code KRB5_CALLCONV +krb5_kt_get_name(krb5_context context, krb5_keytab keytab, char *name, + unsigned int namelen); +krb5_error_code KRB5_CALLCONV +krb5_kt_close(krb5_context context, krb5_keytab keytab); +krb5_error_code KRB5_CALLCONV +krb5_kt_get_entry(krb5_context context, krb5_keytab keytab, + krb5_const_principal principal, krb5_kvno vno, + krb5_enctype enctype, krb5_keytab_entry *entry); +krb5_error_code KRB5_CALLCONV +krb5_kt_start_seq_get(krb5_context context, krb5_keytab keytab, + krb5_kt_cursor *cursor); +krb5_error_code KRB5_CALLCONV +krb5_kt_next_entry(krb5_context context, krb5_keytab keytab, + krb5_keytab_entry *entry, krb5_kt_cursor *cursor); +krb5_error_code KRB5_CALLCONV +krb5_kt_end_seq_get(krb5_context context, krb5_keytab keytab, + krb5_kt_cursor *cursor); +#else #define krb5_kt_get_type(context, keytab) ((keytab)->ops->prefix) #define krb5_kt_get_name(context, keytab, name, namelen) krb5_x((keytab)->ops->get_name,(context, keytab,name,namelen)) #define krb5_kt_close(context, keytab) krb5_x((keytab)->ops->close,(context, keytab)) @@ -1363,11 +1520,12 @@ typedef struct _krb5_kt_ops { #define krb5_kt_start_seq_get(context, keytab, cursor) krb5_x((keytab)->ops->start_seq_get,(context, keytab, cursor)) #define krb5_kt_next_entry(context, keytab, entry, cursor) krb5_x((keytab)->ops->get_next,(context, keytab, entry, cursor)) #define krb5_kt_end_seq_get(context, keytab, cursor) krb5_x((keytab)->ops->end_get,(context, keytab, cursor)) -/* remove and add are functions, so that they can return NOWRITE - if not a writable keytab */ - extern krb5_kt_ops krb5_kt_dfl_ops; +#endif + +/* remove and add are functions, so that they can return NOWRITE + if not a writable keytab */ /* * end "keytab.h" @@ -1384,6 +1542,7 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_init_secure_context KRB5_DLLIMP void KRB5_CALLCONV krb5_free_context KRB5_PROTOTYPE((krb5_context)); +#if KRB5_PRIVATE krb5_error_code krb5_set_default_in_tkt_ktypes KRB5_PROTOTYPE((krb5_context, krb5_const krb5_enctype *)); @@ -1394,18 +1553,29 @@ krb5_error_code krb5_get_default_in_tkt_ktypes krb5_error_code krb5_set_default_tgs_ktypes KRB5_PROTOTYPE((krb5_context, krb5_const krb5_enctype *)); -krb5_error_code krb5_get_tgs_ktypes +#endif + +krb5_error_code KRB5_CALLCONV krb5_set_default_tgs_enctypes + KRB5_PROTOTYPE((krb5_context, + krb5_const krb5_enctype *)); + +#if KRB5_PRIVATE +krb5_error_code KRB5_CALLCONV krb5_get_tgs_ktypes KRB5_PROTOTYPE((krb5_context, krb5_const_principal, krb5_enctype **)); krb5_error_code krb5_get_permitted_enctypes KRB5_PROTOTYPE((krb5_context, krb5_enctype **)); +void KRB5_CALLCONV krb5_free_ktypes + KRB5_PROTOTYPE ((krb5_context, krb5_enctype *)); krb5_boolean krb5_is_permitted_enctype KRB5_PROTOTYPE((krb5_context, krb5_enctype)); +#endif /* libkrb.spec */ +#if KRB5_PRIVATE krb5_error_code krb5_kdc_rep_decrypt_proc KRB5_PROTOTYPE((krb5_context, krb5_const krb5_keyblock *, @@ -1436,6 +1606,7 @@ krb5_error_code krb5_get_cred_from_kdc_renew krb5_creds *, krb5_creds **, krb5_creds *** )); +#endif KRB5_DLLIMP void KRB5_CALLCONV krb5_free_tgt_creds KRB5_PROTOTYPE((krb5_context, krb5_creds FAR * FAR* )); /* XXX too hard to do with const */ @@ -1461,6 +1632,7 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_get_credentials_renew krb5_ccache, krb5_creds FAR *, krb5_creds FAR * FAR *)); +#if KRB5_PRIVATE krb5_error_code krb5_get_cred_via_tkt KRB5_PROTOTYPE((krb5_context, krb5_creds *, @@ -1468,6 +1640,7 @@ krb5_error_code krb5_get_cred_via_tkt krb5_address * krb5_const *, krb5_creds *, krb5_creds **)); +#endif KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_mk_req KRB5_PROTOTYPE((krb5_context, krb5_auth_context FAR *, @@ -1530,19 +1703,19 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_unparse_name_ext KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_set_principal_realm KRB5_PROTOTYPE((krb5_context, krb5_principal, const char FAR *)); -krb5_boolean krb5_address_search +krb5_boolean KRB5_CALLCONV_WRONG krb5_address_search KRB5_PROTOTYPE((krb5_context, krb5_const krb5_address *, krb5_address * krb5_const *)); -krb5_boolean krb5_address_compare +krb5_boolean KRB5_CALLCONV krb5_address_compare KRB5_PROTOTYPE((krb5_context, krb5_const krb5_address *, krb5_const krb5_address *)); -int krb5_address_order +int KRB5_CALLCONV krb5_address_order KRB5_PROTOTYPE((krb5_context, krb5_const krb5_address *, krb5_const krb5_address *)); -krb5_boolean krb5_realm_compare +krb5_boolean KRB5_CALLCONV krb5_realm_compare KRB5_PROTOTYPE((krb5_context, krb5_const_principal, krb5_const_principal)); @@ -1550,6 +1723,15 @@ KRB5_DLLIMP krb5_boolean KRB5_CALLCONV krb5_principal_compare KRB5_PROTOTYPE((krb5_context, krb5_const_principal, krb5_const_principal)); +krb5_error_code KRB5_CALLCONV krb5_init_keyblock + (krb5_context, krb5_enctype enctype, + size_t length, krb5_keyblock **out); + /* Initialize a new keyblock and allocate storage + * for the contents of the key, which will be freed along + * with the keyblock when krb5_free_keyblock is called. + * It is legal to pass in a length of 0, in which + * case contents are left unallocated. + */ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_copy_keyblock KRB5_PROTOTYPE((krb5_context, krb5_const krb5_keyblock FAR *, @@ -1570,10 +1752,12 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_copy_principal KRB5_PROTOTYPE((krb5_context, krb5_const_principal, krb5_principal FAR *)); +#if KRB5_PRIVATE KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_copy_addr KRB5_PROTOTYPE((krb5_context, const krb5_address FAR *, krb5_address FAR * FAR *)); +#endif KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_copy_addresses KRB5_PROTOTYPE((krb5_context, krb5_address FAR * krb5_const FAR *, @@ -1594,6 +1778,7 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_copy_checksum KRB5_PROTOTYPE((krb5_context, krb5_const krb5_checksum FAR *, krb5_checksum FAR * FAR *)); +#if KRB5_PRIVATE void krb5_init_ets KRB5_PROTOTYPE((krb5_context)); void krb5_free_ets @@ -1604,6 +1789,7 @@ krb5_error_code krb5_generate_subkey krb5_error_code krb5_generate_seq_number KRB5_PROTOTYPE((krb5_context, krb5_const krb5_keyblock *, krb5_int32 *)); +#endif KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_get_server_rcache KRB5_PROTOTYPE((krb5_context, krb5_const krb5_data *, krb5_rcache *)); @@ -1613,7 +1799,7 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV_C krb5_build_principal KRB5_STDARG_P((krb5_context, krb5_principal FAR *, int, krb5_const char FAR *, ...)); #ifdef va_start /* XXX depending on varargs include file defining va_start... */ -krb5_error_code krb5_build_principal_va +krb5_error_code KRB5_CALLCONV krb5_build_principal_va KRB5_PROTOTYPE((krb5_context, krb5_principal, int, krb5_const char *, va_list)); #endif @@ -1628,6 +1814,7 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_524_conv_principal KRB5_PROTOTYPE((krb5_context context, krb5_const krb5_principal princ, char FAR *name, char FAR *inst, char FAR *realm)); +#if KRB5_PRIVATE KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_mk_chpw_req KRB5_PROTOTYPE((krb5_context context, krb5_auth_context auth_context, krb5_data *ap_req, char *passwd, krb5_data *packet)); @@ -1638,11 +1825,14 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_rd_chpw_rep KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_chpw_result_code_string KRB5_PROTOTYPE((krb5_context context, int result_code, char **result_codestr)); +#endif /* libkt.spec */ +#if KRB5_PRIVATE KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_kt_register KRB5_PROTOTYPE((krb5_context, krb5_kt_ops FAR * )); +#endif KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_kt_resolve KRB5_PROTOTYPE((krb5_context, krb5_const char FAR *, @@ -1654,9 +1844,15 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_kt_default_name KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_kt_default KRB5_PROTOTYPE((krb5_context, krb5_keytab FAR * )); +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_free_keytab_entry_contents + KRB5_PROTOTYPE((krb5_context, + krb5_keytab_entry FAR * )); +#if KRB5_PRIVATE +/* use krb5_kt_free_entry_contents instead */ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_kt_free_entry KRB5_PROTOTYPE((krb5_context, krb5_keytab_entry FAR * )); +#endif /* remove and add are functions, so that they can return NOWRITE if not a writable keytab */ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_kt_remove_entry @@ -1667,13 +1863,14 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_kt_add_entry KRB5_PROTOTYPE((krb5_context, krb5_keytab, krb5_keytab_entry FAR * )); +#if KRB5_PRIVATE krb5_error_code krb5_principal2salt KRB5_PROTOTYPE((krb5_context, krb5_const_principal, krb5_data *)); krb5_error_code krb5_principal2salt_norealm KRB5_PROTOTYPE((krb5_context, krb5_const_principal, krb5_data *)); - +#endif /* librc.spec--see rcache.h */ /* libcc.spec */ @@ -1688,8 +1885,10 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_cc_set_default_name KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_cc_default KRB5_PROTOTYPE((krb5_context, krb5_ccache FAR *)); +#if KRB5_PRIVATE KRB5_DLLIMP unsigned int KRB5_CALLCONV krb5_get_notification_message KRB5_PROTOTYPE((void)); +#endif KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_cc_copy_creds KRB5_PROTOTYPE((krb5_context context, @@ -1698,32 +1897,43 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_cc_copy_creds /* chk_trans.c */ +#if KRB5_PRIVATE krb5_error_code krb5_check_transited_list - KRB5_PROTOTYPE((krb5_context, - krb5_data *trans, krb5_data *realm1, krb5_data *realm2)); + (krb5_context, const krb5_data *trans, + const krb5_data *realm1, const krb5_data *realm2); +#endif /* free_rtree.c */ +#if KRB5_PRIVATE void krb5_free_realm_tree KRB5_PROTOTYPE((krb5_context, krb5_principal *)); +#endif /* krb5_free.c */ KRB5_DLLIMP void KRB5_CALLCONV krb5_free_principal KRB5_PROTOTYPE((krb5_context, krb5_principal )); KRB5_DLLIMP void KRB5_CALLCONV krb5_free_authenticator KRB5_PROTOTYPE((krb5_context, krb5_authenticator FAR * )); +#if KRB5_PRIVATE KRB5_DLLIMP void KRB5_CALLCONV krb5_free_authenticator_contents KRB5_PROTOTYPE((krb5_context, krb5_authenticator FAR * )); +#endif KRB5_DLLIMP void KRB5_CALLCONV krb5_free_addresses KRB5_PROTOTYPE((krb5_context, krb5_address FAR * FAR * )); +#if KRB5_PRIVATE KRB5_DLLIMP void KRB5_CALLCONV krb5_free_address KRB5_PROTOTYPE((krb5_context, krb5_address FAR * )); +#endif KRB5_DLLIMP void KRB5_CALLCONV krb5_free_authdata KRB5_PROTOTYPE((krb5_context, krb5_authdata FAR * FAR * )); +#if KRB5_PRIVATE KRB5_DLLIMP void KRB5_CALLCONV krb5_free_enc_tkt_part KRB5_PROTOTYPE((krb5_context, krb5_enc_tkt_part FAR * )); +#endif KRB5_DLLIMP void KRB5_CALLCONV krb5_free_ticket KRB5_PROTOTYPE((krb5_context, krb5_ticket FAR * )); +#if KRB5_PRIVATE KRB5_DLLIMP void KRB5_CALLCONV krb5_free_tickets KRB5_PROTOTYPE((krb5_context, krb5_ticket FAR * FAR * )); KRB5_DLLIMP void KRB5_CALLCONV krb5_free_kdc_req @@ -1734,12 +1944,18 @@ KRB5_DLLIMP void KRB5_CALLCONV krb5_free_last_req KRB5_PROTOTYPE((krb5_context, krb5_last_req_entry FAR * FAR * )); KRB5_DLLIMP void KRB5_CALLCONV krb5_free_enc_kdc_rep_part KRB5_PROTOTYPE((krb5_context, krb5_enc_kdc_rep_part FAR * )); +#endif KRB5_DLLIMP void KRB5_CALLCONV krb5_free_error KRB5_PROTOTYPE((krb5_context, krb5_error FAR * )); +#if KRB5_PRIVATE KRB5_DLLIMP void KRB5_CALLCONV krb5_free_ap_req KRB5_PROTOTYPE((krb5_context, krb5_ap_req FAR * )); KRB5_DLLIMP void KRB5_CALLCONV krb5_free_ap_rep KRB5_PROTOTYPE((krb5_context, krb5_ap_rep FAR * )); +/* + * The following 3 fns were moved to k5-int.h on trunk, so are marked + * private here. + */ KRB5_DLLIMP void KRB5_CALLCONV krb5_free_safe KRB5_PROTOTYPE((krb5_context, krb5_safe FAR * )); KRB5_DLLIMP void KRB5_CALLCONV krb5_free_priv @@ -1748,12 +1964,15 @@ KRB5_DLLIMP void KRB5_CALLCONV krb5_free_priv_enc_part KRB5_PROTOTYPE((krb5_context, krb5_priv_enc_part FAR * )); KRB5_DLLIMP void KRB5_CALLCONV krb5_free_cred KRB5_PROTOTYPE((krb5_context, krb5_cred FAR *)); +#endif KRB5_DLLIMP void KRB5_CALLCONV krb5_free_creds KRB5_PROTOTYPE((krb5_context, krb5_creds FAR *)); KRB5_DLLIMP void KRB5_CALLCONV krb5_free_cred_contents KRB5_PROTOTYPE((krb5_context, krb5_creds FAR *)); +#if KRB5_PRIVATE KRB5_DLLIMP void KRB5_CALLCONV krb5_free_cred_enc_part KRB5_PROTOTYPE((krb5_context, krb5_cred_enc_part FAR *)); +#endif KRB5_DLLIMP void KRB5_CALLCONV krb5_free_checksum KRB5_PROTOTYPE((krb5_context, krb5_checksum FAR *)); KRB5_DLLIMP void KRB5_CALLCONV krb5_free_checksum_contents @@ -1762,16 +1981,20 @@ KRB5_DLLIMP void KRB5_CALLCONV krb5_free_keyblock KRB5_PROTOTYPE((krb5_context, krb5_keyblock FAR *)); KRB5_DLLIMP void KRB5_CALLCONV krb5_free_keyblock_contents KRB5_PROTOTYPE((krb5_context, krb5_keyblock FAR *)); +#if KRB5_PRIVATE KRB5_DLLIMP void KRB5_CALLCONV krb5_free_pa_data KRB5_PROTOTYPE((krb5_context, krb5_pa_data FAR * FAR *)); +#endif KRB5_DLLIMP void KRB5_CALLCONV krb5_free_ap_rep_enc_part KRB5_PROTOTYPE((krb5_context, krb5_ap_rep_enc_part FAR *)); +#if KRB5_PRIVATE KRB5_DLLIMP void KRB5_CALLCONV krb5_free_tkt_authent KRB5_PROTOTYPE((krb5_context, krb5_tkt_authent FAR *)); KRB5_DLLIMP void KRB5_CALLCONV krb5_free_pwd_data KRB5_PROTOTYPE((krb5_context, krb5_pwd_data FAR *)); KRB5_DLLIMP void KRB5_CALLCONV krb5_free_pwd_sequences KRB5_PROTOTYPE((krb5_context, passwd_phrase_element FAR * FAR *)); +#endif KRB5_DLLIMP void KRB5_CALLCONV krb5_free_data KRB5_PROTOTYPE((krb5_context, krb5_data FAR *)); KRB5_DLLIMP void KRB5_CALLCONV krb5_free_data_contents @@ -1799,6 +2022,9 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_get_default_realm KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_set_default_realm KRB5_PROTOTYPE((krb5_context, krb5_const char FAR * )); +KRB5_DLLIMP void KRB5_CALLCONV krb5_free_default_realm + KRB5_PROTOTYPE((krb5_context, + char FAR * )); KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_sname_to_principal KRB5_PROTOTYPE((krb5_context, krb5_const char FAR *, @@ -1811,6 +2037,7 @@ krb5_change_password int *result_code, krb5_data *result_code_string, krb5_data *result_string)); +#if KRB5_PRIVATE #ifndef macintosh krb5_error_code krb5_set_config_files KRB5_PROTOTYPE ((krb5_context, krb5_const char FAR * FAR *)); @@ -1822,11 +2049,13 @@ KRB5_DLLIMP void KRB5_CALLCONV krb5_free_config_files KRB5_PROTOTYPE((char **filenames)); #endif +#endif KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_get_profile KRB5_PROTOTYPE((krb5_context, profile_t *)); +#if KRB5_PRIVATE krb5_error_code krb5_send_tgs KRB5_PROTOTYPE((krb5_context, krb5_const krb5_flags, @@ -1839,7 +2068,9 @@ krb5_error_code krb5_send_tgs krb5_const krb5_data *, krb5_creds *, krb5_response * )); +#endif +#if KRB5_DEPRECATED KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_get_in_tkt KRB5_PROTOTYPE((krb5_context, krb5_const krb5_flags, @@ -1893,13 +2124,15 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_get_in_tkt_with_keytab krb5_ccache, krb5_creds FAR *, krb5_kdc_rep FAR * FAR * )); +#endif /* KRB5_DEPRECATED */ - +#if KRB5_PRIVATE krb5_error_code krb5_decode_kdc_rep KRB5_PROTOTYPE((krb5_context, krb5_data *, krb5_const krb5_keyblock *, krb5_kdc_rep ** )); +#endif KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_rd_req KRB5_PROTOTYPE((krb5_context, @@ -1910,6 +2143,7 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_rd_req krb5_flags FAR *, krb5_ticket FAR * FAR *)); +#if KRB5_PRIVATE krb5_error_code krb5_rd_req_decoded KRB5_PROTOTYPE((krb5_context, krb5_auth_context *, @@ -1927,6 +2161,7 @@ krb5_error_code krb5_rd_req_decoded_anyflag krb5_keytab, krb5_flags *, krb5_ticket **)); +#endif KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_kt_read_service_key KRB5_PROTOTYPE((krb5_context, @@ -1947,10 +2182,12 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_mk_priv krb5_const krb5_data FAR *, krb5_data FAR *, krb5_replay_data FAR *)); +#if KRB5_PRIVATE KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_cc_register KRB5_PROTOTYPE((krb5_context, krb5_cc_ops FAR *, krb5_boolean )); +#endif KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_sendauth KRB5_PROTOTYPE((krb5_context, @@ -1976,13 +2213,24 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_recvauth krb5_int32, krb5_keytab, krb5_ticket FAR * FAR *)); +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_recvauth_version + KRB5_PROTOTYPE((krb5_context, + krb5_auth_context FAR *, + krb5_pointer, + krb5_principal, + krb5_int32, + krb5_keytab, + krb5_ticket FAR * FAR *, + krb5_data FAR *)); +#if KRB5_PRIVATE krb5_error_code krb5_walk_realm_tree KRB5_PROTOTYPE((krb5_context, krb5_const krb5_data *, krb5_const krb5_data *, krb5_principal **, int)); +#endif KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_mk_ncred KRB5_PROTOTYPE((krb5_context, @@ -2033,19 +2281,19 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_auth_con_getflags krb5_auth_context, krb5_int32 FAR *)); -krb5_error_code krb5_auth_con_setaddrs +krb5_error_code KRB5_CALLCONV_WRONG krb5_auth_con_setaddrs KRB5_PROTOTYPE((krb5_context, krb5_auth_context, krb5_address *, krb5_address *)); -krb5_error_code krb5_auth_con_getaddrs +krb5_error_code KRB5_CALLCONV krb5_auth_con_getaddrs KRB5_PROTOTYPE((krb5_context, krb5_auth_context, krb5_address **, krb5_address **)); -krb5_error_code krb5_auth_con_setports +krb5_error_code KRB5_CALLCONV krb5_auth_con_setports KRB5_PROTOTYPE((krb5_context, krb5_auth_context, krb5_address *, @@ -2066,6 +2314,7 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_auth_con_getlocalsubkey krb5_auth_context, krb5_keyblock FAR * FAR *)); +#if KRB5_PRIVATE KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_auth_con_set_req_cksumtype KRB5_PROTOTYPE((krb5_context, krb5_auth_context, @@ -2075,11 +2324,7 @@ krb5_error_code krb5_auth_con_set_safe_cksumtype KRB5_PROTOTYPE((krb5_context, krb5_auth_context, krb5_cksumtype)); - -krb5_error_code krb5_auth_con_getcksumtype - KRB5_PROTOTYPE((krb5_context, - krb5_auth_context, - krb5_cksumtype *)); +#endif KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_auth_con_getlocalseqnumber KRB5_PROTOTYPE((krb5_context, @@ -2091,10 +2336,13 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_auth_con_getremoteseqnumber krb5_auth_context, krb5_int32 FAR *)); -krb5_error_code krb5_auth_con_initivector +#if KRB5_DEPRECATED +krb5_error_code KRB5_CALLCONV krb5_auth_con_initivector KRB5_PROTOTYPE((krb5_context, krb5_auth_context)); +#endif +#if KRB5_PRIVATE krb5_error_code krb5_auth_con_setivector KRB5_PROTOTYPE((krb5_context, krb5_auth_context, @@ -2104,13 +2352,14 @@ krb5_error_code krb5_auth_con_getivector KRB5_PROTOTYPE((krb5_context, krb5_auth_context, krb5_pointer *)); +#endif KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_auth_con_setrcache KRB5_PROTOTYPE((krb5_context, krb5_auth_context, krb5_rcache)); -krb5_error_code krb5_auth_con_getrcache +krb5_error_code KRB5_CALLCONV_WRONG krb5_auth_con_getrcache KRB5_PROTOTYPE((krb5_context, krb5_auth_context, krb5_rcache *)); @@ -2141,7 +2390,7 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_read_password const char FAR *, char FAR *, int FAR * )); -krb5_error_code krb5_aname_to_localname +krb5_error_code KRB5_CALLCONV krb5_aname_to_localname KRB5_PROTOTYPE((krb5_context, krb5_const_principal, const int, @@ -2153,10 +2402,12 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_get_host_realm KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_free_host_realm KRB5_PROTOTYPE((krb5_context, char FAR * const FAR * )); +#if KRB5_PRIVATE KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_get_realm_domain KRB5_PROTOTYPE((krb5_context, const char *, char ** )); +#endif KRB5_DLLIMP krb5_boolean KRB5_CALLCONV krb5_kuserok KRB5_PROTOTYPE((krb5_context, krb5_principal, const char *)); @@ -2164,6 +2415,7 @@ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_auth_con_genaddrs KRB5_PROTOTYPE((krb5_context, krb5_auth_context, int, int)); +#if KRB5_PRIVATE krb5_error_code krb5_gen_portaddr KRB5_PROTOTYPE((krb5_context, const krb5_address *, @@ -2175,8 +2427,10 @@ krb5_error_code krb5_make_fulladdr krb5_address *, krb5_address *)); +#if KRB5_PRIVATE /* In k5-int.h on trunk */ krb5_error_code krb5_os_hostaddr KRB5_PROTOTYPE((krb5_context, const char *, krb5_address ***)); +#endif krb5_error_code krb5_set_real_time KRB5_PROTOTYPE((krb5_context, krb5_int32, krb5_int32)); @@ -2184,10 +2438,13 @@ krb5_error_code krb5_set_debugging_time KRB5_PROTOTYPE((krb5_context, krb5_int32, krb5_int32)); krb5_error_code krb5_use_natural_time KRB5_PROTOTYPE((krb5_context)); -krb5_error_code krb5_get_time_offsets +#endif +krb5_error_code KRB5_CALLCONV krb5_get_time_offsets KRB5_PROTOTYPE((krb5_context, krb5_int32 *, krb5_int32 *)); +#if KRB5_PRIVATE krb5_error_code krb5_set_time_offsets KRB5_PROTOTYPE((krb5_context, krb5_int32, krb5_int32)); +#endif /* str_conv.c */ KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_string_to_enctype @@ -2384,6 +2641,25 @@ krb5_decode_ticket KRB5_PROTOTYPE((const krb5_data *code, krb5_ticket **rep)); +KRB5_DLLIMP void KRB5_CALLCONV +krb5_appdefault_string +KRB5_PROTOTYPE((krb5_context context, + const char *appname, + const krb5_data *realm, + const char *option, + const char *default_value, + char ** ret_value)); + +KRB5_DLLIMP void KRB5_CALLCONV +krb5_appdefault_boolean +KRB5_PROTOTYPE((krb5_context context, + const char *appname, + const krb5_data *realm, + const char *option, + int default_value, + int *ret_value)); + +#if KRB5_PRIVATE /* * The realm iterator functions */ @@ -2399,6 +2675,7 @@ KRB5_DLLIMP void KRB5_CALLCONV krb5_realm_iterator_free KRB5_DLLIMP void KRB5_CALLCONV krb5_free_realm_string KRB5_PROTOTYPE((krb5_context context, char *str)); +#endif /* * Prompter enhancements @@ -2414,14 +2691,15 @@ typedef krb5_int32 krb5_prompt_type; KRB5_DLLIMP krb5_prompt_type* KRB5_CALLCONV krb5_get_prompt_types KRB5_PROTOTYPE((krb5_context context)); -#ifdef __cplusplus -} +#if TARGET_OS_MAC + #if defined(__MWERKS__) + #pragma enumsalwaysint reset + #pragma import reset + #endif + #pragma options align=reset #endif -/* Macintoh CFM-68K magic incantation */ -#if defined(macintosh) && defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__) -#pragma import reset -#endif +KRB5INT_END_DECLS #endif /* KRB5_GENERAL__ */ diff --git a/src/include/krb5/ChangeLog b/src/include/krb5/ChangeLog index 6fc5cc3..e0bd30e 100644 --- a/src/include/krb5/ChangeLog +++ b/src/include/krb5/ChangeLog @@ -1,3 +1,28 @@ +2001-10-29 Miro Jurisic + * pullup from krb5-1-2 branch after krb5-1-2-2-bp + * macsock.h: Updated location of Utilities.h and Sockets headers + * macsock.h: #include + +2001-09-25 Ken Raeburn + + * adm.h (struct __krb5_realm_params): Added fields + realm_reject_bad_transit, realm_reject_bad_transit_valid; deleted + field realm_filler. + +2000-10-02 Alexandra Ellwood + + * kdb.h: added Mac OS X #define (__MACH__) -- we're still a kerberos client + +2000-5-18 Alexandra Ellwood + + * macsock.h: local_addr_fallback_kludge defined to 0 again... fixed gethostname + +2000-5-9 Alexandra Ellwood + + * macsock.h: local_addr_fallback_kludge now defined to magic gethostaddr function + in the Sockets Library, which does exactly what we want if the search domain is not + specified. + 1998-11-22 Miro Jurisic * macsock.h: MacOS: only #define MACHOSTNAMELEN when not diff --git a/src/include/krb5/adm.h b/src/include/krb5/adm.h index b3a2b6a..820f652 100644 --- a/src/include/krb5/adm.h +++ b/src/include/krb5/adm.h @@ -1,7 +1,7 @@ /* * include/krb5/adm.h * - * Copyright 1995 by the Massachusetts Institute of Technology. + * Copyright 1995,2001 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -208,13 +208,14 @@ typedef struct __krb5_realm_params { krb5_timestamp realm_expiration; krb5_flags realm_flags; krb5_key_salt_tuple *realm_keysalts; + unsigned int realm_reject_bad_transit:1; unsigned int realm_kadmind_port_valid:1; unsigned int realm_enctype_valid:1; unsigned int realm_max_life_valid:1; unsigned int realm_max_rlife_valid:1; unsigned int realm_expiration_valid:1; unsigned int realm_flags_valid:1; - unsigned int realm_filler:7; + unsigned int realm_reject_bad_transit_valid:1; krb5_int32 realm_num_keysalts; } krb5_realm_params; #endif /* KRB5_ADM_H__ */ diff --git a/src/include/krb5/kdb.h b/src/include/krb5/kdb.h index 8316efe..60a08f4 100644 --- a/src/include/krb5/kdb.h +++ b/src/include/krb5/kdb.h @@ -84,7 +84,7 @@ #define KRB5_KDB_CREATE_BTREE 0x00000001 #define KRB5_KDB_CREATE_HASH 0x00000002 -#if !defined(macintosh) && !defined(_MSDOS) && !defined(_WIN32) +#if !defined(macintosh) && !defined(_MSDOS) && !defined(_WIN32) && !defined(__MACH__) /* * Note --- these structures cannot be modified without changing the diff --git a/src/include/krb5/macsock.h b/src/include/krb5/macsock.h index 06b103a..ecc2375 100644 --- a/src/include/krb5/macsock.h +++ b/src/include/krb5/macsock.h @@ -22,9 +22,9 @@ #ifndef macsock_h #define macsock_h -#include -#include -#include +#include +#include +#include /* Handle ANSI C versus traditional C */ #ifndef __STDC__ @@ -93,7 +93,7 @@ typedef int SOCKET; #define SOCKET_ERRNO (GetMITLibError()) #define SOCKET_SET_ERRNO(x) (SetMITLibError(x)) -#define local_addr_fallback_kludge() (0) +#define local_addr_fallback_kludge() 0 #endif /* macsock_h */ diff --git a/src/include/krb5/stock/ChangeLog b/src/include/krb5/stock/ChangeLog index 60e3d30..b2db75f 100644 --- a/src/include/krb5/stock/ChangeLog +++ b/src/include/krb5/stock/ChangeLog @@ -1,3 +1,7 @@ +2002-05-16 Alexandra Ellwood + * osconf.h (DEFAULT_PROFILE_PATH): Conditionalized for Mac OS X + to look in Mac OS X Preferences file locations. + 1999-09-20 Ken Raeburn * osconf.h (KPASSWD_PORTNAME): Define. diff --git a/src/include/krb5/stock/osconf.h b/src/include/krb5/stock/osconf.h index 452d9c6..bfe39c3 100644 --- a/src/include/krb5/stock/osconf.h +++ b/src/include/krb5/stock/osconf.h @@ -43,7 +43,11 @@ #define DEFAULT_LNAME_FILENAME "/aname" #define DEFAULT_KEYTAB_NAME "FILE:%s\\krb5kt" #else /* !_WINDOWS */ +#if TARGET_OS_MAC +#define DEFAULT_PROFILE_PATH "/Library/Preferences/edu.mit.Kerberos:~/Library/Preferences/edu.mit.Kerberos" +#else #define DEFAULT_PROFILE_PATH "/etc/krb5.conf:@SYSCONFDIR/krb5.conf" +#endif #define DEFAULT_KEYTAB_NAME "FILE:/etc/krb5.keytab" #define DEFAULT_LNAME_FILENAME "@PREFIX/lib/krb5.aname" #endif /* _WINDOWS */ diff --git a/src/include/win-mac.h b/src/include/win-mac.h index e2d37e0..27c5329 100644 --- a/src/include/win-mac.h +++ b/src/include/win-mac.h @@ -1,4 +1,8 @@ /* + * This file is now only used on Windows + */ + +/* * type functions split out of here to make things look nicer in the * various include files which need these definitions, as well as in * the util/ directories. @@ -7,10 +11,7 @@ #ifndef _KRB5_WIN_MAC_H #define _KRB5_WIN_MAC_H -#if (defined(_MSDOS) || defined(_WIN32)) -/* - * Machine-type definitions: PC Clone 386 running Microloss Windows - */ +#ifdef _WIN32 #define ID_READ_PWD_DIALOG 10000 #define ID_READ_PWD_PROMPT 10001 @@ -22,60 +23,27 @@ #define APSTUDIO_HIDDEN_SYMBOLS #include -#else - -#if defined(_MSDOS) - /* Windows 16 specific */ -#define BITS16 -#define SIZEOF_INT 2 -#define SIZEOF_SHORT 2 -#define SIZEOF_LONG 4 - -#ifndef KRB5_CALLCONV -#define KRB5_CALLCONV __far __export __pascal -#define KRB5_CALLCONV_C __far __export __cdecl -#define KRB5_EXPORTVAR __far __export -#define KRB5_DLLIMP -#endif /* !KRB5_CALLCONV */ - -#include - -/* - * The following defines are needed to make work - * in stdc mode (/Za flag). Winsock.h needs . - */ -#ifndef FAR -#define FAR __far -#define NEAR __near -#endif - -#ifndef _far -#define _far __far -#define _near __near -#define _pascal __pascal -#define _cdecl __cdecl -#define _huge __huge -#endif +#else /* ! RES_ONLY */ -#else - /* Windows 32 specific */ +/* Windows 32 specific */ #define SIZEOF_INT 4 #define SIZEOF_SHORT 2 #define SIZEOF_LONG 4 -#include /* always include this here, to get correct FAR and NEAR */ +/* always include this here, to get correct FAR and NEAR */ +#include #define HAVE_LABS #ifndef KRB5_CALLCONV -# ifdef _MSC_VER +# ifdef _MSC_VER # ifdef KRB5_DLL_FILE -# define KRB5_DLLIMP __declspec(dllexport) +# define KRB5_DLLIMP # else # define KRB5_DLLIMP __declspec(dllimport) # endif # ifdef GSS_DLL_FILE -# define GSS_DLLIMP __declspec(dllexport) +# define GSS_DLLIMP # else # define GSS_DLLIMP __declspec(dllimport) # endif @@ -85,11 +53,18 @@ # endif # define KRB5_CALLCONV __stdcall # define KRB5_CALLCONV_C __cdecl + +/* + * Use this to mark an incorrect calling convention that has been + * "immortalized" because it was incorrectly exported in a previous + * release. + */ + +# define KRB5_CALLCONV_WRONG KRB5_CALLCONV_C + # define KRB5_EXPORTVAR #endif /* !KRB5_CALLCONV */ -#endif /* _MSDOS */ - #ifndef KRB5_SYSTYPES__ #define KRB5_SYSTYPES__ #include @@ -180,31 +155,6 @@ typedef unsigned char u_char; #include #include #include -#define THREEPARAMOPEN(x,y,z) open(x,y,z) -#ifndef _WIN32 -#define O_RDONLY _O_RDONLY -#define O_WRONLY _O_WRONLY -#define O_RDWR _O_RDWR -#define O_APPEND _O_APPEND -#define O_CREAT _O_CREAT -#define O_TRUNC _O_TRUNC -#define O_EXCL _O_EXCL -#define O_TEXT _O_TEXT -#define O_BINARY _O_BINARY -#define O_NOINHERIT _O_NOINHERIT -#define stat _stat -#define unlink _unlink -#define lseek _lseek -#define write _write -#define open _open -#define close _close -#define read _read -#define fstat _fstat -#define mktemp _mktemp -#define dup _dup - -#define getpid _getpid -#endif #ifdef NEED_SYSERROR /* Only needed by util/et/error_message.c but let's keep the source clean */ @@ -222,91 +172,26 @@ HINSTANCE get_lib_instance(void); #endif /* !RES_ONLY */ -#endif /* _MSDOS || _WIN32 */ +#endif /* _WIN32 */ -#ifdef macintosh +#define THREEPARAMOPEN(x,y,z) open(x,y,z) +#ifndef KRB5_CALLCONV #define KRB5_CALLCONV -#define KRB5_CALLCONV_C -#define KRB5_DLLIMP -#define GSS_DLLIMP -#ifndef FAR -#define FAR -#endif -#ifndef NEAR -#define NEAR -#endif - -#define SIZEOF_INT 4 -#define SIZEOF_SHORT 2 -#define HAVE_SRAND -#define NO_PASSWORD -#define HAVE_LABS -/*#define ENOMEM 12*/ -#include -#include - -#ifdef NEED_LOWLEVEL_IO -#include #endif -/* - * Which encryption routines libcrypto will provide is controlled by - * mac/libraries/KerberosHeaders.h. - */ - -/* there is no for mpw */ -#ifndef __MWERKS__ -typedef unsigned long size_t; -typedef unsigned long mode_t; -typedef unsigned long ino_t; -typedef unsigned long dev_t; -typedef short nlink_t; -typedef unsigned long uid_t; -typedef unsigned long gid_t; -typedef long off_t; - -struct stat -{ - mode_t st_mode; /* File mode; see #define's below */ - ino_t st_ino; /* File serial number */ - dev_t st_dev; /* ID of device containing this file */ - nlink_t st_nlink; /* Number of links */ - uid_t st_uid; /* User ID of the file's owner */ - gid_t st_gid; /* Group ID of the file's group */ - dev_t st_rdev; /* Device type */ - off_t st_size; /* File size in bytes */ - unsigned long st_atime; /* Time of last access */ - unsigned long st_mtime; /* Time of last data modification */ - unsigned long st_ctime; /* Time of last file status change */ - long st_blksize; /* Optimal blocksize */ - long st_blocks; /* blocks allocated for file */ -}; - -int stat(const char *path, struct stat *buf); +#ifndef KRB5_CALLCONV_C +#define KRB5_CALLCONV_C #endif -int fstat(int fildes, struct stat *buf); - -#define EFBIG 1000 - -#define NOFCHMOD 1 -#define NOCHMOD 1 -#define _MACSOCKAPI_ - -#define THREEPARAMOPEN(x,y,z) open(x,y) -#else /* macintosh */ -#define THREEPARAMOPEN(x,y,z) open(x,y,z) -#endif /* macintosh */ - -#ifndef KRB5_CALLCONV -#define KRB5_CALLCONV -#define KRB5_CALLCONV_C +#ifndef KRB5_DLLIMP #define KRB5_DLLIMP #endif + #ifndef FAR #define FAR #endif + #ifndef NEAR #define NEAR #endif diff --git a/src/kadmin/cli/ChangeLog b/src/kadmin/cli/ChangeLog index aa19760..ceb689c 100644 --- a/src/kadmin/cli/ChangeLog +++ b/src/kadmin/cli/ChangeLog @@ -1,3 +1,28 @@ +2001-10-11 Ken Raeburn + + * kadmin.c (kadmin_parse_name): Properly advance pointer in + certain error cases involving '@'. Patch from Emily Ratliff, + . + [pulled up 1.54->1.55 from trunk] + +2001-02-22 Tom Yu + + * kadmin.M: Remove references to "rename_principal". + +2000-06-09 Tom Yu + + * kadmin.M: Update to reflect new -e and -keepold flags. + +2000-06-06 Ken Raeburn + + * kadmin.c (kadmin_startup): Don't pass keytab_name to printf if + it's NULL. + +2000-05-31 Ken Raeburn + + * strftime.c: Replace with a copy of the one from libkrb5, which + isn't under GPL. + 2000-03-01 Tom Yu * kadmin.c (kadmin_cpw): Initialize ks_tuple to NULL. diff --git a/src/kadmin/cli/kadmin.M b/src/kadmin/cli/kadmin.M index a74874f..08e02e5 100644 --- a/src/kadmin/cli/kadmin.M +++ b/src/kadmin/cli/kadmin.M @@ -320,6 +320,12 @@ sets the key of the principal to a random value sets the key of the principal to the specified string and does not prompt for a password. Note: using this option in a shell script can be dangerous if unauthorized users gain read access to the script. +.TP +\fB\-e\fP \fI"enc:salt ..."\fP +uses the specified list of enctype\-salttype pairs for setting the key +of the principal. The quotes are necessary if there are multiple +enctype\-salttype pairs. This will not function against kadmin +daemons earlier than krb5\-1.2. .nf .TP EXAMPLE: @@ -372,8 +378,8 @@ KADM5_UNK_PRINC (principal does not exist) modifies the specified principal, changing the fields as specified. The options are as above for .BR add_principal , -except that password changing is forbidden by this command. In -addition, the option +except that password changing and flags related to password changing +are forbidden by this command. In addition, the option .B \-clearpolicy will clear the current policy of a principal. This command requires the .I modify @@ -391,42 +397,6 @@ KADM5_BAD_MASK (shouldn't happen) .RE .fi .TP -\fBrename_principal\fP [\fB-force\fP] \fIold new\fP -rename the principal -.I old -to -.IR new . -Prompts for confirmation, unless the -.B \-force -option is given. Requires both the -.I add -and -.I delete -privileges. Aliased to -.BR renprinc . -.sp -.nf -.RS -.TP -EXAMPLE: -kadmin: renprinc tlyutest test0 -Are you sure you want to rename the principal -"tlyutest@BLEEP.COM" to -"test0@BLEEP.COM"? (yes/no): yes -Principal "tlyutest@BLEEP.COM" renamed to -"test0@BLEEP.COM". -Make sure that you have removed "tlyutest@BLEEP.COM" from -all ACLs before reusing. -kadmin: -.TP -ERRORS: -KADM5_AUTH_ADD (requires "add" privilege) -KADM5_AUTH_DELETE (requires "delete" privilege) -KADM5_UNK_PRINC (source principal does not exist) -KADM5_DUP (target principal already exists) -.RE -.fi -.TP \fBchange_password\fP [\fIoptions\fP] \fIprincipal\fP changes the password of .IR principal . @@ -447,6 +417,18 @@ sets the key of the principal to a random value .TP \fB\-pw\fP \fIpassword\fP set the password to the specified string. Not recommended. +.TP +\fB\-e\fP \fI"enc:salt ..."\fP +uses the specified list of enctype\-salttype pairs for setting the key +of the principal. The quotes are necessary if there are multiple +enctype\-salttype pairs. This will not function against kadmin +daemons earlier than krb5\-1.2. +.TP +\fB\-keepold \fP +Keeps the previous kvno's keys around. There is no +easy way to delete the old keys, and this flag is usually not +necessary except perhaps for TGS keys. Don't use this flag unless you +know what you're doing. .nf .TP EXAMPLE: @@ -664,7 +646,10 @@ kadmin: .RE .fi .TP -\fBktadd\fP [\fB\-k\fP \fIkeytab\fP] [\fB\-q\fP] [\fIprincipal\fP | \fB\-glob\fP \fIprinc-exp\fP] [\fI...\fP] +\fBktadd\fP [\fB\-k\fP \fIkeytab\fP] [\fB\-q\fP] [\fB\-e\fP \fIkeysaltlist\fP] +.br +[\fIprincipal\fP | \fB\-glob\fP \fIprinc-exp\fP] [\fI...\fP] +.br Adds a principal or all principals matching .I princ-exp to a keytab, randomizing each principal's key in the process. Requires the @@ -772,3 +757,9 @@ OpenVision Kerberos administration program. .SH BUGS .PP Command output needs to be cleaned up. + +There is no way to delete a key kept around from a "\-keepold" option +to a password-changing command, other than to do a password change +without the "\-keepold" option, which will of course cause problems if +the key is a TGS key. There will be more powerful key-manipulation +commands in the future. diff --git a/src/kadmin/cli/kadmin.c b/src/kadmin/cli/kadmin.c index 8038532..0092eef 100644 --- a/src/kadmin/cli/kadmin.c +++ b/src/kadmin/cli/kadmin.c @@ -149,7 +149,7 @@ krb5_error_code kadmin_parse_name(name, principal) if (cp - fullname && *(cp - 1) != '\\') break; else - cp = strchr(cp, '@'); + cp = strchr(cp + 1, '@'); } if (cp == NULL) { strcat(fullname, "@"); @@ -392,8 +392,12 @@ char *kadmin_startup(argc, argv) KADM5_API_VERSION_2, &handle); } else if (use_keytab) { - printf("Authenticating as principal %s with keytab %s.\n", - princstr, keytab_name); + if (keytab_name) + printf("Authenticating as principal %s with keytab %s.\n", + princstr, keytab_name); + else + printf("Authenticating as principal %s with default keytab.\n", + princstr); retval = kadm5_init_with_skey(princstr, keytab_name, KADM5_ADMIN_SERVICE, ¶ms, diff --git a/src/kadmin/cli/strftime.c b/src/kadmin/cli/strftime.c index 484852a..6fb621e 100644 --- a/src/kadmin/cli/strftime.c +++ b/src/kadmin/cli/strftime.c @@ -1,469 +1,464 @@ -/* strftime - custom formatting of date and/or time - Copyright (C) 1989, 1991, 1992 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Note: this version of strftime lacks locale support, - but it is standalone. - - Performs `%' substitutions similar to those in printf. Except - where noted, substituted fields have a fixed size; numeric fields are - padded if necessary. Padding is with zeros by default; for fields - that display a single number, padding can be changed or inhibited by - following the `%' with one of the modifiers described below. Unknown - field specifiers are copied as normal characters. All other - characters are copied to the output without change. - - Supports a superset of the ANSI C field specifiers. - - Literal character fields: - % % - n newline - t tab - - Numeric modifiers (a nonstandard extension): - - do not pad the field - _ pad the field with spaces - - Time fields: - %H hour (00..23) - %I hour (01..12) - %k hour ( 0..23) - %l hour ( 1..12) - %M minute (00..59) - %p locale's AM or PM - %r time, 12-hour (hh:mm:ss [AP]M) - %R time, 24-hour (hh:mm) - %s time in seconds since 00:00:00, Jan 1, 1970 (a nonstandard extension) - %S second (00..61) - %T time, 24-hour (hh:mm:ss) - %X locale's time representation (%H:%M:%S) - %Z time zone (EDT), or nothing if no time zone is determinable - - Date fields: - %a locale's abbreviated weekday name (Sun..Sat) - %A locale's full weekday name, variable length (Sunday..Saturday) - %b locale's abbreviated month name (Jan..Dec) - %B locale's full month name, variable length (January..December) - %c locale's date and time (Sat Nov 04 12:02:33 EST 1989) - %C century (00..99) - %d day of month (01..31) - %e day of month ( 1..31) - %D date (mm/dd/yy) - %h same as %b - %j day of year (001..366) - %m month (01..12) - %U week number of year with Sunday as first day of week (00..53) - %w day of week (0..6) - %W week number of year with Monday as first day of week (00..53) - %x locale's date representation (mm/dd/yy) - %y last two digits of year (00..99) - %Y year (1970...) - - David MacKenzie */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#if defined(TM_IN_SYS_TIME) || (!defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME)) -#include +/* $NetBSD: strftime.c,v 1.8 1999/02/07 17:33:30 augustss Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * 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 University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +#if 0 +static char *sccsid = "@(#)strftime.c 5.11 (Berkeley) 2/24/91"; #else -#include -#endif - -#ifndef STDC_HEADERS -time_t mktime (); +__RCSID("$NetBSD: strftime.c,v 1.8 1999/02/07 17:33:30 augustss Exp $"); #endif +#endif /* LIBC_SCCS and not lint */ -#if defined(HAVE_TZNAME) -extern char *tzname[2]; -#endif - -/* Types of padding for numbers in date and time. */ -enum padding -{ - none, blank, zero -}; +#include +#include -static char const* const days[] = -{ - "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" +/* begin krb5 hack - replace stuff that would come from netbsd libc */ +#undef _CurrentTimeLocale +#define _CurrentTimeLocale (&dummy_locale_info) + +struct dummy_locale_info_t { + char d_t_fmt[15]; + char t_fmt_ampm[12]; + char t_fmt[9]; + char d_fmt[9]; + char day[7][10]; + char abday[7][4]; + char mon[12][10]; + char abmon[12][4]; + char am_pm[2][3]; }; - -static char const * const months[] = -{ - "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December" +static const struct dummy_locale_info_t dummy_locale_info = { + "%a %b %d %X %Y", /* %c */ + "%I:%M:%S %p", /* %r */ + "%H:%M:%S", /* %X */ + "%m/%d/%y", /* %x */ + { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", + "Saturday" }, + { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }, + { "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" }, + { "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }, + { "AM", "PM" }, }; +#undef TM_YEAR_BASE +#define TM_YEAR_BASE 1900 + +#undef DAYSPERLYEAR +#define DAYSPERLYEAR 366 +#undef DAYSPERNYEAR +#define DAYSPERNYEAR 365 +#undef DAYSPERWEEK +#define DAYSPERWEEK 7 +#undef isleap +#define isleap(N) ((N % 4) == 0 && (N % 100 != 0 || N % 400 == 0)) +#undef tzname +#define tzname my_tzname +static const char *const tzname[2] = { 0, 0 }; +#undef tzset +#define tzset() +#undef __P +#define __P(X) X /* we already require ansi c in this tree */ +/* end krb5 hack */ + +static int _add __P((const char *, char **, const char *)); +static int _conv __P((int, int, int, char **, const char *)); +static int _secs __P((const struct tm *, char **, const char *)); +static size_t _fmt __P((const char *, const struct tm *, char **, + const char *)); -/* Add character C to STRING and increment LENGTH, - unless LENGTH would exceed MAX. */ - -#define add_char(c) \ - do \ - { \ - if (length + 1 <= max) \ - string[length++] = (c); \ - } \ - while (0) - -/* Add a 2 digit number to STRING, padding if specified. - Return the number of characters added, up to MAX. */ - -static int -add_num2 (string, num, max, pad) - char *string; - int num; - int max; - enum padding pad; -{ - int top = num / 10; - int length = 0; - - if (top == 0 && pad == blank) - add_char (' '); - else if (top != 0 || pad == zero) - add_char (top + '0'); - add_char (num % 10 + '0'); - return length; -} - -/* Add a 3 digit number to STRING, padding if specified. - Return the number of characters added, up to MAX. */ - -static int -add_num3 (string, num, max, pad) - char *string; - int num; - int max; - enum padding pad; +size_t +strftime(s, maxsize, format, t) + char *s; + size_t maxsize; + const char *format; + const struct tm *t; { - int top = num / 100; - int mid = (num - top * 100) / 10; - int length = 0; - - if (top == 0 && pad == blank) - add_char (' '); - else if (top != 0 || pad == zero) - add_char (top + '0'); - if (mid == 0 && top == 0 && pad == blank) - add_char (' '); - else if (mid != 0 || top != 0 || pad == zero) - add_char (mid + '0'); - add_char (num % 10 + '0'); - return length; + char *pt; + + tzset(); + if (maxsize < 1) + return (0); + + pt = s; + if (_fmt(format, t, &pt, s + maxsize)) { + *pt = '\0'; + return (pt - s); + } else + return (0); } -/* Like strncpy except return the number of characters copied. */ - -static int -add_str (to, from, max) - char *to; - const char *from; - int max; +#define SUN_WEEK(t) (((t)->tm_yday + 7 - \ + ((t)->tm_wday)) / 7) +#define MON_WEEK(t) (((t)->tm_yday + 7 - \ + ((t)->tm_wday ? (t)->tm_wday - 1 : 6)) / 7) + +static size_t +_fmt(format, t, pt, ptlim) + const char *format; + const struct tm *t; + char **pt; + const char * const ptlim; { - int i; - - for (i = 0; from[i] && i <= max; ++i) - to[i] = from[i]; - return i; + for (; *format; ++format) { + if (*format == '%') { + ++format; + if (*format == 'E') { + /* Alternate Era */ + ++format; + } else if (*format == 'O') { + /* Alternate numeric symbols */ + ++format; + } + switch (*format) { + case '\0': + --format; + break; + case 'A': + if (t->tm_wday < 0 || t->tm_wday > 6) + return (0); + if (!_add(_CurrentTimeLocale->day[t->tm_wday], + pt, ptlim)) + return (0); + continue; + + case 'a': + if (t->tm_wday < 0 || t->tm_wday > 6) + return (0); + if (!_add(_CurrentTimeLocale->abday[t->tm_wday], + pt, ptlim)) + return (0); + continue; + case 'B': + if (t->tm_mon < 0 || t->tm_mon > 11) + return (0); + if (!_add(_CurrentTimeLocale->mon[t->tm_mon], + pt, ptlim)) + return (0); + continue; + case 'b': + case 'h': + if (t->tm_mon < 0 || t->tm_mon > 11) + return (0); + if (!_add(_CurrentTimeLocale->abmon[t->tm_mon], + pt, ptlim)) + return (0); + continue; + case 'C': + if (!_conv((t->tm_year + TM_YEAR_BASE) / 100, + 2, '0', pt, ptlim)) + return (0); + continue; + case 'c': + if (!_fmt(_CurrentTimeLocale->d_t_fmt, t, pt, + ptlim)) + return (0); + continue; + case 'D': + if (!_fmt("%m/%d/%y", t, pt, ptlim)) + return (0); + continue; + case 'd': + if (!_conv(t->tm_mday, 2, '0', pt, ptlim)) + return (0); + continue; + case 'e': + if (!_conv(t->tm_mday, 2, ' ', pt, ptlim)) + return (0); + continue; + case 'H': + if (!_conv(t->tm_hour, 2, '0', pt, ptlim)) + return (0); + continue; + case 'I': + if (!_conv(t->tm_hour % 12 ? + t->tm_hour % 12 : 12, 2, '0', pt, ptlim)) + return (0); + continue; + case 'j': + if (!_conv(t->tm_yday + 1, 3, '0', pt, ptlim)) + return (0); + continue; + case 'k': + if (!_conv(t->tm_hour, 2, ' ', pt, ptlim)) + return (0); + continue; + case 'l': + if (!_conv(t->tm_hour % 12 ? + t->tm_hour % 12: 12, 2, ' ', pt, ptlim)) + return (0); + continue; + case 'M': + if (!_conv(t->tm_min, 2, '0', pt, ptlim)) + return (0); + continue; + case 'm': + if (!_conv(t->tm_mon + 1, 2, '0', pt, ptlim)) + return (0); + continue; + case 'n': + if (!_add("\n", pt, ptlim)) + return (0); + continue; + case 'p': + if (!_add(_CurrentTimeLocale->am_pm[t->tm_hour + >= 12], pt, ptlim)) + return (0); + continue; + case 'R': + if (!_fmt("%H:%M", t, pt, ptlim)) + return (0); + continue; + case 'r': + if (!_fmt(_CurrentTimeLocale->t_fmt_ampm, t, pt, + ptlim)) + return (0); + continue; + case 'S': + if (!_conv(t->tm_sec, 2, '0', pt, ptlim)) + return (0); + continue; + case 's': + if (!_secs(t, pt, ptlim)) + return (0); + continue; + case 'T': + if (!_fmt("%H:%M:%S", t, pt, ptlim)) + return (0); + continue; + case 't': + if (!_add("\t", pt, ptlim)) + return (0); + continue; + case 'U': + if (!_conv(SUN_WEEK(t), 2, '0', pt, ptlim)) + return (0); + continue; + case 'u': + if (!_conv(t->tm_wday ? t->tm_wday : 7, 1, '0', + pt, ptlim)) + return (0); + continue; + case 'V': /* ISO 8601 week number */ + case 'G': /* ISO 8601 year (four digits) */ + case 'g': /* ISO 8601 year (two digits) */ +/* +** From Arnold Robbins' strftime version 3.0: "the week number of the +** year (the first Monday as the first day of week 1) as a decimal number +** (01-53)." +** (ado, 1993-05-24) +** +** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn: +** "Week 01 of a year is per definition the first week which has the +** Thursday in this year, which is equivalent to the week which contains +** the fourth day of January. In other words, the first week of a new year +** is the week which has the majority of its days in the new year. Week 01 +** might also contain days from the previous year and the week before week +** 01 of a year is the last week (52 or 53) of the previous year even if +** it contains days from the new year. A week starts with Monday (day 1) +** and ends with Sunday (day 7). For example, the first week of the year +** 1997 lasts from 1996-12-30 to 1997-01-05..." +** (ado, 1996-01-02) +*/ + { + int year; + int yday; + int wday; + int w; + + year = t->tm_year + TM_YEAR_BASE; + yday = t->tm_yday; + wday = t->tm_wday; + for ( ; ; ) { + int len; + int bot; + int top; + + len = isleap(year) ? + DAYSPERLYEAR : + DAYSPERNYEAR; + /* + ** What yday (-3 ... 3) does + ** the ISO year begin on? + */ + bot = ((yday + 11 - wday) % + DAYSPERWEEK) - 3; + /* + ** What yday does the NEXT + ** ISO year begin on? + */ + top = bot - + (len % DAYSPERWEEK); + if (top < -3) + top += DAYSPERWEEK; + top += len; + if (yday >= top) { + ++year; + w = 1; + break; + } + if (yday >= bot) { + w = 1 + ((yday - bot) / + DAYSPERWEEK); + break; + } + --year; + yday += isleap(year) ? + DAYSPERLYEAR : + DAYSPERNYEAR; + } +#ifdef XPG4_1994_04_09 + if ((w == 52 + && t->tm_mon == TM_JANUARY) + || (w == 1 + && t->tm_mon == TM_DECEMBER)) + w = 53; +#endif /* defined XPG4_1994_04_09 */ + if (*format == 'V') { + if (!_conv(w, 2, '0', + pt, ptlim)) + return (0); + } else if (*format == 'g') { + if (!_conv(year % 100, 2, '0', + pt, ptlim)) + return (0); + } else if (!_conv(year, 4, '0', + pt, ptlim)) + return (0); + } + continue; + case 'W': + if (!_conv(MON_WEEK(t), 2, '0', pt, ptlim)) + return (0); + continue; + case 'w': + if (!_conv(t->tm_wday, 1, '0', pt, ptlim)) + return (0); + continue; + case 'x': + if (!_fmt(_CurrentTimeLocale->d_fmt, t, pt, + ptlim)) + return (0); + continue; + case 'X': + if (!_fmt(_CurrentTimeLocale->t_fmt, t, pt, + ptlim)) + return (0); + continue; + case 'y': + if (!_conv((t->tm_year + TM_YEAR_BASE) % 100, + 2, '0', pt, ptlim)) + return (0); + continue; + case 'Y': + if (!_conv((t->tm_year + TM_YEAR_BASE), 4, '0', + pt, ptlim)) + return (0); + continue; + case 'Z': + if (tzname[t->tm_isdst ? 1 : 0] && + !_add(tzname[t->tm_isdst ? 1 : 0], pt, + ptlim)) + return (0); + continue; + case '%': + /* + * X311J/88-090 (4.12.3.5): if conversion char is + * undefined, behavior is undefined. Print out the + * character itself as printf(3) does. + */ + default: + break; + } + } + if (*pt == ptlim) + return (0); + *(*pt)++ = *format; + } + return (ptlim - *pt); } static int -add_num_time_t (string, max, num) - char *string; - int max; - time_t num; +_secs(t, pt, ptlim) + const struct tm *t; + char **pt; + const char * const ptlim; { - /* This buffer is large enough to hold the character representation - (including the trailing NUL) of any unsigned decimal quantity - whose binary representation fits in 128 bits. */ - char buf[40]; - int length; - - if (sizeof (num) > 16) - abort (); - sprintf (buf, "%lu", (unsigned long) num); - length = add_str (string, buf, max); - return length; + char buf[15]; + time_t s; + char *p; + struct tm tmp; + + buf[sizeof (buf) - 1] = '\0'; + /* Make a copy, mktime(3) modifies the tm struct. */ + tmp = *t; + s = mktime(&tmp); + for (p = buf + sizeof(buf) - 2; s > 0 && p > buf; s /= 10) + *p-- = (char)(s % 10 + '0'); + return (_add(++p, pt, ptlim)); } -/* Return the week in the year of the time in TM, with the weeks - starting on Sundays. */ - static int -sun_week (tm) - struct tm *tm; +_conv(n, digits, pad, pt, ptlim) + int n, digits; + int pad; + char **pt; + const char * const ptlim; { - int dl; - - /* Set `dl' to the day in the year of the last day of the week previous - to the one containing the day specified in TM. If the day specified - in TM is in the first week of the year, `dl' will be negative or 0. - Otherwise, calculate the number of complete weeks before our week - (dl / 7) and add any partial week at the start of the year (dl % 7). */ - dl = tm->tm_yday - tm->tm_wday; - return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0); + char buf[10]; + char *p; + + buf[sizeof (buf) - 1] = '\0'; + for (p = buf + sizeof(buf) - 2; n > 0 && p > buf; n /= 10, --digits) + *p-- = n % 10 + '0'; + while (p > buf && digits-- > 0) + *p-- = pad; + return (_add(++p, pt, ptlim)); } -/* Return the week in the year of the time in TM, with the weeks - starting on Mondays. */ - static int -mon_week (tm) - struct tm *tm; -{ - int dl, wday; - - if (tm->tm_wday == 0) - wday = 6; - else - wday = tm->tm_wday - 1; - dl = tm->tm_yday - wday; - return dl <= 0 ? 0 : dl / 7 + (dl % 7 != 0); -} - -#if !defined(HAVE_TM_ZONE) && !defined(HAVE_TZNAME) -char * -zone_name (tp) - struct tm *tp; +_add(str, pt, ptlim) + const char *str; + char **pt; + const char * const ptlim; { - char *timezone (); - struct timeval tv; - struct timezone tz; - - gettimeofday (&tv, &tz); - return timezone (tz.tz_minuteswest, tp->tm_isdst); -} -#endif - -/* Format the time given in TM according to FORMAT, and put the - results in STRING. - Return the number of characters (not including terminating null) - that were put into STRING, or 0 if the length would have - exceeded MAX. */ - -size_t -strftime (string, max, format, tm) - char *string; - size_t max; - const char *format; - const struct tm *tm; -{ - enum padding pad; /* Type of padding to apply. */ - size_t length = 0; /* Characters put in STRING so far. */ - - for (; *format && length < max; ++format) - { - if (*format != '%') - add_char (*format); - else - { - ++format; - /* Modifiers: */ - if (*format == '-') - { - pad = none; - ++format; - } - else if (*format == '_') - { - pad = blank; - ++format; - } - else - pad = zero; - - switch (*format) - { - /* Literal character fields: */ - case 0: - case '%': - add_char ('%'); - break; - case 'n': - add_char ('\n'); - break; - case 't': - add_char ('\t'); - break; - default: - add_char (*format); - break; - - /* Time fields: */ - case 'H': - case 'k': - length += - add_num2 (&string[length], tm->tm_hour, max - length, - *format == 'H' ? pad : blank); - break; - case 'I': - case 'l': - { - int hour12; - - if (tm->tm_hour == 0) - hour12 = 12; - else if (tm->tm_hour > 12) - hour12 = tm->tm_hour - 12; - else - hour12 = tm->tm_hour; - length += - add_num2 (&string[length], hour12, max - length, - *format == 'I' ? pad : blank); - } - break; - case 'M': - length += - add_num2 (&string[length], tm->tm_min, max - length, pad); - break; - case 'p': - if (tm->tm_hour < 12) - add_char ('A'); - else - add_char ('P'); - add_char ('M'); - break; - case 'r': - length += - strftime (&string[length], max - length, "%I:%M:%S %p", tm); - break; - case 'R': - length += - strftime (&string[length], max - length, "%H:%M", tm); - break; - - case 's': - { - struct tm writable_tm; - writable_tm = *tm; - length += add_num_time_t (&string[length], max - length, - mktime (&writable_tm)); - } - break; - - case 'S': - length += - add_num2 (&string[length], tm->tm_sec, max - length, pad); - break; - case 'T': - length += - strftime (&string[length], max - length, "%H:%M:%S", tm); - break; - case 'X': - length += - strftime (&string[length], max - length, "%H:%M:%S", tm); - break; - case 'Z': -#ifdef HAVE_TM_ZONE - length += add_str (&string[length], tm->tm_zone, max - length); -#else -#ifdef HAVE_TZNAME - if (tm->tm_isdst && tzname[1] && *tzname[1]) - length += add_str (&string[length], tzname[1], max - length); - else - length += add_str (&string[length], tzname[0], max - length); -#else - length += add_str (&string[length], zone_name (tm), max - length); -#endif -#endif - break; - /* Date fields: */ - case 'a': - add_char (days[tm->tm_wday][0]); - add_char (days[tm->tm_wday][1]); - add_char (days[tm->tm_wday][2]); - break; - case 'A': - length += - add_str (&string[length], days[tm->tm_wday], max - length); - break; - case 'b': - case 'h': - add_char (months[tm->tm_mon][0]); - add_char (months[tm->tm_mon][1]); - add_char (months[tm->tm_mon][2]); - break; - case 'B': - length += - add_str (&string[length], months[tm->tm_mon], max - length); - break; - case 'c': - length += - strftime (&string[length], max - length, - "%a %b %d %H:%M:%S %Z %Y", tm); - break; - case 'C': - length += - add_num2 (&string[length], (tm->tm_year + 1900) / 100, - max - length, pad); - break; - case 'd': - length += - add_num2 (&string[length], tm->tm_mday, max - length, pad); - break; - case 'e': - length += - add_num2 (&string[length], tm->tm_mday, max - length, blank); - break; - case 'D': - length += - strftime (&string[length], max - length, "%m/%d/%y", tm); - break; - case 'j': - length += - add_num3 (&string[length], tm->tm_yday + 1, max - length, pad); - break; - case 'm': - length += - add_num2 (&string[length], tm->tm_mon + 1, max - length, pad); - break; - case 'U': - length += - add_num2 (&string[length], sun_week (tm), max - length, pad); - break; - case 'w': - add_char (tm->tm_wday + '0'); - break; - case 'W': - length += - add_num2 (&string[length], mon_week (tm), max - length, pad); - break; - case 'x': - length += - strftime (&string[length], max - length, "%m/%d/%y", tm); - break; - case 'y': - length += - add_num2 (&string[length], tm->tm_year % 100, - max - length, pad); - break; - case 'Y': - add_char ((tm->tm_year + 1900) / 1000 + '0'); - length += - add_num3 (&string[length], - (1900 + tm->tm_year) % 1000, max - length, zero); - break; - } + for (;; ++(*pt)) { + if (*pt == ptlim) + return (0); + if ((**pt = *str++) == '\0') + return (1); } - } - add_char (0); - return length - 1; } diff --git a/src/kadmin/dbutil/ChangeLog b/src/kadmin/dbutil/ChangeLog index 9a309bd..2008272 100644 --- a/src/kadmin/dbutil/ChangeLog +++ b/src/kadmin/dbutil/ChangeLog @@ -1,3 +1,45 @@ +2002-08-23 Tom Yu + + * dump.c (dump_db): Update usage comment. Add "-rev" and + "-recurse" flags to permit reverse and recursive dumping of the + database, respectively. Check for dump filename beginning with + "-" to avoid accidental dumps to such filenames. + + * kdb5_util.c (usage): Update to match reality, primarily by + updating the "dump" usage, but also showing global options before + the command, which is how they were being interpreted anyway. + + * kdb5_util.M: Update to match reality. Document "-mkey_convert", + "-new_mkey_file", "-rev", and "-recurse" options to "dump". + Document "dump to stdout" behavior. Show global options before + the command. Make some formatting fixes. s/binary tree/btree/ + since the btree back end is actually an n-ary tree. + + [pullups from trunk] + +2002-08-12 Tom Yu + + * dump.c (master_key_convert): Iterate over freeing + key_data->key_data_contents[j] rather than attempting to free + key_data->key_data_contents. + [pullup from trunk] + +2001-10-23 Tom Yu + + * loadv4.c (fixup_database): Don't set SUPPORT_DESMD5 anymore. + +2001-02-05 Tom Yu + + * kdb5_util.M: Fix some formatting nits and document new flags + controlling dump formats. + +2000-06-30 Tom Yu + + * dump.c: Add a new dump version, r1_3_version, and make it the + default; it will be used in krb5-1.3 and will permit a principal's + kadm5 data to be dumped. This is an interim measure until we + redesign the dump format somewhat. + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/kadmin/dbutil/dump.c b/src/kadmin/dbutil/dump.c index 4378e31..2023f7d 100644 --- a/src/kadmin/dbutil/dump.c +++ b/src/kadmin/dbutil/dump.c @@ -47,6 +47,9 @@ extern void usage(); static int mkey_convert; static krb5_keyblock new_master_keyblock; +static int backwards; +static int recursive; + /* * Use compile(3) if no regcomp present. */ @@ -74,8 +77,16 @@ static krb5_error_code dump_k5beta_iterator PROTOTYPE((krb5_pointer, krb5_db_entry *)); static krb5_error_code dump_k5beta6_iterator PROTOTYPE((krb5_pointer, krb5_db_entry *)); +static krb5_error_code dump_k5beta6_iterator_ext PROTOTYPE((krb5_pointer, + krb5_db_entry *, + int)); static krb5_error_code dump_k5beta7_princ PROTOTYPE((krb5_pointer, krb5_db_entry *)); +static krb5_error_code dump_k5beta7_princ_ext PROTOTYPE((krb5_pointer, + krb5_db_entry *, + int)); +static krb5_error_code dump_k5beta7_princ_withpolicy + PROTOTYPE((krb5_pointer, krb5_db_entry *)); static krb5_error_code dump_ov_princ PROTOTYPE((krb5_pointer, krb5_db_entry *)); static void dump_k5beta7_policy PROTOTYPE((void *, osa_policy_ent_t)); @@ -141,6 +152,16 @@ dump_version ov_version = { process_ov_record, }; +dump_version r1_3_version = { + "Kerberos version 5 release 1.3", + "kdb5_util load_dump version 5\n", + 0, + 0, + dump_k5beta7_princ_withpolicy, + dump_k5beta7_policy, + process_k5beta7_record, +}; + /* External data */ extern char *current_dbname; extern krb5_boolean dbactive; @@ -220,6 +241,7 @@ static const char dfile_err_fmt[] = "%s: cannot open %s (%s)\n"; static const char oldoption[] = "-old"; static const char b6option[] = "-b6"; +static const char b7option[] = "-b7"; static const char verboseoption[] = "-verbose"; static const char updateoption[] = "-update"; static const char hashoption[] = "-hash"; @@ -236,7 +258,7 @@ krb5_error_code master_key_convert(context, db_entry) krb5_error_code retval; krb5_keyblock v5plainkey, *key_ptr; krb5_keysalt keysalt; - int i; + int i, j; krb5_key_data new_key_data, *key_data; krb5_boolean is_mkey; @@ -265,7 +287,11 @@ krb5_error_code master_key_convert(context, db_entry) if (retval) return retval; krb5_free_keyblock_contents(context, &v5plainkey); - free(key_data->key_data_contents); + for (j = 0; j < key_data->key_data_ver; j++) { + if (key_data->key_data_length[j]) { + free(key_data->key_data_contents[j]); + } + } *key_data = new_key_data; } return 0; @@ -634,6 +660,15 @@ dump_k5beta6_iterator(ptr, entry) krb5_pointer ptr; krb5_db_entry *entry; { + return dump_k5beta6_iterator_ext(ptr, entry, 0); +} + +static krb5_error_code +dump_k5beta6_iterator_ext(ptr, entry, kadm) + krb5_pointer ptr; + krb5_db_entry *entry; + int kadm; +{ krb5_error_code retval; struct dump_args *arg; char *name; @@ -703,7 +738,10 @@ dump_k5beta6_iterator(ptr, entry) */ switch (tlp->tl_data_type) { case KRB5_TL_KADM_DATA: - skip++; + if (kadm) + counter++; + else + skip++; break; default: counter++; @@ -731,7 +769,7 @@ dump_k5beta6_iterator(ptr, entry) entry->fail_auth_count); /* Pound out tagged data. */ for (tlp = entry->tl_data; tlp; tlp = tlp->tl_data_next) { - if (tlp->tl_data_type == KRB5_TL_KADM_DATA) + if (tlp->tl_data_type == KRB5_TL_KADM_DATA && !kadm) continue; /* see above, [krb5-admin/89] */ fprintf(arg->ofile, "%d\t%d\t", @@ -797,6 +835,15 @@ dump_k5beta7_princ(ptr, entry) krb5_pointer ptr; krb5_db_entry *entry; { + return dump_k5beta7_princ_ext(ptr, entry, 0); +} + +static krb5_error_code +dump_k5beta7_princ_ext(ptr, entry, kadm) + krb5_pointer ptr; + krb5_db_entry *entry; + int kadm; +{ krb5_error_code retval; struct dump_args *arg; char *name; @@ -826,7 +873,7 @@ dump_k5beta7_princ(ptr, entry) /* save the callee from matching the name again */ tmp_nnames = arg->nnames; arg->nnames = 0; - retval = dump_k5beta6_iterator(ptr, entry); + retval = dump_k5beta6_iterator_ext(ptr, entry, kadm); arg->nnames = tmp_nnames; } @@ -834,6 +881,14 @@ dump_k5beta7_princ(ptr, entry) return retval; } +static krb5_error_code +dump_k5beta7_princ_withpolicy(ptr, entry) + krb5_pointer ptr; + krb5_db_entry *entry; +{ + return dump_k5beta7_princ_ext(ptr, entry, 1); +} + void dump_k5beta7_policy(void *data, osa_policy_ent_t entry) { struct dump_args *arg; @@ -953,7 +1008,9 @@ static krb5_error_code dump_ov_princ(krb5_pointer ptr, krb5_db_entry *kdb) /* * usage is: - * dump_db [-old] [-b6] [-ov] [-verbose] [filename [principals...]] + * dump_db [-old] [-b6] [-b7] [-ov] [-verbose] [-mkey_convert] + * [-new_mkey_file mkey_file] [-rev] [-recurse] + * [filename [principals...]] */ void dump_db(argc, argv) @@ -980,10 +1037,12 @@ dump_db(argc, argv) programname = strrchr(argv[0], (int) '/') + 1; ofile = (char *) NULL; error = 0; - dump = &beta7_version; + dump = &r1_3_version; arglist.verbose = 0; new_mkey_file = 0; mkey_convert = 0; + backwards = 0; + recursive = 0; /* * Parse the qualifiers. @@ -993,6 +1052,8 @@ dump_db(argc, argv) dump = &old_version; else if (!strcmp(argv[aindex], b6option)) dump = &beta6_version; + else if (!strcmp(argv[aindex], b7option)) + dump = &beta7_version; else if (!strcmp(argv[aindex], ovoption)) dump = &ov_version; else if (!strcmp(argv[aindex], verboseoption)) @@ -1002,7 +1063,11 @@ dump_db(argc, argv) else if (!strcmp(argv[aindex], "-new_mkey_file")) { new_mkey_file = argv[++aindex]; mkey_convert = 1; - } else + } else if (!strcmp(argv[aindex], "-rev")) + backwards = 1; + else if (!strcmp(argv[aindex], "-recurse")) + recursive = 1; + else break; } @@ -1072,6 +1137,11 @@ dump_db(argc, argv) locked = 0; if (ofile && strcmp(ofile, "-")) { /* + * Discourage accidental dumping to filenames beginning with '-'. + */ + if (ofile[0] == '-') + usage(); + /* * Make sure that we don't open and truncate on the fopen, * since that may hose an on-going kprop process. * @@ -1108,9 +1178,10 @@ dump_db(argc, argv) if (dump->header[strlen(dump->header)-1] != '\n') fputc('\n', arglist.ofile); - if ((kret = krb5_db_iterate(util_context, - dump->dump_princ, - (krb5_pointer) &arglist))) { + if ((kret = krb5_db_iterate_ext(util_context, + dump->dump_princ, + (krb5_pointer) &arglist, + backwards, recursive))) { fprintf(stderr, dumprec_err, programname, dump->name, error_message(kret)); exit_status++; @@ -2008,7 +2079,8 @@ restore_dump(programname, kcontext, dumpfile, f, verbose, dump, pol_db) } /* - * Usage: load_db [-old] [-ov] [-b6] [-verbose] [-update] [-hash] filename + * Usage: load_db [-old] [-ov] [-b6] [-b7] [-verbose] [-update] [-hash] + * filename */ void load_db(argc, argv) @@ -2052,6 +2124,8 @@ load_db(argc, argv) load = &old_version; else if (!strcmp(argv[aindex], b6option)) load = &beta6_version; + else if (!strcmp(argv[aindex], b7option)) + load = &beta7_version; else if (!strcmp(argv[aindex], ovoption)) load = &ov_version; else if (!strcmp(argv[aindex], verboseoption)) @@ -2129,6 +2203,8 @@ load_db(argc, argv) load = &beta6_version; else if (strcmp(buf, beta7_version.header) == 0) load = &beta7_version; + else if (strcmp(buf, r1_3_version.header) == 0) + load = &r1_3_version; else if (strncmp(buf, ov_version.header, strlen(ov_version.header)) == 0) load = &ov_version; diff --git a/src/kadmin/dbutil/kdb5_util.M b/src/kadmin/dbutil/kdb5_util.M index 829e55a..8080756 100644 --- a/src/kadmin/dbutil/kdb5_util.M +++ b/src/kadmin/dbutil/kdb5_util.M @@ -3,11 +3,12 @@ kdb5_util \- Kerberos database maintainance utility .SH SYNOPSIS .B kdb5_util -.I command -[\fB\-r\fP \fIrealm\fP] [\fB\-d\fP \fIdbname\fP] -[\fB\-k\fP \fImkeytype\fP] [\fB\-M\fP \fImkeyname\fP] +[\fB\-r\fP\ \fIrealm\fP] [\fB\-d\fP\ \fIdbname\fP] +[\fB\-k\fP\ \fImkeytype\fP] [\fB\-M\fP\ \fImkeyname\fP] +[\fB\-sf\fP\ \fIstashfilename\fP] [\fB\-m\fP] -.I command_options +.I command +.I [command_options] .SH DESCRIPTION .B kdb5_util allows an administrator to perform low-level maintainance procedures on @@ -35,25 +36,25 @@ successfully opens the database, because the database may not exist yet or the stash file may be corrupt. .SH COMMAND-LINE OPTIONS .TP -\fB\-r\fP \fIrealm\fP +\fB\-r\fP\ \fIrealm\fP specifies the Kerberos realm of the database; by default the realm returned by .IR krb5_default_local_realm (3) is used. .TP -\fB-d\fP \fIdbname\fP +\fB\-d\fP\ \fIdbname\fP specifies the name under which the principal database is stored; by default the database is that listed in .IR kdc.conf (5). The KADM5 policy database and lock file are also derived from this value. .TP -\fB\-k\fP \fImkeytype\fP +\fB\-k\fP\ \fImkeytype\fP specifies the key type of the master key in the database; the default is that given in .IR kdc.conf . .TP -\fB\-M\fP \fImkeyname\fP +\fB\-M\fP\ \fImkeyname\fP principal name for the master key in the database; the default is that given in .IR kdc.conf . @@ -63,7 +64,7 @@ specifies that the master database password should be read from the TTY rather than fetched from a file on disk. .SH COMMANDS .TP -\fBcreate\fP [\fB-s\fP] +\fBcreate\fP [\fB\-s\fP] Creates a new database. If the .B \-s option is specified, the stash file is also created. This command fails @@ -78,15 +79,22 @@ the .B \-f argument, does not prompt the user. .TP -\fBstash\fP [\fB\-f\fP \fIkeyfile\fP] +\fBstash\fP [\fB\-f\fP\ \fIkeyfile\fP] Stores the master principal's keys in a stash file. The .B \-f argument can be used to override the keyfile specified at startup. .TP -\fBdump\fP [\fB\-old\fP] [\fB\-b6\fP] [\fB\-ov\fP] [\fB-verbose\fP] [\fIfilename\fP [\fIprincipals...\fP]] +\fBdump\fP [\fB\-old\fP] [\fB\-b6\fP] [\fB\-b7\fP] [\fB\-ov\fP] +[\fB\-verbose\fP] [\fB\-mkey_convert\fP] +[\fB\-new_mkey_file\fP \fImkey_file\fP] [\fB\-rev\fP] [\fB\-recurse\fP] +[\fIfilename\fP [\fIprincipals...\fP]] +.br Dumps the current Kerberos and KADM5 database into an ASCII file. By default, the database is dumped in current format, "kdb5_util -load_dumpversion 4". Options: +load_dumpversion 5". If +.I filename +is not specified, or is the string "\-", the dump is sent to standard +output. Options: .RS .TP .B \-old @@ -97,6 +105,9 @@ causes the dump to be in the Kerberos 5 Beta 5 and earlier dump format causes the dump to be in the Kerberos 5 Beta 6 format ("kdb5_edit load_dump version 3.0"). .TP +.B \-b7 +causes the dump to be in the Kerberos 5 Beta 7 format ("kdb5_util load_dump version 4"). This was the dump format produced on releases prior to 1.2.2. +.TP .B \-ov causes the dump to be in .I ovsec_adm_export @@ -105,15 +116,38 @@ format. .B \-verbose causes the name of each principal and policy to be printed as it is dumped. +.TP +.B \-mkey_convert +prompts for a new master key. This new master key will be used to +re-encrypt the key data in the dumpfile. The key data in the database +will not be changed. +.TP +.B \-new_mkey_file \fImkey_file\fP +the filename of a stash file. The master key in this stash file will +be used to re-encrypt the key data in the dumpfile. The key data in +the database will not be changed. +.TP +.B \-rev +dumps in reverse order. This may recover principals that do not dump +normally, in cases where database corruption has occured. +.TP +.B \-recurse +causes the dump to walk the database recursively (btree only). This +may recover principals that do not dump normally, in cases where +database corruption has occured. In cases of such corruption, this +option will probably retrieve more principals than the \fB\-rev\fP +option will. .RE .TP -\fBload\fP [\fB\-old\fP] [\fB\-b6\fP] [\fB\-ov\fP] [\fB-verbose\fP] [\fB-update\fP] \fIfilename dbname\fP [\fIadmin_dbname\fP] +\fBload\fP [\fB\-old\fP] [\fB\-b6\fP] [\fB\-ov\fP] +[\fB\-verbose\fP] [\fB\-update\fP] \fIfilename dbname\fP [\fIadmin_dbname\fP] +.br Loads a database dump from the named file into the named database. Unless the .B \-old or .B \-b6 -option is givnen, the format of the dump file is detected +option is given, the format of the dump file is detected automatically and handled as appropriate. Unless the .B \-update option is given, @@ -130,6 +164,10 @@ requires the database to be in the Kerberos 5 Beta 5 and earlier format requires the database to be in the Kerberos 5 Beta 6 format ("kdb5_edit load_dump version 3.0"). .TP +.B \-b7 +requires the database to be in the Kerberos 5 Beta 7 format ("kdb5_util +load_dump version 4"). +.TP .B \-ov requires the database to be in .I ovsec_adm_import @@ -137,6 +175,12 @@ format. Must be used with the .B \-update option. .TP +.B \-hash +requires the database to be stored as a hash. If this option is not +specified, the database will be stored as a btree. This option +is not recommended, as databases stored in hash format are known to +corrupt data and lose principals. +.TP .B \-verbose causes the name of each principal and policy to be printed as it is dumped. @@ -159,7 +203,10 @@ if not specified. \fBdump_v4\fP [\fIfilename\fP] Dumps the current database into the Kerberos 4 database dump format. .TP -\fBload_v4\fP [\fB\-t\fP] [\fB-n\fP] [\fB\-K\fP] [\fB-s \fIstashfile\fP] \fIinputfile\fP +\fBload_v4\fP [\fB\-T\fP] [\fB\-v\fP] [\fB\-h\fP] +[\fB\-t\fP] [\fB-n\fP] [\fB\-K\fP] [\fB\-s\fP\ \fIstashfile\fP] +\fIinputfile\fP +.br Loads a Kerberos 4 database dump file. Options: .RS .TP @@ -183,6 +230,11 @@ lists each principal as it is converted or ignored. .B \-t uses a temporary database, then moves that into place, instead of adding the keys to the current database. +.TP +.B \-h +Stores the database as a hash instead of a btree. This option is +not recommended, as databases stored in hash format are known to +corrupt data and lose principals. .PP Note: if the Kerberos 4 database had a default expiration date of 12/31/1999 or 12/31/2009 (the compiled in defaults for older or newer Kerberos @@ -195,5 +247,9 @@ record; Version 5 stores a seperate modification time and last password change time. In practice, Version 4 "modifications" were always password changes. \fIload_v4\fP copies the value into both fields. +.RE +.TP +\fBark\fP +Adds a random key. .SH SEE ALSO kadmin(8) diff --git a/src/kadmin/dbutil/kdb5_util.c b/src/kadmin/dbutil/kdb5_util.c index 92b1c21..7eaa7f8 100644 --- a/src/kadmin/dbutil/kdb5_util.c +++ b/src/kadmin/dbutil/kdb5_util.c @@ -81,12 +81,14 @@ kadm5_config_params global_params; usage() { fprintf(stderr, "Usage: " - "kdb5_util cmd [-r realm] [-d dbname] [-k mkeytype] [-M mkeyname]\n" - "\t [-m] [cmd options]\n" + "kdb5_util [-r realm] [-d dbname] [-k mkeytype] [-M mkeyname]\n" + "\t [-sf stashfilename] [-m] cmd [cmd_options]\n" "\tcreate [-s]\n" "\tdestroy [-f]\n" "\tstash [-f keyfile]\n" - "\tdump [-old] [-ov] [-b6] [-verbose] [filename [princs...]]\n" + "\tdump [-old] [-ov] [-b6] [-verbose]\n" + "\t [-mkey_convert] [-new_mkey_file mkey_file]\n" + "\t [-rev] [-recurse] [filename [princs...]]\n" "\tload [-old] [-ov] [-b6] [-verbose] [-update] filename\n" "\tdump_v4 [filename]\n" "\tload_v4 [-t] [-n] [-v] [-K] [-s stashfile] inputfile\n" diff --git a/src/kadmin/dbutil/loadv4.c b/src/kadmin/dbutil/loadv4.c index fb9c2e1..96f51cb 100644 --- a/src/kadmin/dbutil/loadv4.c +++ b/src/kadmin/dbutil/loadv4.c @@ -937,27 +937,7 @@ static krb5_error_code fixup_database(context, realm) krb5_context context; char * realm; { - krb5_db_entry entry; - krb5_error_code retval; - int nprincs; - krb5_boolean more; - - nprincs = 1; - if (retval = krb5_db_get_principal(context, &tgt_princ, &entry, - &nprincs, &more)) - return retval; - - if (nprincs == 0) - return 0; - - entry.attributes |= KRB5_KDB_SUPPORT_DESMD5; - - retval = krb5_db_put_principal(context, &entry, &nprincs); - - if (nprincs) - krb5_db_free_principal(context, &entry, nprincs); - - return retval; + return 0; } #else /* KRB5_KRB4_COMPAT */ diff --git a/src/kadmin/ktutil/ChangeLog b/src/kadmin/ktutil/ChangeLog index fbd4611..9d6b310 100644 --- a/src/kadmin/ktutil/ChangeLog +++ b/src/kadmin/ktutil/ChangeLog @@ -1,3 +1,14 @@ +2002-02-04 Ken Raeburn + + * ktutil_funcs.c (ktutil_write_srvtab): When keeping only + highest-numbered kvno, with some heuristics to deal with + wrap-around at 256. + +2000-05-19 Ken Raeburn + + * ktutil_funcs.c (ktutil_write_keytab): Reject a filename that's + too long. + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/kadmin/ktutil/ktutil_funcs.c b/src/kadmin/ktutil/ktutil_funcs.c index d4c0ce9..74531fc 100644 --- a/src/kadmin/ktutil/ktutil_funcs.c +++ b/src/kadmin/ktutil/ktutil_funcs.c @@ -317,7 +317,9 @@ krb5_error_code ktutil_write_keytab(context, list, name) krb5_error_code retval = 0; strcpy(ktname, "WRFILE:"); - strncat(ktname, name, MAXPATHLEN); + if (strlen (name) >= MAXPATHLEN) + return ENAMETOOLONG; + strncat (ktname, name, MAXPATHLEN); retval = krb5_kt_resolve(context, ktname, &kt); if (retval) return retval; @@ -500,9 +502,18 @@ krb5_error_code ktutil_write_srvtab(context, list, name) lp1 = prev->next; } lp1->entry = lp->entry; - } else if (lp1->entry->vno < lp->entry->vno) - /* Check if lp->entry is newer kvno; if so, update */ - lp1->entry = lp->entry; + } else { + /* This heuristic should be roughly the same as in the + keytab-reading code in libkrb5. */ + int offset = 0; + if (lp1->entry->vno > 240 || lp->entry->vno > 240) { + offset = 128; + } +#define M(X) (((X) + offset) % 256) + if (M(lp1->entry->vno) < M(lp->entry->vno)) + /* Check if lp->entry is newer kvno; if so, update */ + lp1->entry = lp->entry; + } } fp = fopen(name, "w"); if (!fp) { diff --git a/src/kadmin/passwd/ChangeLog b/src/kadmin/passwd/ChangeLog index 3833b63..e7ce2d6 100644 --- a/src/kadmin/passwd/ChangeLog +++ b/src/kadmin/passwd/ChangeLog @@ -1,3 +1,7 @@ +2000-05-08 Nalin Dahyabhai + + * xm_kpasswd.c (motif_com_err): Don't overflow buffer "buf". + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/kadmin/passwd/xm_kpasswd.c b/src/kadmin/passwd/xm_kpasswd.c index 0db1111..4232e3b 100644 --- a/src/kadmin/passwd/xm_kpasswd.c +++ b/src/kadmin/passwd/xm_kpasswd.c @@ -111,13 +111,15 @@ motif_com_err (whoami, code, fmt, args) if (whoami) { - strcpy(buf, whoami); - strcat(buf, ": "); + strncpy(buf, whoami, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; + strncat(buf, ": ", sizeof(buf) - 1 - strlen(buf)); } if (code) { - strcat(buf, error_message(code)); - strcat(buf, " "); + buf[sizeof(buf) - 1] = '\0'; + strncat(buf, error_message(code), sizeof(buf) - 1 - strlen(buf)); + strncat(buf, " ", sizeof(buf) - 1 - strlen(buf)); } if (fmt) { diff --git a/src/kadmin/server/ChangeLog b/src/kadmin/server/ChangeLog index d5f932e..da07371 100644 --- a/src/kadmin/server/ChangeLog +++ b/src/kadmin/server/ChangeLog @@ -1,3 +1,33 @@ +2002-10-30 Tom Yu + + * misc.c (chpass_principal_wrapper_3): Renamed from + chpass_principal_wrapper; calls chpass_principal_3 now. + (randkey_principal_wrapper_3): Renamed from + randkey_principal_wrapper; calls randkey_principal_3 now. Patch + from Ben Cox. + + * server_stubs.c (chpass_principal_1_svc) + (chpass_principal3_1_svc): Call chpass_principal_wrapper_3. + (chrand_principal_1_svc, chrand_principal3_1_svc): Call + randkey_principal_wrapper_3. Patch from Ben Cox. + + [pullups from trunk] + +2002-08-12 Tom Yu + + * server_stubs.c: Check return value from unparse_name() in lots + of places. Patch from Mark Levinson; fixes [krb5-admin/1140]. + [pullup from trunk] + +2000-06-21 Tom Yu + + * server_stubs.c: Kludge to rename xdr_free() properly. + +2000-05-23 Tom Yu + + * schpw.c (process_chpw_request): Add new argument to call to + chpass_principal_util() + 2000-03-16 Ken Raeburn Matt Crawford diff --git a/src/kadmin/server/misc.c b/src/kadmin/server/misc.c index 9dc3d9d..132a66e 100644 --- a/src/kadmin/server/misc.c +++ b/src/kadmin/server/misc.c @@ -14,7 +14,7 @@ static char *rcsid = "$Header$"; #include "misc.h" /* - * Function: chpass_principal_wrapper + * Function: chpass_principal_wrapper_3 * * Purpose: wrapper to kadm5_chpass_principal that checks to see if * pw_min_life has been reached. if not it returns an error. @@ -23,8 +23,12 @@ static char *rcsid = "$Header$"; * Arguments: * principal (input) krb5_principals whose password we are * changing - * passoword (input) passowrd we are going to change to. - * 0 on sucsess error code on failure. + * keepold (input) whether to preserve old keys + * n_ks_tuple (input) the number of key-salt tuples in ks_tuple + * ks_tuple (input) array of tuples indicating the caller's + * requested enctypes/salttypes + * password (input) password we are going to change to. + * 0 on success error code on failure. * * Requires: * kadm5_init to have been run. @@ -35,8 +39,12 @@ static char *rcsid = "$Header$"; * */ kadm5_ret_t -chpass_principal_wrapper(void *server_handle, - krb5_principal principal, char *password) +chpass_principal_wrapper_3(void *server_handle, + krb5_principal principal, + krb5_boolean keepold, + int n_ks_tuple, + krb5_key_salt_tuple *ks_tuple, + char *password) { krb5_int32 now; kadm5_ret_t ret; @@ -72,12 +80,14 @@ chpass_principal_wrapper(void *server_handle, if (ret = kadm5_free_principal_ent(handle->lhandle, &princ)) return ret; - return kadm5_chpass_principal(server_handle, principal, password); + return kadm5_chpass_principal_3(server_handle, principal, + keepold, n_ks_tuple, ks_tuple, + password); } /* - * Function: randkey_principal_wrapper + * Function: randkey_principal_wrapper_3 * * Purpose: wrapper to kadm5_randkey_principal which checks the passwords min. life. @@ -85,6 +95,10 @@ chpass_principal_wrapper(void *server_handle, * Arguments: * principal (input) krb5_principal whose password we are * changing + * keepold (input) whether to preserve old keys + * n_ks_tuple (input) the number of key-salt tuples in ks_tuple + * ks_tuple (input) array of tuples indicating the caller's + * requested enctypes/salttypes * key (output) new random key * 0, error code on error. * @@ -96,9 +110,12 @@ chpass_principal_wrapper(void *server_handle, * */ kadm5_ret_t -randkey_principal_wrapper(void *server_handle, - krb5_principal principal, - krb5_keyblock **keys, int *n_keys) +randkey_principal_wrapper_3(void *server_handle, + krb5_principal principal, + krb5_boolean keepold, + int n_ks_tuple, + krb5_key_salt_tuple *ks_tuple, + krb5_keyblock **keys, int *n_keys) { krb5_int32 now; @@ -134,5 +151,7 @@ randkey_principal_wrapper(void *server_handle, } if (ret = kadm5_free_principal_ent(handle->lhandle, &princ)) return ret; - return kadm5_randkey_principal(server_handle, principal, keys, n_keys); + return kadm5_randkey_principal_3(server_handle, principal, + keepold, n_ks_tuple, ks_tuple, + keys, n_keys); } diff --git a/src/kadmin/server/schpw.c b/src/kadmin/server/schpw.c index f246571..9de8116 100644 --- a/src/kadmin/server/schpw.c +++ b/src/kadmin/server/schpw.c @@ -229,7 +229,7 @@ process_chpw_request(context, server_handle, realm, s, keytab, sin, req, rep) ptr[clear.length] = '\0'; ret = kadm5_chpass_principal_util(server_handle, ticket->enc_part2->client, - ptr, NULL, strresult); + ptr, NULL, strresult, sizeof(strresult)); /* zap the password */ memset(clear.data, 0, clear.length); diff --git a/src/kadmin/server/server_stubs.c b/src/kadmin/server/server_stubs.c index 2eef601..4880331 100644 --- a/src/kadmin/server/server_stubs.c +++ b/src/kadmin/server/server_stubs.c @@ -18,6 +18,8 @@ static char *rcsid = "$Header$"; #include #include "misc.h" +#define xdr_free gssrpc_xdr_free /* XXX kludge */ + #define LOG_UNAUTH "Unauthorized request: %s, %s, client=%s, service=%s, addr=%s" #define LOG_DONE "Request: %s, %s, %s, client=%s, service=%s, addr=%s" @@ -255,7 +257,10 @@ create_principal_1(cprinc_arg *arg, struct svc_req *rqstp) ret.code = KADM5_FAILURE; return &ret; } - krb5_unparse_name(handle->context, arg->rec.principal, &prime_arg); + if (krb5_unparse_name(handle->context, arg->rec.principal, &prime_arg)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } if (CHANGEPW_SERVICE(rqstp) || !acl_check(handle->context, rqstp->rq_clntcred, ACL_ADD, @@ -309,7 +314,10 @@ create_principal3_1(cprinc3_arg *arg, struct svc_req *rqstp) ret.code = KADM5_FAILURE; return &ret; } - krb5_unparse_name(handle->context, arg->rec.principal, &prime_arg); + if (krb5_unparse_name(handle->context, arg->rec.principal, &prime_arg)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } if (CHANGEPW_SERVICE(rqstp) || !acl_check(handle->context, rqstp->rq_clntcred, ACL_ADD, @@ -365,7 +373,10 @@ delete_principal_1(dprinc_arg *arg, struct svc_req *rqstp) ret.code = KADM5_FAILURE; return &ret; } - krb5_unparse_name(handle->context, arg->princ, &prime_arg); + if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } if (CHANGEPW_SERVICE(rqstp) || !acl_check(handle->context, rqstp->rq_clntcred, ACL_DELETE, @@ -413,7 +424,10 @@ modify_principal_1(mprinc_arg *arg, struct svc_req *rqstp) ret.code = KADM5_FAILURE; return &ret; } - krb5_unparse_name(handle->context, arg->rec.principal, &prime_arg); + if (krb5_unparse_name(handle->context, arg->rec.principal, &prime_arg)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } if (CHANGEPW_SERVICE(rqstp) || !acl_check(handle->context, rqstp->rq_clntcred, ACL_MODIFY, @@ -467,8 +481,11 @@ rename_principal_1(rprinc_arg *arg, struct svc_req *rqstp) ret.code = KADM5_FAILURE; return &ret; } - krb5_unparse_name(handle->context, arg->src, &prime_arg1); - krb5_unparse_name(handle->context, arg->dest, &prime_arg2); + if (krb5_unparse_name(handle->context, arg->src, &prime_arg1) || + krb5_unparse_name(handle->context, arg->dest, &prime_arg2)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } sprintf(prime_arg, "%s to %s", prime_arg1, prime_arg2); ret.code = KADM5_OK; @@ -537,7 +554,10 @@ get_principal_1(gprinc_arg *arg, struct svc_req *rqstp) ret.code = KADM5_FAILURE; return &ret; } - krb5_unparse_name(handle->context, arg->princ, &prime_arg); + if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } if (! cmp_gss_krb5_name(handle, rqstp->rq_clntcred, arg->princ) && (CHANGEPW_SERVICE(rqstp) || !acl_check(handle->context, @@ -657,11 +677,14 @@ chpass_principal_1(chpass_arg *arg, struct svc_req *rqstp) ret.code = KADM5_FAILURE; return &ret; } - krb5_unparse_name(handle->context, arg->princ, &prime_arg); + if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } if (cmp_gss_krb5_name(handle, rqstp->rq_clntcred, arg->princ)) { - ret.code = chpass_principal_wrapper((void *)handle, arg->princ, - arg->pass); + ret.code = chpass_principal_wrapper_3((void *)handle, arg->princ, + FALSE, 0, NULL, arg->pass); } else if (!(CHANGEPW_SERVICE(rqstp)) && acl_check(handle->context, rqstp->rq_clntcred, ACL_CHANGEPW, arg->princ, NULL)) { @@ -715,11 +738,17 @@ chpass_principal3_1(chpass3_arg *arg, struct svc_req *rqstp) ret.code = KADM5_FAILURE; return &ret; } - krb5_unparse_name(handle->context, arg->princ, &prime_arg); + if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } if (cmp_gss_krb5_name(handle, rqstp->rq_clntcred, arg->princ)) { - ret.code = chpass_principal_wrapper((void *)handle, arg->princ, - arg->pass); + ret.code = chpass_principal_wrapper_3((void *)handle, arg->princ, + arg->keepold, + arg->n_ks_tuple, + arg->ks_tuple, + arg->pass); } else if (!(CHANGEPW_SERVICE(rqstp)) && acl_check(handle->context, rqstp->rq_clntcred, ACL_CHANGEPW, arg->princ, NULL)) { @@ -776,7 +805,10 @@ setv4key_principal_1(setv4key_arg *arg, struct svc_req *rqstp) ret.code = KADM5_FAILURE; return &ret; } - krb5_unparse_name(handle->context, arg->princ, &prime_arg); + if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } if (!(CHANGEPW_SERVICE(rqstp)) && acl_check(handle->context, rqstp->rq_clntcred, @@ -831,7 +863,10 @@ setkey_principal_1(setkey_arg *arg, struct svc_req *rqstp) ret.code = KADM5_FAILURE; return &ret; } - krb5_unparse_name(handle->context, arg->princ, &prime_arg); + if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } if (!(CHANGEPW_SERVICE(rqstp)) && acl_check(handle->context, rqstp->rq_clntcred, @@ -886,7 +921,10 @@ setkey_principal3_1(setkey3_arg *arg, struct svc_req *rqstp) ret.code = KADM5_FAILURE; return &ret; } - krb5_unparse_name(handle->context, arg->princ, &prime_arg); + if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } if (!(CHANGEPW_SERVICE(rqstp)) && acl_check(handle->context, rqstp->rq_clntcred, @@ -950,11 +988,14 @@ chrand_principal_1(chrand_arg *arg, struct svc_req *rqstp) free_server_handle(handle); return &ret; } - krb5_unparse_name(handle->context, arg->princ, &prime_arg); + if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } if (cmp_gss_krb5_name(handle, rqstp->rq_clntcred, arg->princ)) { - ret.code = randkey_principal_wrapper((void *)handle, - arg->princ, &k, &nkeys); + ret.code = randkey_principal_wrapper_3((void *)handle, arg->princ, + FALSE, 0, NULL, &k, &nkeys); } else if (!(CHANGEPW_SERVICE(rqstp)) && acl_check(handle->context, rqstp->rq_clntcred, ACL_CHANGEPW, arg->princ, NULL)) { @@ -1023,11 +1064,17 @@ chrand_principal3_1(chrand3_arg *arg, struct svc_req *rqstp) free_server_handle(handle); return &ret; } - krb5_unparse_name(handle->context, arg->princ, &prime_arg); + if (krb5_unparse_name(handle->context, arg->princ, &prime_arg)) { + ret.code = KADM5_BAD_PRINCIPAL; + return &ret; + } if (cmp_gss_krb5_name(handle, rqstp->rq_clntcred, arg->princ)) { - ret.code = randkey_principal_wrapper((void *)handle, - arg->princ, &k, &nkeys); + ret.code = randkey_principal_wrapper_3((void *)handle, arg->princ, + arg->keepold, + arg->n_ks_tuple, + arg->ks_tuple, + &k, &nkeys); } else if (!(CHANGEPW_SERVICE(rqstp)) && acl_check(handle->context, rqstp->rq_clntcred, ACL_CHANGEPW, arg->princ, NULL)) { diff --git a/src/kadmin/testing/proto/ChangeLog b/src/kadmin/testing/proto/ChangeLog index e1fedaf..a69cf30 100644 --- a/src/kadmin/testing/proto/ChangeLog +++ b/src/kadmin/testing/proto/ChangeLog @@ -1,3 +1,13 @@ +2000-05-31 Ken Raeburn + + * kdc.conf.proto: Use des3 master key. + +2000-05-09 Ken Raeburn + + * krb5.conf.proto: Set dns_fallback=no. + + * kdc.conf.proto: Add des3 to supported_enctypes. + Wed Jan 21 12:44:25 1998 Ezra Peisach * kdc.conf.proto: Add kpasswd_port line so kadmind can start as diff --git a/src/kadmin/testing/proto/kdc.conf.proto b/src/kadmin/testing/proto/kdc.conf.proto index 69d6041..6f9edeb 100644 --- a/src/kadmin/testing/proto/kdc.conf.proto +++ b/src/kadmin/testing/proto/kdc.conf.proto @@ -11,7 +11,6 @@ dict_file = __K5ROOT__/ovsec_adm.dict kadmind_port = 1751 kpasswd_port = 1752 - master_key_type = des-cbc-crc - supported_enctypes = des-cbc-crc:normal des-cbc-crc:v4 des-cbc-md5:normal des-cbc-raw:normal + master_key_type = des3-hmac-sha1 + supported_enctypes = des3-hmac-sha1:normal des-cbc-crc:normal des-cbc-crc:v4 des-cbc-md5:normal des-cbc-raw:normal } - diff --git a/src/kadmin/testing/proto/krb5.conf.proto b/src/kadmin/testing/proto/krb5.conf.proto index a063815..5521267 100644 --- a/src/kadmin/testing/proto/krb5.conf.proto +++ b/src/kadmin/testing/proto/krb5.conf.proto @@ -1,6 +1,7 @@ [libdefaults] default_realm = __REALM__ default_keytab_name = FILE:__K5ROOT__/v5srvtab + dns_fallback = no [realms] __REALM__ = { diff --git a/src/kadmin/testing/util/ChangeLog b/src/kadmin/testing/util/ChangeLog index e3d88d1..d1d9c42 100644 --- a/src/kadmin/testing/util/ChangeLog +++ b/src/kadmin/testing/util/ChangeLog @@ -1,3 +1,14 @@ +2002-02-04 Ken Raeburn + + * tcl_kadm5.c (unparse_err): Print error message, not just number, + to stderr for unrecognized error code. + * tcl_ovsec_kadm.c (unparse_err): Likewise. + +2000-05-23 Tom Yu + + * tcl_kadm5.c (tcl_kadm5_chpass_principal_util): Add new argument + to call to chpass_principal_util(). + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/kadmin/testing/util/tcl_kadm5.c b/src/kadmin/testing/util/tcl_kadm5.c index c334850..e85b4f5 100644 --- a/src/kadmin/testing/util/tcl_kadm5.c +++ b/src/kadmin/testing/util/tcl_kadm5.c @@ -403,7 +403,7 @@ static Tcl_DString *unparse_err(kadm5_ret_t code) case KRB5_CONFIG_BADFORMAT: code_string = "KRB5_CONFIG_BADFORMAT"; break; case EINVAL: code_string = "EINVAL"; break; case ENOENT: code_string = "ENOENT"; break; - default: fprintf(stderr, "**** CODE %d ***\n", code); code_string = "UNKNOWN"; break; + default: fprintf(stderr, "**** CODE %d (%s) ***\n", code, error_message (code)); code_string = "UNKNOWN"; break; } error_string = (char *) error_message(code); @@ -1965,7 +1965,8 @@ int tcl_kadm5_chpass_principal_util(ClientData clientData, override_qual, #endif pw_ret_var ? &pw_ret : 0, - msg_ret_var ? msg_ret : 0); + msg_ret_var ? msg_ret : 0, + msg_ret_var ? sizeof(msg_ret) : 0); if (ret == KADM5_OK) { if (pw_ret_var && diff --git a/src/kadmin/testing/util/tcl_ovsec_kadm.c b/src/kadmin/testing/util/tcl_ovsec_kadm.c index 9e27e92..16684e2 100644 --- a/src/kadmin/testing/util/tcl_ovsec_kadm.c +++ b/src/kadmin/testing/util/tcl_ovsec_kadm.c @@ -372,7 +372,7 @@ static Tcl_DString *unparse_err(ovsec_kadm_ret_t code) case KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN: code_string = "KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN"; break; case EINVAL: code_string = "EINVAL"; break; case ENOENT: code_string = "ENOENT"; break; - default: fprintf(stderr, "**** CODE %d ***\n", code); code_string = "UNKNOWN"; break; + default: fprintf(stderr, "**** CODE %d (%s) ***\n", code, error_message (code)); code_string = "UNKNOWN"; break; } error_string = (char *) error_message(code); diff --git a/src/kadmin/v4server/ChangeLog b/src/kadmin/v4server/ChangeLog index c036eb8..76c0fe3 100644 --- a/src/kadmin/v4server/ChangeLog +++ b/src/kadmin/v4server/ChangeLog @@ -1,3 +1,42 @@ +2002-11-01 Tom Yu + + * kadm_ser_wrap.c (kadm_ser_in): Apply fix for MITKRB5-SA-2002-002 + buffer overflow. + [pullup from trunk] + +2002-08-13 Tom Yu + + * acl_files.c (canon;): Properly handle appending of the local + realm, which was botched due to a buffer-overflow patch. + [pullup from trunk] + +2000-05-23 Ken Raeburn + + * admin_server.c (main, case 'r'): Reject realm name that's too + long. + + * acl_files.c (acl_load): Return error if name too long. + + * kadm_err.et (KADM_REALM_TOO_LONG): New error code. + * kadm_ser_wrap.c (kadm_ser_init): Return it instead of truncating + a too-long realm name. + +2000-05-23 Nalin Dahyabhai + + * acl_files.c (acl_canonicalize_principal): If the principal name + would be too long, return a zero-length string to mark it as invalid. + (acl_load): Don't add the principal to the hash if it's invalid. + (acl_add): Don't check the principal if it's invalid. + (acl_delete): Don't try to delete the principal if it's invalid. + + * kadm_ser_wrap.c (kadm_ser_init): Truncate "server_parm.krbrlm" + if "realm" is too long. + +2000-05-23 Tom Yu + + * kadm_server.c (kadm_ser_cpw): Add new arg to call to + chpass_principal_util(). + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/kadmin/v4server/acl_files.c b/src/kadmin/v4server/acl_files.c index 22a0007..e68d384 100644 --- a/src/kadmin/v4server/acl_files.c +++ b/src/kadmin/v4server/acl_files.c @@ -69,7 +69,8 @@ void acl_canonicalize_principal(principal, canon) char *principal; char *canon; { - char *dot, *atsign, *end; + char *dot, *atsign, *end, *canon_save = canon; + char realm[REALM_SZ]; int len; dot = strchr(principal, INST_SEP); @@ -94,18 +95,33 @@ char *canon; /* Get the principal name */ len = MIN(ANAME_SZ, COR(dot, COR(atsign, end)) - principal); - strncpy(canon, principal, len); - canon += len; + if(canon + len < canon_save + MAX_PRINCIPAL_SIZE) { + strncpy(canon, principal, len); + canon += len; + } else { + strcpy(canon, ""); + return; + } /* Add INST_SEP */ - *canon++ = INST_SEP; + if(canon + 1 < canon_save + MAX_PRINCIPAL_SIZE) { + *canon++ = INST_SEP; + } else { + strcpy(canon, ""); + return; + } /* Get the instance, if it exists */ if(dot != NULL) { ++dot; len = MIN(INST_SZ, COR(atsign, end) - dot); - strncpy(canon, dot, len); - canon += len; + if(canon + len < canon_save + MAX_PRINCIPAL_SIZE) { + strncpy(canon, dot, len); + canon += len; + } else { + strcpy(canon, ""); + return; + } } /* Add REALM_SEP */ @@ -116,11 +132,28 @@ char *canon; if(atsign != NULL) { ++atsign; len = MIN(REALM_SZ, end - atsign); - strncpy(canon, atsign, len); - canon += len; - *canon++ = '\0'; - } else if(krb_get_lrealm(canon, 1) != KSUCCESS) { - strcpy(canon, KRB_REALM); + if(canon + len + 1 < canon_save + MAX_PRINCIPAL_SIZE) { + strncpy(canon, atsign, len); + canon += len; + *canon++ = '\0'; + } else { + strcpy(canon, ""); + return; + } + } else if(krb_get_lrealm(realm, 1) != KSUCCESS) { + if(canon + strlen(KRB_REALM) < canon_save + MAX_PRINCIPAL_SIZE) { + strcpy(canon, KRB_REALM); + } else { + strcpy(canon, ""); + return; + } + } else { + if (canon + strlen(realm) < canon_save + MAX_PRINCIPAL_SIZE) { + strcpy(canon, realm); + } else { + strcpy(canon, ""); + return; + } } } @@ -399,7 +432,11 @@ char *name; } /* Set up the acl */ - strcpy(acl_cache[i].filename, name); + if (strlen (name) >= sizeof (acl_cache[i].filename) - 1) { + return -1; + } + strncpy(acl_cache[i].filename, name, sizeof(acl_cache[i].filename) - 1); + acl_cache[i].filename[sizeof(acl_cache[i].filename) - 1] = '\0'; if((acl_cache[i].fd = open(name, O_RDONLY, 0)) < 0) return(-1); /* Force reload */ acl_cache[i].acl = (struct hashtbl *) 0; @@ -426,7 +463,9 @@ char *name; while(fgets(buf, sizeof(buf), f) != NULL) { nuke_whitespace(buf); acl_canonicalize_principal(buf, canon); - add_hash(acl_cache[i].acl, canon); + if(strlen(canon) > 0) { + add_hash(acl_cache[i].acl, canon); + } } fclose(f); acl_cache[i].status = s; @@ -459,6 +498,9 @@ char *principal; acl_canonicalize_principal(principal, canon); + /* Is it an invalid principal name? */ + if(strlen(canon) == 0) return(0); + /* Is it there? */ if(acl_exact_match(acl, canon)) return(1); @@ -489,6 +531,9 @@ char *principal; acl_canonicalize_principal(principal, canon); + /* Is it an invalid principal name? */ + if(strlen(canon) == 0) return(-1); + if((new = acl_lock_file(acl)) == NULL) return(-1); if((acl_exact_match(acl, canon)) || (idx = acl_load(acl)) < 0) { @@ -523,6 +568,9 @@ char *principal; acl_canonicalize_principal(principal, canon); + /* Is it an invalid principal name? */ + if(strlen(canon) == 0) return(-1); + if((new = acl_lock_file(acl)) == NULL) return(-1); if((!acl_exact_match(acl, canon)) || (idx = acl_load(acl)) < 0) { diff --git a/src/kadmin/v4server/admin_server.c b/src/kadmin/v4server/admin_server.c index 90bf087..cd8742d 100644 --- a/src/kadmin/v4server/admin_server.c +++ b/src/kadmin/v4server/admin_server.c @@ -149,6 +149,10 @@ char *argv[]; fascist_cpw = 0; break; case 'r': + if (strlen (optarg) + 1 > REALM_SZ) { + com_err(argv[0], 0, "realm name `%s' too long", optarg); + exit(1); + } (void) strncpy(krbrlm, optarg, sizeof(krbrlm) - 1); break; case 'k': diff --git a/src/kadmin/v4server/kadm_err.et b/src/kadmin/v4server/kadm_err.et index a192730..07ab9da 100644 --- a/src/kadmin/v4server/kadm_err.et +++ b/src/kadmin/v4server/kadm_err.et @@ -54,4 +54,5 @@ ec KADM_INSECURE_PW, "Insecure password rejected" ec KADM_PW_MISMATCH, "Cleartext password and DES key did not match" ec KADM_NOT_SERV_PRINC, "Invalid principal for change srvtab request" +ec KADM_REALM_TOO_LONG, "Realm name too long" end diff --git a/src/kadmin/v4server/kadm_ser_wrap.c b/src/kadmin/v4server/kadm_ser_wrap.c index bca814d..e98a47b 100644 --- a/src/kadmin/v4server/kadm_ser_wrap.c +++ b/src/kadmin/v4server/kadm_ser_wrap.c @@ -47,7 +47,7 @@ kadm_ser_init(inter, realm, params) kadm_ser_init(inter, realm) int inter; /* interactive or from file */ char realm[]; -#endif +#endif { struct servent *sep; struct hostent *hp; @@ -64,7 +64,11 @@ kadm_ser_init(inter, realm) (void) strcpy(server_parm.sname, PWSERV_NAME); (void) strcpy(server_parm.sinst, KRB_MASTER); - (void) strcpy(server_parm.krbrlm, realm); + if (strlen (realm) > REALM_SZ) + return KADM_REALM_TOO_LONG; + (void) strncpy(server_parm.krbrlm, realm, sizeof(server_parm.krbrlm)-1); + server_parm.krbrlm[sizeof(server_parm.krbrlm) - 1] = '\0'; + if (krb5_425_conv_principal(kadm_context, server_parm.sname, server_parm.sinst, server_parm.krbrlm, &server_parm.sprinc)) @@ -166,14 +170,21 @@ int *dat_len; u_char *retdat, *tmpdat; int retval, retlen; - if (strncmp(KADM_VERSTR, (char *)*dat, KADM_VERSIZE)) { + if ((*dat_len < KADM_VERSIZE + sizeof(krb5_ui_4)) + || strncmp(KADM_VERSTR, (char *)*dat, KADM_VERSIZE)) { errpkt(dat, dat_len, KADM_BAD_VER); return KADM_BAD_VER; } in_len = KADM_VERSIZE; /* get the length */ - if ((retc = stv_long(*dat, &r_len, in_len, *dat_len)) < 0) + if ((retc = stv_long(*dat, &r_len, in_len, *dat_len)) < 0 + || (r_len > *dat_len - KADM_VERSIZE - sizeof(krb5_ui_4)) + || (*dat_len - r_len - KADM_VERSIZE - + sizeof(krb5_ui_4) > sizeof(authent.dat))) { + errpkt(dat, dat_len, KADM_LENGTH_ERROR); return KADM_LENGTH_ERROR; + } + in_len += retc; authent.length = *dat_len - r_len - KADM_VERSIZE - sizeof(krb5_ui_4); memcpy((char *)authent.dat, (char *)(*dat) + in_len, authent.length); diff --git a/src/kadmin/v4server/kadm_server.c b/src/kadmin/v4server/kadm_server.c index 687259b..886620f 100644 --- a/src/kadmin/v4server/kadm_server.c +++ b/src/kadmin/v4server/kadm_server.c @@ -309,7 +309,8 @@ int *outlen; *msg_ret = '\0'; } else { retval = kadm5_chpass_principal_util(kadm5_handle, user_princ, - pword, NULL, msg_ret); + pword, NULL, msg_ret, + sizeof(msg_ret)); msg_ptr = msg_ret; } (void) krb5_free_principal(kadm_context, user_princ); diff --git a/src/kadmin/v5passwdd/ChangeLog b/src/kadmin/v5passwdd/ChangeLog index a63cc97..1fedd80 100644 --- a/src/kadmin/v5passwdd/ChangeLog +++ b/src/kadmin/v5passwdd/ChangeLog @@ -1,3 +1,21 @@ +2000-05-24 Ken Raeburn + Ezra Peisach + + * proto_serv.c (proto_serv): Don't overflow err_str. Pass data + pointer and not a krb5_data to sprintf. Remove unused variable + adm_errmsg. Remove unused label done. Declare variable + mime_setting only if MIME_SUPPORTED is defined. Make variables + db_opened and kret volatile. + (proto_fmt_reply_msg): Unused variable deleted. + +2000-05-23 Tom Yu + + * kadm5_defs.h: Add argument for length of error string. + + * main.c (pwd_change): Add argument for length of error string. + + * proto_serv.c (proto_serv): Fix up call to pwd_change(). + 2000-02-28 Ezra Peisach * proto_serv.c (proto_serv): For error return,strdup the returned diff --git a/src/kadmin/v5passwdd/kadm5_defs.h b/src/kadmin/v5passwdd/kadm5_defs.h index 08650bd..17ec2e5 100644 --- a/src/kadmin/v5passwdd/kadm5_defs.h +++ b/src/kadmin/v5passwdd/kadm5_defs.h @@ -259,7 +259,8 @@ krb5_int32 pwd_change krb5_ticket *, krb5_data *, krb5_data *, - char [])); + char [], + int)); #if 0 diff --git a/src/kadmin/v5passwdd/main.c b/src/kadmin/v5passwdd/main.c index a9b381e..cec5bf8 100644 --- a/src/kadmin/v5passwdd/main.c +++ b/src/kadmin/v5passwdd/main.c @@ -230,7 +230,7 @@ krb5_error_code key_close_db(krb5_context context) krb5_int32 pwd_change(kcontext, debug_level, auth_context, ticket, - olddata, newdata, err_str) + olddata, newdata, err_str, err_str_len) krb5_context kcontext; int debug_level; krb5_auth_context auth_context; @@ -238,6 +238,7 @@ pwd_change(kcontext, debug_level, auth_context, ticket, krb5_data *olddata; krb5_data *newdata; char err_str[]; + int err_str_len; { kadm5_ret_t ret; krb5_int32 now; @@ -301,7 +302,7 @@ pwd_change(kcontext, debug_level, auth_context, ticket, principal, newdata->data, NULL, - err_str)) + err_str, err_str_len)) return(KRB5_ADM_PW_UNACCEPT); return(KRB5_ADM_SUCCESS); diff --git a/src/kadmin/v5passwdd/proto_serv.c b/src/kadmin/v5passwdd/proto_serv.c index 413c5ef..419f861 100644 --- a/src/kadmin/v5passwdd/proto_serv.c +++ b/src/kadmin/v5passwdd/proto_serv.c @@ -52,7 +52,6 @@ static const char *proto_rd_cmd_msg = "\004%d: cannot read administrative protoc static const char *proto_db_open_msg = "\004%d: cannot open database"; static const char *proto_db_close_msg = "\004%d: cannot close database"; static const char *proto_wr_reply_msg = "\004%d: cannot write administrative protocol reply"; -static const char *proto_fmt_reply_msg = "\004%d: cannot format administrative protocol reply"; extern char *programname; static int proto_proto_timeout = -1; @@ -109,7 +108,7 @@ proto_serv(kcontext, my_id, cl_sock, sv_p, cl_p) void *sv_p; void *cl_p; { - krb5_error_code kret; + volatile krb5_error_code kret; struct sockaddr_in *cl_addr; struct sockaddr_in *sv_addr; @@ -127,12 +126,14 @@ proto_serv(kcontext, my_id, cl_sock, sv_p, cl_p) #endif /* POSIX_SIGNALS */ char *curr_lang = (char *) NULL; +#ifdef MIME_SUPPORTED krb5_boolean mime_setting = 0; +#endif krb5_int32 num_args; krb5_data *arglist; - krb5_boolean db_opened; + volatile krb5_boolean db_opened; cl_addr = (struct sockaddr_in *) cl_p; sv_addr = (struct sockaddr_in *) sv_p; @@ -286,6 +287,7 @@ proto_serv(kcontext, my_id, cl_sock, sv_p, cl_p) */ while (1) { krb5_int32 cmd_error; + /* If this size changed, change the sprintf below */ char err_str[1024]; krb5_int32 cmd_repl_ncomps; krb5_data *cmd_repl_complist; @@ -412,7 +414,8 @@ proto_serv(kcontext, my_id, cl_sock, sv_p, cl_p) ticket, &arglist[1], &arglist[2], - &err_str); + err_str, + sizeof(err_str)); } else { DPRINT(DEBUG_REQUESTS, proto_debug_level, @@ -732,7 +735,7 @@ proto_serv(kcontext, my_id, cl_sock, sv_p, cl_p) ("> %d:UNKNOWN command %s\n", my_id, arglist[0].data)); cmd_error = KRB5_ADM_CMD_UNKNOWN; - sprintf(err_str, "Command %s not supported.", arglist[0]); + sprintf(err_str, "Command %-.900s not supported", arglist[0].data); /* XXX Knows size of err_str. */ } } else { @@ -770,7 +773,6 @@ proto_serv(kcontext, my_id, cl_sock, sv_p, cl_p) } } else { - char *adm_errmsg; krb5_data reply_comps; reply_comps.data = err_str; @@ -858,7 +860,6 @@ proto_serv(kcontext, my_id, cl_sock, sv_p, cl_p) key_close_db(kcontext); close(cl_sock); - done: DPRINT(DEBUG_CALLS, proto_debug_level, ("X proto_serv() = %d\n", kret)); return(kret); } diff --git a/src/kdc/ChangeLog b/src/kdc/ChangeLog index d0bbda2..537c94a 100644 --- a/src/kdc/ChangeLog +++ b/src/kdc/ChangeLog @@ -1,3 +1,141 @@ +2002-11-03 Tom Yu + + * do_as_req.c (process_as_req): Fix previous patch; it caused an + uninitialized pointer to be dereferenced under certain error + conditions. + [pullup from trunk] + +2002-10-30 Sam Hartman + + * kdc_util.c (add_to_transited): Don't include trailing null in + transited encoding length; doing so breaks using codee + [pullup from trunk] + +2002-10-30 Tom Yu + + * do_as_req.c (process_as_req): Apply fix from Kevin Coffman to + avoid leaking padata. + [pullup from trunk] + +2002-08-15 Tom Yu + + * kerberos_v4.c: For consistency, check for both DISALLOW_ALL_TIX + and DISALLOW_SVR when looking up services. + [pullup from trunk] + +2002-08-12 Sam Hartman + + * kdc_preauth.c (get_etype_info): We get KRB5_KDB_NO_MATCHING_KEY + not ENOENT; per 5.27 of kdb_xdr.c. + [pullup from trunk] + +2001-10-29 Ken Raeburn + + * network.c: Don't cause net/if.h to be included multiple times. + +2001-10-25 Tom Yu + + * do_as_req.c (process_as_req: Treat SUPPORT_DESMD5 as if it were + always cleared. + + * do_tgs_req.c (process_tgs_req): Treat SUPPORT_DESMD5 as if it + were always cleared. + +2001-10-24 Tom Yu + + * kdc_util.c (select_session_keytype): Don't issue session key + enctype that is not in permitted_enctypes. + (dbentry_supports_enctype): For now, always treat SUPPORT_DESMD5 + as if it were cleared. + +2001-10-12 Tom Yu + + * kdc_util.c (ktypes2str): New function; construct a string + containing a list of enctypes, given a number and list of + enctypes. + (rep_etypes2str): New function; construct a string indicating all + three enctypes associated with a KDC reply. + [pullup 5.99->5.101 from trunk] + + * kdc_util.h: Add prototypes for ktypes2str() and + rep_etypes2str(). + [pullup 5.46->5.47 from trunk] + + * do_as_req.c (process_as_req): Call ktypes2str() and + rep_etypes2str() as appropriate. + [pullup 5.80->5.81 from trunk] + + * do_tgs_req.c (process_tgs_req): Call ktypes2str() and + rep_etypes2str() as appropriate. + [pullup 5.77->5.78 from trunk] + +2001-10-11 Ezra Peisach + + * do_as_req.c: If KRBCONF_KDC_MODIFIES_KDB defined, produce code + that compiles and works. + [pullup 5.78->5.79 from trunk] + +2001-10-05 Ken Raeburn + + * do_tgs_req.c (process_tgs_req): Fix logging of bad transit path + info. + +2001-09-25 Ken Raeburn + + * do_tgs_req.c (process_tgs_req): If disable-transited-check + option isn't set, try to verify transit path. If + reject_bad_transit flag is set and transit path isn't verified, + reject the request. Use a temporary variable to simplify + references to the second ticket. + * extern.h (struct __kdc_realm_data): Add new field + realm_reject_bad_transit. + (find_realm_data): Declare. + (reject_bad_transit): New macro. + * main.c (find_realm_data): Delete declaration. + (init_realm): Copy reject-bad-transit value or use default. + * rtest.c (find_realm_data): Define dummy version. + +2001-02-02 Ken Raeburn + + * network.c (foreach_localaddr): Sync with lib/krb5/os/localaddr.c + version. + +2000-05-17 Tom Yu + + * kerberos_v4.c (process_v4): Zero out v4_pkt.mbz. + (kerberos_v4): Fix handling of APPL_REQUEST messages to deal with + ridiculously long realms, etc. Fix up some calls to + kerb_err_reply() to be more useful. Set req_*_ptr before any + possible calls to kerb_err_reply(). + +2000-05-11 Nalin Dahyabhai + + * kdc_util.c (add_to_transited): Use strncpy/strncat when building + data in buffers so as not to overrun "prev", "current", and "exp". + * kerberos_v4.c (process_v4): Don't assume that the realm is null- + terminated. + (set_tgtkey): Truncate realm name if it's too long. + +2000-04-28 Ken Raeburn + Nalin Dahyabhai + + * kdc_util.c (add_to_transited): Use strncpy/strncat when building + data in buffers. Fix some limit checks. + * kerberos_v4.c (kerb_err_reply): Use strncat so as not to overrun + error buffer. + +2000-04-22 Ken Raeburn + + * network.c: Include stddef.h. + (foreach_localaddr): Check each address against previously used + addresses, and skip duplicates, in case multiple interfaces have + the same address. + +2000-04-21 Ken Raeburn + + * network.c (foreach_localaddr): If called functions fail, drop + out of loop and return nonzero. + 2000-03-14 Ken Raeburn * sock2p.c: New file. diff --git a/src/kdc/do_as_req.c b/src/kdc/do_as_req.c index 158747e..0cdc9c37 100644 --- a/src/kdc/do_as_req.c +++ b/src/kdc/do_as_req.c @@ -80,12 +80,18 @@ krb5_data **response; /* filled in with a response packet */ register int i; krb5_timestamp until, rtime; char *cname = 0, *sname = 0, *fromstring = 0; + char ktypestr[128]; + char rep_etypestr[128]; ticket_reply.enc_part.ciphertext.data = 0; e_data.data = 0; encrypting_key.contents = 0; + reply.padata = 0; session_key.contents = 0; + ktypes2str(ktypestr, sizeof(ktypestr), + request->nktypes, request->ktype); + #ifdef HAVE_NETINET_IN_H if (from->address->addrtype == ADDRTYPE_INET) fromstring = (char *) inet_ntoa(*(struct in_addr *)from->address->contents); @@ -318,9 +324,6 @@ krb5_data **response; /* filled in with a response packet */ status = "DECRYPT_SERVER_KEY"; goto errout; } - if ((encrypting_key.enctype == ENCTYPE_DES_CBC_CRC) && - (isflagset(server.attributes, KRB5_KDB_SUPPORT_DESMD5))) - encrypting_key.enctype = ENCTYPE_DES_CBC_MD5; errcode = krb5_encrypt_tkt_part(kdc_context, &encrypting_key, &ticket_reply); krb5_free_keyblock_contents(kdc_context, &encrypting_key); @@ -363,7 +366,6 @@ krb5_data **response; /* filled in with a response packet */ /* Start assembling the response */ reply.msg_type = KRB5_AS_REP; - reply.padata = 0; reply.client = request->client; reply.ticket = &ticket_reply; reply_encpart.session = &session_key; @@ -411,8 +413,14 @@ krb5_data **response; /* filled in with a response packet */ memset(reply.enc_part.ciphertext.data, 0, reply.enc_part.ciphertext.length); free(reply.enc_part.ciphertext.data); - krb5_klog_syslog(LOG_INFO, "AS_REQ %s(%d): ISSUE: authtime %d, %s for %s", - fromstring, portnum, authtime, cname, sname); + rep_etypes2str(rep_etypestr, sizeof(rep_etypestr), &reply); + krb5_klog_syslog(LOG_INFO, + "AS_REQ (%s) %s(%d): ISSUE: authtime %d, " + "%s, %s for %s", + ktypestr, + fromstring, portnum, authtime, + rep_etypestr, + cname, sname); #ifdef KRBCONF_KDC_MODIFIES_KDB /* @@ -425,7 +433,8 @@ krb5_data **response; /* filled in with a response packet */ errout: if (status) - krb5_klog_syslog(LOG_INFO, "AS_REQ %s(%d): %s: %s for %s%s%s", + krb5_klog_syslog(LOG_INFO, "AS_REQ (%s) %s(%d): %s: %s for %s%s%s", + ktypestr, fromstring, portnum, status, cname ? cname : "", sname ? sname : "", @@ -439,7 +448,10 @@ errout: errcode = prepare_error_as(request, errcode, &e_data, response); } - krb5_free_keyblock_contents(kdc_context, &encrypting_key); + if (encrypting_key.contents) + krb5_free_keyblock_contents(kdc_context, &encrypting_key); + if (reply.padata) + krb5_free_pa_data(kdc_context, reply.padata); if (cname) free(cname); @@ -458,7 +470,7 @@ errout: kdc_active_realm->realm_dbname); krb5_db_init(kdc_context); /* Reset master key */ - krb5_db_set_mkey(kdc_context, &kdc_active_realm->realm_encblock); + krb5_db_set_mkey(kdc_context, &kdc_active_realm->realm_mkey); } #endif /* KRBCONF_KDC_MODIFIES_KDB */ krb5_db_free_principal(kdc_context, &client, c_nprincs); diff --git a/src/kdc/do_tgs_req.c b/src/kdc/do_tgs_req.c index e5c6d1a..103ab16 100644 --- a/src/kdc/do_tgs_req.c +++ b/src/kdc/do_tgs_req.c @@ -1,7 +1,7 @@ /* * kdc/do_tgs_req.c * - * Copyright 1990,1991 by the Massachusetts Institute of Technology. + * Copyright 1990,1991,2001 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -59,10 +59,10 @@ static krb5_error_code prepare_error_tgs PROTOTYPE((krb5_kdc_req *, /*ARGSUSED*/ krb5_error_code process_tgs_req(pkt, from, portnum, response) -krb5_data *pkt; -const krb5_fulladdr *from; /* who sent it ? */ -int portnum; -krb5_data **response; /* filled in with a response packet */ + krb5_data *pkt; + const krb5_fulladdr *from; /* who sent it ? */ + int portnum; + krb5_data **response; /* filled in with a response packet */ { krb5_keyblock * subkey; krb5_kdc_req *request = 0; @@ -90,6 +90,8 @@ krb5_data **response; /* filled in with a response packet */ register int i; int firstpass = 1; const char *status = 0; + char ktypestr[128]; + char rep_etypestr[128]; session_key.contents = 0; @@ -97,6 +99,8 @@ krb5_data **response; /* filled in with a response packet */ if (retval) return retval; + ktypes2str(ktypestr, sizeof(ktypestr), + request->nktypes, request->ktype); /* * setup_server_realm() sets up the global realm-specific data pointer. */ @@ -491,6 +495,36 @@ tgt_again: } newtransited = 1; } + if (!isflagset (request->kdc_options, KDC_OPT_DISABLE_TRANSITED_CHECK)) { + errcode = krb5_check_transited_list (kdc_context, + &enc_tkt_reply.transited.tr_contents, + krb5_princ_realm (kdc_context, header_ticket->enc_part2->client), + krb5_princ_realm (kdc_context, request->server)); + if (errcode == 0) { + setflag (enc_tkt_reply.flags, TKT_FLG_TRANSIT_POLICY_CHECKED); + } else if (errcode == KRB5KRB_AP_ERR_ILL_CR_TKT) + krb5_klog_syslog (LOG_INFO, + "bad realm transit path from '%s' to '%s' via '%.*s'", + cname ? cname : "", + sname ? sname : "", + enc_tkt_reply.transited.tr_contents.length, + enc_tkt_reply.transited.tr_contents.data); + else + krb5_klog_syslog (LOG_ERR, + "unexpected error checking transit from '%s' to '%s' via '%.*s': %s", + cname ? cname : "", + sname ? sname : "", + enc_tkt_reply.transited.tr_contents.length, + enc_tkt_reply.transited.tr_contents.data, + error_message (errcode)); + } else + krb5_klog_syslog (LOG_ERR, "not checking transit path"); + if (reject_bad_transit + && !isflagset (enc_tkt_reply.flags, TKT_FLG_TRANSIT_POLICY_CHECKED)) { + errcode = KRB5KDC_ERR_POLICY; + status = "BAD_TRANSIT"; + goto cleanup; + } ticket_reply.enc_part2 = &enc_tkt_reply; @@ -505,27 +539,26 @@ tgt_again: * Make sure the client for the second ticket matches * requested server. */ - if (!krb5_principal_compare(kdc_context, request->server, - request->second_ticket[st_idx]->enc_part2->client)) { - if ((errcode = krb5_unparse_name(kdc_context, - request->second_ticket[st_idx]->enc_part2->client, - &tmp))) + krb5_enc_tkt_part *t2enc = request->second_ticket[st_idx]->enc_part2; + krb5_principal client2 = t2enc->client; + if (!krb5_principal_compare(kdc_context, request->server, client2)) { + if ((errcode = krb5_unparse_name(kdc_context, client2, &tmp))) tmp = 0; - krb5_klog_syslog(LOG_INFO, "TGS_REQ %s(%d): 2ND_TKT_MISMATCH: authtime %d, %s for %s, 2nd tkt client %s", - fromstring, portnum, authtime, - cname ? cname : "", - sname ? sname : "", - tmp ? tmp : ""); + krb5_klog_syslog(LOG_INFO, + "TGS_REQ %s(%d): 2ND_TKT_MISMATCH: " + "authtime %d, %s for %s, 2nd tkt client %s", + fromstring, portnum, authtime, + cname ? cname : "", + sname ? sname : "", + tmp ? tmp : ""); errcode = KRB5KDC_ERR_SERVER_NOMATCH; goto cleanup; } ticket_reply.enc_part.kvno = 0; - ticket_reply.enc_part.enctype = - request->second_ticket[st_idx]->enc_part2->session->enctype; - if ((errcode = krb5_encrypt_tkt_part(kdc_context, - request->second_ticket[st_idx]->enc_part2->session, - &ticket_reply))) { + ticket_reply.enc_part.enctype = t2enc->session->enctype; + if ((errcode = krb5_encrypt_tkt_part(kdc_context, t2enc->session, + &ticket_reply))) { status = "2ND_TKT_ENCRYPT"; goto cleanup; } @@ -551,9 +584,6 @@ tgt_again: status = "DECRYPT_SERVER_KEY"; goto cleanup; } - if ((encrypting_key.enctype == ENCTYPE_DES_CBC_CRC) && - (isflagset(server.attributes, KRB5_KDB_SUPPORT_DESMD5))) - encrypting_key.enctype = ENCTYPE_DES_CBC_MD5; errcode = krb5_encrypt_tkt_part(kdc_context, &encrypting_key, &ticket_reply); krb5_free_keyblock_contents(kdc_context, &encrypting_key); @@ -619,13 +649,22 @@ tgt_again: free(reply.enc_part.ciphertext.data); cleanup: - if (status) - krb5_klog_syslog(LOG_INFO, "TGS_REQ %s(%d): %s: authtime %d, %s for %s%s%s", - fromstring, portnum, status, authtime, - cname ? cname : "", - sname ? sname : "", - errcode ? ", " : "", - errcode ? error_message(errcode) : ""); + if (status) { + if (!errcode) + rep_etypes2str(rep_etypestr, sizeof(rep_etypestr), &reply); + krb5_klog_syslog(LOG_INFO, + "TGS_REQ (%s) %s(%d): %s: authtime %d, " + "%s%s %s for %s%s%s", + ktypestr, + fromstring, portnum, status, authtime, + !errcode ? rep_etypestr : "", + !errcode ? "," : "", + cname ? cname : "", + sname ? sname : "", + errcode ? ", " : "", + errcode ? error_message(errcode) : ""); + } + if (errcode) { errcode -= ERROR_TABLE_BASE_krb5; if (errcode < 0 || errcode > 128) diff --git a/src/kdc/extern.h b/src/kdc/extern.h index 01a267d..556cc57 100644 --- a/src/kdc/extern.h +++ b/src/kdc/extern.h @@ -1,7 +1,7 @@ /* * kdc/extern.h * - * Copyright 1990 by the Massachusetts Institute of Technology. + * Copyright 1990,2001 by the Massachusetts Institute of Technology. * * Export of this software from the United States of America may * require a specific license from the United States Government. @@ -67,12 +67,15 @@ typedef struct __kdc_realm_data { krb5_deltat realm_maxrlife; /* Maximum renewable life for realm */ void *realm_kstypes; /* Key/Salts supported for realm */ krb5_int32 realm_nkstypes; /* Number of key/salts */ + krb5_boolean realm_reject_bad_transit; /* Accept unverifiable transited_realm ? */ } kdc_realm_t; extern kdc_realm_t **kdc_realmlist; extern int kdc_numrealms; extern kdc_realm_t *kdc_active_realm; +kdc_realm_t *find_realm_data (char *, krb5_ui_4); + /* * Replace previously used global variables with the active (e.g. request's) * realm data. This allows us to support multiple realms with minimal logic @@ -89,6 +92,7 @@ extern kdc_realm_t *kdc_active_realm; #define tgs_server kdc_active_realm->realm_tgsprinc #define dbm_db_name kdc_active_realm->realm_dbname #define primary_port kdc_active_realm->realm_pport +#define reject_bad_transit kdc_active_realm->realm_reject_bad_transit /* various externs for KDC */ extern krb5_data empty_string; /* an empty string */ diff --git a/src/kdc/kdc_preauth.c b/src/kdc/kdc_preauth.c index 41152f2..829b842 100644 --- a/src/kdc/kdc_preauth.c +++ b/src/kdc/kdc_preauth.c @@ -533,7 +533,7 @@ get_etype_info(context, request, client, server, pa_data) while (1) { retval = krb5_dbe_search_enctype(context, client, &start, -1, -1, 0, &client_key); - if (retval == ENOENT) + if (retval == KRB5_KDB_NO_MATCHING_KEY) break; if (retval) goto cleanup; diff --git a/src/kdc/kdc_util.c b/src/kdc/kdc_util.c index f5a0016..fa5b7da 100644 --- a/src/kdc/kdc_util.c +++ b/src/kdc/kdc_util.c @@ -31,9 +31,11 @@ #include "kdc_util.h" #include "extern.h" #include +#include #include #include "adm.h" #include "adm_proto.h" +#include #ifdef USE_RCACHE static char *kdc_current_rcname = (char *) NULL; @@ -657,26 +659,30 @@ add_to_transited(tgt_trans, new_trans, tgs, client, server) clst = strlen(current) - 1; if (current[0] == ' ') { - strcpy(exp, current+1); + strncpy(exp, current+1, sizeof(exp) - 1); + exp[sizeof(exp) - 1] = '\0'; } else if ((current[0] == '/') && (prev[0] == '/')) { - strcpy(exp, prev); + strncpy(exp, prev, sizeof(exp) - 1); + exp[sizeof(exp) - 1] = '\0'; if (strlen(exp) + strlen(current) + 1 >= MAX_REALM_LN) { retval = KRB5KRB_AP_ERR_ILL_CR_TKT; goto fail; } - strcat(exp, current); + strncat(exp, current, sizeof(exp) - 1 - strlen(exp)); } else if (current[clst] == '.') { - strcpy(exp, current); - if (strlen(exp) + strlen(current) + 1 >= MAX_REALM_LN) { + strncpy(exp, current, sizeof(exp) - 1); + exp[sizeof(exp) - 1] = '\0'; + if (strlen(exp) + strlen(prev) + 1 >= MAX_REALM_LN) { retval = KRB5KRB_AP_ERR_ILL_CR_TKT; goto fail; } - strcat(exp, prev); + strncat(exp, prev, sizeof(exp) - 1 - strlen(exp)); } else { - strcpy(exp, current); + strncpy(exp, current, sizeof(exp) - 1); + exp[sizeof(exp) - 1] = '\0'; } /* read field into next */ @@ -718,11 +724,12 @@ add_to_transited(tgt_trans, new_trans, tgs, client, server) if ((next[nlst] != '.') && (next[0] != '/') && (pl = subrealm(exp, realm))) { added = TRUE; + current[sizeof(current) - 1] = '\0'; if (strlen(current) + (pl>0?pl:-pl) + 2 >= MAX_REALM_LN) { retval = KRB5KRB_AP_ERR_ILL_CR_TKT; goto fail; } - strcat(current, ","); + strncat(current, ",", sizeof(current) - 1 - strlen(current)); if (pl > 0) { strncat(current, realm, pl); } @@ -762,19 +769,22 @@ add_to_transited(tgt_trans, new_trans, tgs, client, server) retval = KRB5KRB_AP_ERR_ILL_CR_TKT; goto fail; } - strcat(current, " "); + strncat(current, " ", sizeof(current) - 1 - strlen(current)); + current[sizeof(current) - 1] = '\0'; } if (strlen(current) + strlen(realm) + 1 >= MAX_REALM_LN) { retval = KRB5KRB_AP_ERR_ILL_CR_TKT; goto fail; } - strcat(current, realm); + strncat(current, realm, sizeof(current) - 1 - strlen(current)); + current[sizeof(current) - 1] = '\0'; } if (strlen(current) + (pl>0?pl:-pl) + 2 >= MAX_REALM_LN) { retval = KRB5KRB_AP_ERR_ILL_CR_TKT; goto fail; } - strcat(current,","); + strncat(current,",", sizeof(current) - 1 - strlen(current)); + current[sizeof(current) - 1] = '\0'; if (pl > 0) { strncat(current, exp, pl); } @@ -796,10 +806,12 @@ add_to_transited(tgt_trans, new_trans, tgs, client, server) goto fail; } strcat(trans, current); - new_trans->length = strlen(trans) + 1; + new_trans->length = strlen(trans); - strcpy(prev, exp); - strcpy(current, next); + strncpy(prev, exp, sizeof(prev) - 1); + prev[sizeof(prev) - 1] = '\0'; + strncpy(current, next, sizeof(current) - 1); + current[sizeof(current) - 1] = '\0'; } if (!added) { @@ -822,7 +834,7 @@ add_to_transited(tgt_trans, new_trans, tgs, client, server) goto fail; } strcat(trans, realm); - new_trans->length = strlen(trans) + 1; + new_trans->length = strlen(trans); } retval = 0; @@ -1406,13 +1418,14 @@ dbentry_supports_enctype(context, client, enctype) { /* * If it's DES_CBC_MD5, there's a bit in the attribute mask which - * checks to see if we support it. + * checks to see if we support it. For now, treat it as always + * clear. * * In theory everything's supposed to support DES_CBC_MD5, but * that's not the reality.... */ if (enctype == ENCTYPE_DES_CBC_MD5) - return isflagset(client->attributes, KRB5_KDB_SUPPORT_DESMD5); + return 0; /* * XXX we assume everything can understand DES_CBC_CRC @@ -1446,6 +1459,9 @@ select_session_keytype(context, server, nktypes, ktype) if (!valid_enctype(ktype[i])) continue; + if (!krb5_is_permitted_enctype(context, ktype[i])) + continue; + if (dbentry_supports_enctype(context, server, ktype[i])) return ktype[i]; } @@ -1527,3 +1543,82 @@ void limit_string(char *name) name[i] = '\0'; return; } + +/* + * L10_2 = log10(2**x), rounded up; log10(2) ~= 0.301. + */ +#define L10_2(x) ((int)(((x * 301) + 999) / 1000)) + +/* + * Max length of sprintf("%ld") for an int of type T; includes leading + * minus sign and terminating NUL. + */ +#define D_LEN(t) (L10_2(sizeof(t) * CHAR_BIT) + 2) + +void +ktypes2str(char *s, size_t len, int nktypes, krb5_enctype *ktype) +{ + int i; + char stmp[D_LEN(krb5_enctype) + 1]; + char *p; + + if (nktypes < 0 + || len < (sizeof(" etypes {...}") + D_LEN(int))) { + *s = '\0'; + return; + } + + sprintf(s, "%d etypes {", nktypes); + for (i = 0; i < nktypes; i++) { + sprintf(stmp, "%s%ld", i ? " " : "", (long)ktype[i]); + if (strlen(s) + strlen(stmp) + sizeof("}") > len) + break; + strcat(s, stmp); + } + if (i < nktypes) { + /* + * We broke out of the loop. Try to truncate the list. + */ + p = s + strlen(s); + while (p - s + sizeof("...}") > len) { + while (p > s && *p != ' ' && *p != '{') + *p-- = '\0'; + if (p > s && *p == ' ') { + *p-- = '\0'; + continue; + } + } + strcat(s, "..."); + } + strcat(s, "}"); + return; +} + +void +rep_etypes2str(char *s, size_t len, krb5_kdc_rep *rep) +{ + char stmp[sizeof("ses=") + D_LEN(krb5_enctype)]; + + if (len < (3 * D_LEN(krb5_enctype) + + sizeof("etypes {rep= tkt= ses=}"))) { + *s = '\0'; + return; + } + + sprintf(s, "etypes {rep=%ld", (long)rep->enc_part.enctype); + + if (rep->ticket != NULL) { + sprintf(stmp, " tkt=%ld", (long)rep->ticket->enc_part.enctype); + strcat(s, stmp); + } + + if (rep->ticket != NULL + && rep->ticket->enc_part2 != NULL + && rep->ticket->enc_part2->session != NULL) { + sprintf(stmp, " ses=%ld", + (long)rep->ticket->enc_part2->session->enctype); + strcat(s, stmp); + } + strcat(s, "}"); + return; +} diff --git a/src/kdc/kdc_util.h b/src/kdc/kdc_util.h index ce2377e..6cc48b0 100644 --- a/src/kdc/kdc_util.h +++ b/src/kdc/kdc_util.h @@ -98,6 +98,12 @@ get_salt_from_key PROTOTYPE((krb5_context, krb5_principal, void limit_string PROTOTYPE((char *name)); +void +ktypes2str(char *s, size_t len, int nktypes, krb5_enctype *ktype); + +void +rep_etypes2str(char *s, size_t len, krb5_kdc_rep *rep); + /* do_as_req.c */ krb5_error_code process_as_req PROTOTYPE((krb5_kdc_req *, const krb5_fulladdr *, diff --git a/src/kdc/kerberos_v4.c b/src/kdc/kerberos_v4.c index f05452e..d9fe6ab 100644 --- a/src/kdc/kerberos_v4.c +++ b/src/kdc/kerberos_v4.c @@ -155,7 +155,7 @@ static int set_tgtkey PROTOTYPE((char *, krb5_kvno)); #define V4_KDB_REQUIRES_PREAUTH 0x1 #define V4_KDB_DISALLOW_ALL_TIX 0x2 #define V4_KDB_REQUIRES_PWCHANGE 0x4 - +#define V4_KDB_DISALLOW_SVR 0x8 /* v4 compatibitly mode switch */ #define KDC_V4_NONE 0 /* Don't even respond to packets */ @@ -233,11 +233,11 @@ krb5_data **resp; return(retval); if (!*local_realm) { /* local-realm name already set up */ - /* XXX assumes realm is null-terminated! */ lrealm = master_princ->realm.data; - if (strlen(lrealm) < sizeof(local_realm)) - strcpy(local_realm, lrealm); - else + if (master_princ->realm.length < sizeof(local_realm)) { + memcpy(local_realm, lrealm, master_princ->realm.length); + local_realm[master_princ->realm.length] = '\0'; + } else retval = KRB5_CONFIG_NOTENUFSPACE; } /* convert client_fulladdr to client_sockaddr: @@ -256,6 +256,7 @@ krb5_data **resp; return KRB5KRB_ERR_FIELD_TOOLONG; } v4_pkt.length = pkt->length; + v4_pkt.mbz = 0; memcpy( v4_pkt.dat, pkt->data, pkt->length); kerberos_v4( &client_sockaddr, &v4_pkt); @@ -539,6 +540,9 @@ kerb_get_principal(name, inst, principal, maxn, more, k5key, kvno, issrv) if (isflagset(entries.attributes, KRB5_KDB_DISALLOW_ALL_TIX)) { principal->attributes |= V4_KDB_DISALLOW_ALL_TIX; } + if (issrv && isflagset(entries.attributes, KRB5_KDB_DISALLOW_SVR)) { + principal->attributes |= V4_KDB_DISALLOW_SVR; + } if (isflagset(entries.attributes, KRB5_KDB_REQUIRES_PWCHANGE)) { principal->attributes |= V4_KDB_REQUIRES_PWCHANGE; } @@ -622,6 +626,9 @@ kerberos_v4(client, pkt) req_act_vno = req_version; + /* set these to point to something safe */ + req_name_ptr = req_inst_ptr = req_realm_ptr = ""; + /* check if disabled, but we tell client */ if (kdc_v4 == KDC_V4_DISABLE) { lt = klog(L_KRB_PERR, @@ -700,7 +707,7 @@ kerberos_v4(client, pkt) if ((i = check_princ(req_name_ptr, req_inst_ptr, 0, &a_name_data, &k5key, 0))) { - kerb_err_reply(client, pkt, i, lt); + kerb_err_reply(client, pkt, i, "check_princ failed"); a_name_data.key_low = a_name_data.key_high = 0; krb5_free_keyblock_contents(kdc_context, &k5key); return; @@ -715,7 +722,7 @@ kerberos_v4(client, pkt) /* this does all the checking */ if ((i = check_princ(service, instance, lifetime, &s_name_data, &k5key, 1))) { - kerb_err_reply(client, pkt, i, lt); + kerb_err_reply(client, pkt, i, "check_princ failed"); a_name_data.key_high = a_name_data.key_low = 0; s_name_data.key_high = s_name_data.key_low = 0; krb5_free_keyblock_contents(kdc_context, &k5key); @@ -806,19 +813,40 @@ kerberos_v4(client, pkt) tk->length = 0; k_flags = 0; /* various kerberos flags */ + auth->mbz = 0; /* pkt->mbz already zeroed */ auth->length = 4 + strlen((char *)pkt->dat + 3); + if (auth->length + 1 > MAX_KTXT_LEN) { + lt = klog(L_KRB_PERR, + "APPL request with realm length too long from %s", + inet_ntoa(client_host)); + kerb_err_reply(client, pkt, RD_AP_INCON, + "realm length too long"); + return; + } + auth->length += (int) *(pkt->dat + auth->length) + (int) *(pkt->dat + auth->length + 1) + 2; + if (auth->length > MAX_KTXT_LEN) { + lt = klog(L_KRB_PERR, + "APPL request with funky tkt or req_id length from %s", + inet_ntoa(client_host)); + kerb_err_reply(client, pkt, RD_AP_INCON, + "funky tkt or req_id length"); + return; + } memcpy(auth->dat, pkt->dat, auth->length); strncpy(tktrlm, (char *)auth->dat + 3, REALM_SZ); + tktrlm[REALM_SZ-1] = '\0'; kvno = (krb5_kvno)auth->dat[2]; if (set_tgtkey(tktrlm, kvno)) { lt = klog(L_ERR_UNK, "FAILED set_tgtkey realm %s, kvno %d. Host: %s ", tktrlm, kvno, inet_ntoa(client_host)); - kerb_err_reply(client, pkt, kerno, lt); + /* no better error code */ + kerb_err_reply(client, pkt, + KERB_ERR_PRINCIPAL_UNKNOWN, lt); return; } kerno = krb_rd_req(auth, "krbtgt", tktrlm, client_host.s_addr, @@ -863,7 +891,7 @@ kerberos_v4(client, pkt) kerno = check_princ(service, instance, req_life, &s_name_data, &k5key, 1); if (kerno) { - kerb_err_reply(client, pkt, kerno, lt); + kerb_err_reply(client, pkt, kerno, "check_princ failed"); s_name_data.key_high = s_name_data.key_low = 0; krb5_free_keyblock_contents(kdc_context, &k5key); return; @@ -968,7 +996,7 @@ kerb_err_reply(client, pkt, err, string) static char e_msg[128]; strcpy(e_msg, "\nKerberos error -- "); - strcat(e_msg, string); + strncat(e_msg, string, sizeof(e_msg) - 1 - 19); cr_err_reply(e_pkt, req_name_ptr, req_inst_ptr, req_realm_ptr, req_time_ws, err, e_msg); krb4_sendto(f, (char *) e_pkt->dat, e_pkt->length, 0, @@ -1066,6 +1094,13 @@ check_princ(p_name, instance, lifetime, p, k5key, issrv) return KERB_ERR_NAME_EXP; } + if (isflagset(p->attributes, V4_KDB_DISALLOW_SVR)) { + lt = klog(L_ERR_SEXP, "V5 DISALLOW_SVR set: " + "\"%s\" \"%s\"", p_name, instance); + /* Not sure of a better error to return */ + return KERB_ERR_NAME_EXP; + } + /* * Does the principal require preauthentication? */ @@ -1125,9 +1160,23 @@ set_tgtkey(r, kvno) if (n == 0) return (KFAILURE); + if (isflagset(p->attributes, V4_KDB_DISALLOW_ALL_TIX)) { + lt = klog(L_ERR_SEXP, + "V5 DISALLOW_ALL_TIX set: \"krbtgt\" \"%s\"", r); + krb5_free_keyblock_contents(kdc_context, &k5key); + return KFAILURE; + } + + if (isflagset(p->attributes, V4_KDB_DISALLOW_SVR)) { + lt = klog(L_ERR_SEXP, "V5 DISALLOW_SVR set: \"krbtgt\" \"%s\"", r); + krb5_free_keyblock_contents(kdc_context, &k5key); + return KFAILURE; + } + if (!K4KDC_ENCTYPE_OK(k5key.enctype)) { krb_set_key_krb5(kdc_context, &k5key); - strcpy(lastrealm, r); + strncpy(lastrealm, r, sizeof(lastrealm) - 1); + lastrealm[sizeof(lastrealm) - 1] = '\0'; last_kvno = kvno; } else { /* unseal tgt key from master key */ @@ -1136,7 +1185,8 @@ set_tgtkey(r, kvno) kdb_encrypt_key(key, key, master_key, master_key_schedule, DECRYPT); krb_set_key((char *) key, 0); - strcpy(lastrealm, r); + strncpy(lastrealm, r, sizeof(lastrealm) - 1); + lastrealm[sizeof(lastrealm) - 1] = '\0'; last_kvno = kvno; } krb5_free_keyblock_contents(kdc_context, &k5key); diff --git a/src/kdc/main.c b/src/kdc/main.c index 473b902..1cf5356 100644 --- a/src/kdc/main.c +++ b/src/kdc/main.c @@ -1,7 +1,7 @@ /* * kdc/main.c * - * Copyright 1990 by the Massachusetts Institute of Technology. + * Copyright 1990,2001 by the Massachusetts Institute of Technology. * * Export of this software from the United States of America may * require a specific license from the United States Government. @@ -44,8 +44,6 @@ #include #endif -kdc_realm_t *find_realm_data PROTOTYPE((char *, krb5_ui_4)); - void usage PROTOTYPE((char *)); krb5_sigtype request_exit PROTOTYPE((int)); @@ -230,6 +228,12 @@ init_realm(progname, rdp, realm, def_dbname, def_mpname, else rdp->realm_mkey.enctype = manual ? def_enctype : ENCTYPE_UNKNOWN; + /* Handle reject-bad-transit flag */ + if (rparams && rparams->realm_reject_bad_transit_valid) + rdp->realm_reject_bad_transit = rparams->realm_reject_bad_transit; + else + rdp->realm_reject_bad_transit = 1; + /* Handle ticket maximum life */ rdp->realm_maxlife = (rparams && rparams->realm_max_life_valid) ? rparams->realm_max_life : KRB5_KDB_MAX_LIFE; diff --git a/src/kdc/network.c b/src/kdc/network.c index 502682a..131b1df 100644 --- a/src/kdc/network.c +++ b/src/kdc/network.c @@ -1,7 +1,7 @@ /* * kdc/network.c * - * Copyright 1990 by the Massachusetts Institute of Technology. + * Copyright 1990,2000 by the Massachusetts Institute of Technology. * * Export of this software from the United States of America may * require a specific license from the United States Government. @@ -35,6 +35,7 @@ #include #include +#include #include #ifdef HAVE_NETINET_IN_H #include @@ -50,7 +51,9 @@ #endif #include +#ifndef ARPHRD_ETHER /* protect on OpenBSD */ #include +#endif extern int errno; @@ -120,13 +123,17 @@ foreach_localaddr (data, pass1fn, betweenfn, pass2fn) int (*betweenfn) (void *); int (*pass2fn) (void *, struct sockaddr *); { - struct ifreq *ifr, ifreq; + struct ifreq *ifr, ifreq, *ifr2; struct ifconf ifc; - int s, code, n, i; + int s, code, n, i, j; int est_if_count = 8, est_ifreq_size; char *buf = 0; size_t current_buf_size = 0; - + int fail = 0; +#ifdef SIOCGSIZIFCONF + int ifconfsize = -1; +#endif + s = socket (USE_AF, USE_TYPE, USE_PROTO); if (s < 0) return SOCKET_ERRNO; @@ -134,8 +141,17 @@ foreach_localaddr (data, pass1fn, betweenfn, pass2fn) /* At least on NetBSD, an ifreq can hold an IPv4 address, but isn't big enough for an IPv6 or ethernet address. So add a little more space. */ - est_ifreq_size = sizeof (struct ifreq) + 8; - current_buf_size = est_ifreq_size * est_if_count; + est_ifreq_size = sizeof (struct ifreq) + 16; +#ifdef SIOCGSIZIFCONF + code = ioctl (s, SIOCGSIZIFCONF, &ifconfsize); + if (!code) { + current_buf_size = ifconfsize; + est_if_count = ifconfsize / est_ifreq_size; + } +#endif + if (current_buf_size == 0) { + current_buf_size = est_ifreq_size * est_if_count; + } buf = malloc (current_buf_size); ask_again: @@ -149,12 +165,35 @@ foreach_localaddr (data, pass1fn, betweenfn, pass2fn) closesocket (s); return retval; } - /* Test that the buffer was big enough that another ifreq could've + /* BSD 4.4 and similar systems truncate the address list if the + supplied buffer isn't big enough. + + Test that the buffer was big enough that another ifreq could've fit easily, if the OS wanted to provide one. That seems to be the only indication we get, complicated by the fact that the associated address may make the required storage a little bigger than the size of an ifreq. */ - if (current_buf_size - ifc.ifc_len < sizeof (struct ifreq) + 40) { +#define SLOP (sizeof (struct ifreq) + 128) + if ((current_buf_size - ifc.ifc_len < sizeof (struct ifreq) + SLOP + /* On AIX 4.3.3, ifc.ifc_len may be set to a larger size than + provided under some circumstances. On my test system, a + supplied value of 32..112 gets me 112, but with no data + filled in even at 112. But larger input ifc_len values get + me larger output values, so it's not necessarily the full + desired output buffer size. And as near as I can tell, the + ifc_len output has little to do with the offset of the last + byte in the buffer actually modified, except that both + input and output ifc_len values are higher (i.e., no buffer + overrun takes place in my testing). */ + || current_buf_size < ifc.ifc_len) + /* But let's let SIOCGSIZIFCONF dominate, unless we discover + it's broken somewhere. */ +#ifdef SIOCGSIZIFCONF + && ifconfsize <= 0 +#endif + /* And we need *some* sort of bounds. */ + && current_buf_size <= 100000 + ) { int new_size; char *newbuf; @@ -172,7 +211,15 @@ foreach_localaddr (data, pass1fn, betweenfn, pass2fn) } n = ifc.ifc_len; - + if (n > current_buf_size) + n = current_buf_size; + + /* Note: Apparently some systems put the size (used or wanted?) + into the start of the buffer, just none that I'm actually + using. Fix this when there's such a test system available. + The Samba mailing list archives mention that NTP looks for the + size on these systems: *-fujitsu-uxp* *-ncr-sysv4* + *-univel-sysv*. [raeburn:20010201T2226-05] */ for (i = 0; i < n; i+= ifreq_size(*ifr) ) { ifr = (struct ifreq *)((caddr_t) ifc.ifc_buf+i); @@ -184,6 +231,7 @@ foreach_localaddr (data, pass1fn, betweenfn, pass2fn) continue; } + #ifdef IFF_LOOPBACK /* None of the current callers want loopback addresses. */ if (ifreq.ifr_flags & IFF_LOOPBACK) @@ -193,13 +241,32 @@ foreach_localaddr (data, pass1fn, betweenfn, pass2fn) if (!(ifreq.ifr_flags & IFF_UP)) goto skip; + /* Make sure we didn't process this address already. */ + for (j = 0; j < i; j += ifreq_size(*ifr2)) { + ifr2 = (struct ifreq *)((caddr_t) ifc.ifc_buf+j); + if (ifr2->ifr_name[0] == 0) + continue; + if (ifr2->ifr_addr.sa_family == ifr->ifr_addr.sa_family + && ifreq_size (*ifr) == ifreq_size (*ifr2) + /* Compare address info. If this isn't good enough -- + i.e., if random padding bytes turn out to differ + when the addresses are the same -- then we'll have + to do it on a per address family basis. */ + && !memcmp (&ifr2->ifr_addr.sa_data, &ifr->ifr_addr.sa_data, + (ifreq_size (*ifr) + - offsetof (struct ifreq, ifr_addr.sa_data)))) + goto skip; + } + if ((*pass1fn) (data, &ifr->ifr_addr)) { - abort (); + fail = 1; + goto punt; } } if (betweenfn && (*betweenfn)(data)) { - abort (); + fail = 1; + goto punt; } if (pass2fn) @@ -211,13 +278,15 @@ foreach_localaddr (data, pass1fn, betweenfn, pass2fn) continue; if ((*pass2fn) (data, &ifr->ifr_addr)) { - abort (); + fail = 1; + goto punt; } } + punt: closesocket(s); free (buf); - return 0; + return fail; } struct socksetup { diff --git a/src/kdc/rtest.c b/src/kdc/rtest.c index e5f1d89..e7f6fc2 100644 --- a/src/kdc/rtest.c +++ b/src/kdc/rtest.c @@ -112,3 +112,4 @@ main(argc,argv) } void krb5_klog_syslog() {} +kdc_realm_t *find_realm_data (char *rname, krb5_ui_4 rsize) { return 0; } diff --git a/src/krb5-config.in b/src/krb5-config.in new file mode 100644 index 0000000..3738c3e --- /dev/null +++ b/src/krb5-config.in @@ -0,0 +1,213 @@ +#!/bin/sh + +# Copyright 2001 by the Massachusetts Institute of Technology. +# All Rights Reserved. +# +# Export of this software from the United States of America may +# 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. Furthermore if you modify this software you must label +# your software as modified software and not distribute it in such a +# fashion that it might be confused with the original M.I.T. software. +# 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. +# +# + +# Configurable parameters set by autoconf +version_string="Kerberos 5 release @KRB5_VERSION@" + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +includedir=@includedir@ +libdir=@libdir@ +CC_LINK='@CC_LINK@' +KRB4_LIB=@KRB4_LIB@ +DES425_LIB=@DES425_LIB@ + + +LIBS='@LIBS@' +GEN_LIB=@GEN_LIB@ + +# Defaults for program +library=krb5 + +# Some constants +vendor_string="Massachusetts Institute of Technology" + +# Process arguments +# Yes, we are sloppy, library specifications can come before options +while test $# != 0; do + case $1 in + --all) + do_all=1 + ;; + --cflags) + do_cflags=1 + ;; + --deps) + do_deps=1 + ;; + --exec-prefix) + do_exec_prefix=1 + ;; + --help) + do_help=1 + ;; + --libs) + do_libs=1 + ;; + --prefix) + do_prefix=1 + ;; + --vendor) + do_vendor=1 + ;; + --version) + do_version=1 + ;; + krb5) + library=krb5 + ;; + gssapi) + library=gssapi + ;; + krb4) + library=krb4 + ;; + kadm-client) + library=kadm_client + ;; + kadm-server) + library=kadm_server + ;; + kdb) + library=kdb + ;; + *) + echo "$0: Unknown option \`$1' -- use \`--help' for usage" + exit 1 + esac + shift +done + +# If required options - provide help +if test -z "$do_all" -a -z "$do_version" -a -z "$do_vendor" -a -z "$do_prefix" -a -z "$do_vendor" -a -z "$do_exec_prefix" -a -z "$do_cflags" -a -z "$do_libs"; then + do_help=1 +fi + + +if test -n "$do_help"; then + echo "Usage: $0 [OPTIONS] [LIBRARIES]" + echo "Options:" + echo " [--help] Help" + echo " [--all] Display version, vendor, and various values" + echo " [--version] Version information" + echo " [--vendor] Vendor information" + echo " [--prefix] Kerberos installed prefix" + echo " [--exec-prefix] Kerberos installed exec_prefix" + echo " [--cflags] Compile time CFLAGS" + echo " [--libs] List libraries required to link [LIBRARIES]" + echo "Libraries:" + echo " krb5 Kerberos 5 application" + echo " gssapi GSSAPI application with Kerberos 5 bindings" + echo " krb4 Kerberos 4 application" + echo " kadm-client Kadmin client" + echo " kadm-server Kadmin server" + echo " kdb Application that accesses the kerberos database" + exit 0 +fi + +if test -n "$do_all"; then + all_exit= + do_version=1 + do_prefix=1 + do_exec_prefix=1 + do_vendor=1 + title_version="Version: " + title_prefix="Prefix: " + title_exec_prefix="Exec_prefix: " + title_vendor="Vendor: " +else + all_exit="exit 0" +fi + +if test -n "$do_version"; then + echo "$title_version$version_string" + $all_exit +fi + +if test -n "$do_vendor"; then + echo "$title_vendor$vendor_string" + $all_exit +fi + +if test -n "$do_prefix"; then + echo "$title_prefix$prefix" + $all_exit +fi + +if test -n "$do_exec_prefix"; then + echo "$title_exec_prefix$exec_prefix" + $all_exit +fi + +if test -n "$do_cflags"; then + echo "-I${includedir}" +fi + + +if test -n "$do_libs"; then + # Ugly gross hack for our build tree + lib_flags=`echo $CC_LINK | sed -e 's/\$(CC)//' \ + -e 's#\$(PROG_RPATH)#'$libdir'#' \ + -e 's#\$(PROG_LIBPATH)#-L'$libdir'#'` + + if test $library = 'kdb'; then + lib_flags="$lib_flags -lkdb5 -ldb" + library=krb5 + fi + + if test $library = 'kadm_server'; then + lib_flags="$lib_flags -lkadm5srv -lkdb5 -ldb" + library=kadm_common + fi + + if test $library = 'kadm_client'; then + lib_flags="$lib_flags -lkadm5clnt" + library=kadm_common + fi + + if test $library = 'kadm_common'; then + lib_flags="$lib_flags -lgssrpc -ldyn" + library=gssapi + fi + + if test $library = 'gssapi'; then + lib_flags="$lib_flags -lgssapi_krb5" + library=krb5 + fi + + if test $library = 'krb4'; then + lib_flags="$lib_flags $KRB4_LIB $DES425_LIB" + library=krb5 + fi + + if test $library = 'krb5'; then + lib_flags="$lib_flags -lkrb5 -lk5crypto -lcom_err $GEN_LIB" + fi + + echo $lib_flags +fi + +exit 0 diff --git a/src/krb524/ChangeLog b/src/krb524/ChangeLog index e3c656b..243e3cd 100644 --- a/src/krb524/ChangeLog +++ b/src/krb524/ChangeLog @@ -1,3 +1,78 @@ +2002-08-29 Sam Hartman + + * README: Document new afs_krb5 configuration information + + * krb524d.c (afs_return_v4): New function to determine if we have + been configured to return v4 tickets for afs or use the afs + krb5-encpart proposal + (do_connection): Call afs_return_v4 and use its result + + * RELEASE_NOTES: Delete OV release notes now with 100% incorrect + content + + * krb524d.c (do_connection): Add support for AFS + krb5-encpart-only per discussion with jhutz and lha + (handle_classic_v4): Split out code for handling v4 tickets since + it needs to be called multiple times + + [pullups from trunk] + +2002-08-15 Tom Yu + + * krb524d.c (kdc_get_server_key): Check for DISALLOW_ALL_TIX and + DISALLOW_SVR when looking up server key. + [pullup from trunk] + +2002-05-22 Alexandra Ellwood + * conv_creds.c, sendmsg.c: Added return values to krb524_sendto_kdc + to return an IPv4 address for the KDC we talked to (if such an address + exists). On Mac OS X we store this address in the Credentials Cache + so we can inform the user when the tickets become invalid. + +2002-05-22 Alexandra Ellwood + * krb524.h: Added #include of krb.h for Mac OS X so that CREDENTIALS + is defined (and krb524.h compiles standalone. + +2002-05-16 Alexandra Ellwood + conv_creds.c: call krb_time_to_life to get v4 lifetime on Mac OS + X. This enables v4 long lifetime support. + +2002-05-05 Alexandra Ellwood + * krb524.h: Mac OS X needs krb524.h to include krb5.h because it + uses KRB5_PROTOTYPE, krb5_context, etc. On Mac OS X this is a + public header to get krb524_convert_creds_kdc. Everything else + is private. + +2002-04-03 Alexandra Ellwood + * krb524.h: Updated C++ protection to not interfere with emacs + auto indentation and added KRB524_PRIVATE macro for Mac OS X + to control visibility of function prototypes + +2002-03-28 Alexandra Ellwood + * krb524.h: Added C++ protection and Mac pragmas + +2002-03-1 Alexandra Ellwood + * krb524.h, cnv_tkt_skey.c, conv_creds.c, conv_princ.c, encode.c, + misc.c, sendmsg.c: Updated header paths on Mac OS X so that we + correctly include the autogenerated krb524.h + * conv_creds.c, cnv_tkt_skey.c: added cast to remove warning. + +2002-02-28 Alexandra Ellwood + * krb524.h: Updated to new Mac OS header layout. + * sendmsg.c: k5-int.h should be included as a local header + +2001-12-07 Ken Raeburn + + * krb524d.c (cleanup_and_exit): Don't close keytab if it hasn't + been opened yet. + (lookup_service_key): Copy key block and free up keytab entry + data. + +2001-02-05 Tom Yu + + * cnv_tkt_skey.c (krb524_convert_tkt_skey): Avoid double-free; + caller should free v5tkt. [pullup from trunk] + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/krb524/README b/src/krb524/README index 1531de0..dd7ca9c 100644 --- a/src/krb524/README +++ b/src/krb524/README @@ -48,6 +48,16 @@ information in the V5 credential and {C,S}_4. Steps (2) through (4) are encapsulated in a single function call in the krb524 library. +An alternate conversion is provided for AFS servers that support the +encrypted part of a krb5 ticket as an AFS token. If the krb524d is +converting a principal whose first component is afs and if the +encrypted part of the ticket fits in 344 bytes, then it will default +to simply returning the encrypted part of the ticket as a token. If +it turns out that the AFS server does not support the ticket, then +users will get an unknown key version error and the krb524d must be +configured to use v4 tickets for this AFS service. + + Obviously, not all V5 credentials can be completely converted to V4 credentials, since the former is a superset of the latter. The precise semantics of the conversion function are still undecided. @@ -82,6 +92,29 @@ default principal's realm if not specified. The -n argument causes the new ticket to be added to the existing ticket file; otherwise, the ticket file is initialized. +Configuring krb524d AFS Conversion +====================================================================== + +The krb524d looks in the appdefaults section of krb5.conf for an +application called afs_krb5 to determine whether afs principals +support encrypted ticket parts as tokens. The following configuration +fragment says that afs/sipb.mit.edu@ATHENA.MIT.EDU supports the new +token format but afs@ATHENA.MIT.EDU and +afs/athena.mit.edu@ATHENA.MIT.EDU do not. Note that the default is to +assume afs servers support the new format. + +[appdefaults] +afs_krb5 = { + ATHENA.MIT.EDU = { + # This stanza describes principals in the + #ATHENA.MIT.EDU realm + afs = false + afs/athena.mit.edu = false + afs/sipb.mit.edu = true + } +} + + Using libkrb524.a ====================================================================== diff --git a/src/krb524/RELEASE_NOTES b/src/krb524/RELEASE_NOTES deleted file mode 100644 index 8d1ea9f..0000000 --- a/src/krb524/RELEASE_NOTES +++ /dev/null @@ -1,16 +0,0 @@ - -Kerberos V5 to Kerberos V4 Credentials Converting Service, ALPHA RELEASE -======================================================================== - -This is the ALPHA RELEASE of krb524. Treat it accordingly. - -Soon, krb524 will be integrated into the standard MIT Kerberos 5 -distribution. krb524's existence as a distinct distribution is -temporary. - -If you have any questions, contact - -Barry Jaspan, bjaspan@cam.ov.com -OpenVision Technologies, Inc. -(617) 374-2225 - diff --git a/src/krb524/cnv_tkt_skey.c b/src/krb524/cnv_tkt_skey.c index fc25246..79c467b 100644 --- a/src/krb524/cnv_tkt_skey.c +++ b/src/krb524/cnv_tkt_skey.c @@ -25,8 +25,14 @@ #include #include #include +#if TARGET_OS_MAC +#include +#include +#include "cr_tkt.h" +#else #include #include "krb524.h" +#endif /* rather than copying the cmu code, these values are derived from a calculation based on the table and comments found there. @@ -72,7 +78,6 @@ int krb524_convert_tkt_skey(context, v5tkt, v4tkt, v5_skey, v4_skey, v5tkt->enc_part2 = NULL; if ((ret = krb5_decrypt_tkt_part(context, v5_skey, v5tkt))) { - krb5_free_ticket(context, v5tkt); return ret; } v5etkt = v5tkt->enc_part2; @@ -91,7 +96,7 @@ int krb524_convert_tkt_skey(context, v5tkt, v4tkt, v5_skey, v4_skey, fprintf(stderr, "v5 session keyblock type %d length %d != C_Block size %d\n", v5etkt->session->enctype, v5etkt->session->length, - sizeof(C_Block)); + (int) sizeof(C_Block)); krb5_free_enc_tkt_part(context, v5etkt); v5tkt->enc_part2 = NULL; return KRB524_BADKEY; diff --git a/src/krb524/conv_creds.c b/src/krb524/conv_creds.c index ae31f9c..0ad9f49 100644 --- a/src/krb524/conv_creds.c +++ b/src/krb524/conv_creds.c @@ -25,9 +25,13 @@ #include #include #include +#if TARGET_OS_MAC +#include +#include +#else #include - #include "krb524.h" +#endif krb5_error_code krb524_convert_creds_plain KRB5_PROTOTYPE((krb5_context context, krb5_creds *v5creds, @@ -35,7 +39,8 @@ KRB5_PROTOTYPE((krb5_context context, krb5_creds *v5creds, krb5_error_code krb524_sendto_kdc KRB5_PROTOTYPE((krb5_context context, const krb5_data *message, - krb5_data *realm, krb5_data *reply)); + krb5_data *realm, krb5_data *reply, + struct sockaddr *local_addr, int *addrlen)); krb5_error_code krb524_convert_creds_kdc(context, v5creds, v4creds) @@ -46,17 +51,30 @@ krb524_convert_creds_kdc(context, v5creds, v4creds) krb5_error_code ret; krb5_data reply; char *p; + struct sockaddr_in local_addr; /* Ask for an IPv4 address */ + int addrlen = sizeof (local_addr); ret = krb524_convert_creds_plain(context, v5creds, v4creds); if (ret) return ret; reply.data = NULL; + ret = krb524_sendto_kdc(context, &v5creds->ticket, - &v5creds->server->realm, &reply); + &v5creds->server->realm, &reply, + (struct sockaddr *)&local_addr, &addrlen); if (ret) return ret; +#if TARGET_OS_MAC + /* On the Mac, we need our local address used to talk to the KDC + because we use this to determine validity of v4 tickets. */ + if ((addrlen == sizeof (struct sockaddr_in)) + && (local_addr.sin_family == AF_INET)) { + v4creds->address = local_addr.sin_addr.s_addr; + } +#endif + p = reply.data; ret = ntohl(*((krb5_error_code *) p)); p += sizeof(krb5_error_code); @@ -139,7 +157,7 @@ krb524_convert_creds_plain(context, v5creds, v4creds) if (krb524_debug) fprintf(stderr, "v5 session keyblock length %d != C_Block size %d\n", v5creds->keyblock.length, - sizeof(C_Block)); + (int) sizeof(C_Block)); return KRB524_BADKEY; } else memcpy(v4creds->session, (char *) v5creds->keyblock.contents, @@ -147,10 +165,16 @@ krb524_convert_creds_plain(context, v5creds, v4creds) /* V4 has no concept of authtime or renew_till, so ignore them */ /* V4 lifetime is 1 byte, in 5 minute increments */ +#if TARGET_OS_MAC + /* krb4 long lifetime support --- how should this be done on Unix? */ + v4creds->lifetime = krb_time_to_life (v5creds->times.starttime, + v5creds->times.endtime); +#else lifetime = ((v5creds->times.endtime - v5creds->times.starttime) / 300); v4creds->lifetime = ((lifetime > 0xff) ? 0xff : lifetime); +#endif v4creds->issue_date = v5creds->times.starttime; #if 0 diff --git a/src/krb524/conv_princ.c b/src/krb524/conv_princ.c index f55f4a2..a918a8b 100644 --- a/src/krb524/conv_princ.c +++ b/src/krb524/conv_princ.c @@ -26,10 +26,13 @@ #include #include #include - +#if TARGET_OS_MAC +#include +#include +#else #include - #include "krb524.h" +#endif int krb524_convert_princs(context, client, server, pname, pinst, prealm, sname, sinst) diff --git a/src/krb524/encode.c b/src/krb524/encode.c index fc40b79..f7d84b6 100644 --- a/src/krb524/encode.c +++ b/src/krb524/encode.c @@ -29,8 +29,13 @@ #include #include +#if TARGET_OS_MAC +#include +#include +#else #include #include "krb524.h" +#endif /* * I'm sure that this is reinventing the wheel, but I don't know where diff --git a/src/krb524/krb524.h b/src/krb524/krb524.h index da9c008..211d921 100644 --- a/src/krb524/krb524.h +++ b/src/krb524/krb524.h @@ -26,8 +26,39 @@ #define KRB524_SERVICE "krb524" #define KRB524_PORT 4444 -#include "krb524_err.h" - +#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__)) + #include + #include + #include + #ifndef KRB524_PRIVATE /* Allow e.g. build system to override */ + #define KRB524_PRIVATE 0 + #endif +#else + #include "krb524_err.h" + #ifndef KRB524_PRIVATE + #define KRB524_PRIVATE 1 + #endif +#endif + +#if defined(__cplusplus) && !defined(KRB524INT_BEGIN_DECLS) +#define KRB524INT_BEGIN_DECLS extern "C" { +#define KRB524INT_END_DECLS } +#else +#define KRB524INT_BEGIN_DECLS +#define KRB524INT_END_DECLS +#endif + +#if TARGET_OS_MAC + #if defined(__MWERKS__) + #pragma import on + #pragma enumsalwaysint on + #endif + #pragma options align=mac68k +#endif + +KRB524INT_BEGIN_DECLS + +#if KRB524_PRIVATE extern int krb524_debug; int krb524_convert_tkt_skey @@ -47,11 +78,13 @@ int krb524_convert_princs int krb524_convert_creds_addr KRB5_PROTOTYPE((krb5_context context, krb5_creds *v5creds, CREDENTIALS *v4creds, struct sockaddr *saddr)); +#endif /* KRB524_PRIVATE */ int krb524_convert_creds_kdc KRB5_PROTOTYPE((krb5_context context, krb5_creds *v5creds, CREDENTIALS *v4creds)); +#if KRB524_PRIVATE /* conv_tkt.c */ int krb524_convert_tkt @@ -77,5 +110,16 @@ void krb524_init_ets int krb524_send_message KRB5_PROTOTYPE((const struct sockaddr * addr, const krb5_data * message, krb5_data * reply)); +#endif /* KRB524_PRIVATE */ + +#if TARGET_OS_MAC + #if defined(__MWERKS__) + #pragma enumsalwaysint reset + #pragma import reset + #endif + #pragma options align=reset +#endif + +KRB524INT_END_DECLS #endif /* __KRB524_H__ */ diff --git a/src/krb524/krb524d.c b/src/krb524/krb524d.c index cad0e31..c91df30 100644 --- a/src/krb524/krb524d.c +++ b/src/krb524/krb524d.c @@ -1,4 +1,25 @@ /* + * Copyright (C) 2002 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. * Copyright 1994 by OpenVision Technologies, Inc. * * Permission to use, copy, modify, distribute, and sell this software @@ -24,6 +45,7 @@ #include #include +#include #include #ifdef HAVE_SYS_SELECT_H #include @@ -54,6 +76,13 @@ krb5_keytab kt; void init_keytab(), init_master(), cleanup_and_exit(); krb5_error_code do_connection(), lookup_service_key(), kdc_get_server_key(); +static krb5_error_code +handle_classic_v4 (krb5_context context, krb5_ticket *v5tkt, + struct sockaddr_in *saddr, + krb5_data *tktdata, krb5_kvno *v4kvno); +static krb5_error_code +afs_return_v4(krb5_context, const krb5_principal , int *use_v5); + void usage(context) krb5_context context; { @@ -201,7 +230,7 @@ void cleanup_and_exit(ret, context) if (use_master) { (void) kadm5_destroy(handle); } - if (use_keytab) krb5_kt_close(context, kt); + if (use_keytab && kt) krb5_kt_close(context, kt); krb5_free_context(context); exit(ret); } @@ -248,19 +277,15 @@ krb5_error_code do_connection(s, context) { struct sockaddr saddr; krb5_ticket *v5tkt = 0; - KTEXT_ST v4tkt; - krb5_keyblock v5_service_key, v4_service_key; krb5_data msgdata, tktdata; char msgbuf[MSGSIZE], tktbuf[TKT_BUFSIZ], *p; int n, ret, saddrlen; krb5_kvno v4kvno; - /* Clear out keyblock contents so we don't accidentally free the stack.*/ - v5_service_key.contents = v4_service_key.contents = 0; - msgdata.data = msgbuf; msgdata.length = MSGSIZE; - + tktdata.data = tktbuf; + tktdata.length = TKT_BUFSIZ; saddrlen = sizeof(struct sockaddr); ret = recvfrom(s, msgdata.data, msgdata.length, 0, &saddr, &saddrlen); if (ret < 0) { @@ -292,51 +317,41 @@ krb5_error_code do_connection(s, context) if (debug) printf("V5 ticket decoded\n"); - if ((ret = lookup_service_key(context, v5tkt->server, - v5tkt->enc_part.enctype, - v5tkt->enc_part.kvno, - &v5_service_key, NULL))) - goto error; - - if ((ret = lookup_service_key(context, v5tkt->server, - ENCTYPE_DES3_CBC_RAW, - 0, /* highest kvno */ - &v4_service_key, &v4kvno)) && - (ret = lookup_service_key(context, v5tkt->server, - ENCTYPE_LOCAL_DES3_HMAC_SHA1, - 0, - &v4_service_key, &v4kvno)) && - (ret = lookup_service_key(context, v5tkt->server, - ENCTYPE_DES3_CBC_SHA1, - 0, - &v4_service_key, &v4kvno)) && - (ret = lookup_service_key(context, v5tkt->server, - ENCTYPE_DES_CBC_CRC, - 0, - &v4_service_key, &v4kvno))) - goto error; - - if (debug) - printf("service key retrieved\n"); - - ret = krb524_convert_tkt_skey(context, v5tkt, &v4tkt, &v5_service_key, - &v4_service_key, - (struct sockaddr_in *)&saddr); - if (ret) - goto error; - - if (debug) - printf("credentials converted\n"); - - tktdata.data = tktbuf; - tktdata.length = TKT_BUFSIZ; - ret = encode_v4tkt(&v4tkt, tktdata.data, &tktdata.length); - if (ret) - goto error; - if (debug) - printf("v4 credentials encoded\n"); - -error: + if( v5tkt->server->length >= 1 + &&krb5_princ_component(context, v5tkt->server, 0)->length == 3 + &&strncmp(krb5_princ_component(context, v5tkt->server, 0)->data, + "afs", 3) == 0) { + krb5_data *enc_part; + int use_v5; + if ((ret = afs_return_v4(context, v5tkt->server, + &use_v5)) != 0) + goto error; + if ((ret = encode_krb5_enc_data( &v5tkt->enc_part, &enc_part)) != 0) + goto error; + if (!(use_v5 )|| enc_part->length >= 344) { + krb5_free_data(context, enc_part); + if ((ret = handle_classic_v4(context, v5tkt, + (struct sockaddr_in *) &saddr, &tktdata, + &v4kvno)) != 0) + goto error; + } else { + KTEXT_ST fake_v4tkt; + fake_v4tkt.mbz = 0; + fake_v4tkt.length = enc_part->length; + memcpy(fake_v4tkt.dat, enc_part->data, enc_part->length); + v4kvno = (0x100-0x2b); /*protocol constant indicating v5 + * enc part only*/ + krb5_free_data(context, enc_part); + ret = encode_v4tkt(&fake_v4tkt, tktdata.data, &tktdata.length); + } + } else { + if ((ret = handle_classic_v4(context, v5tkt, + (struct sockaddr_in *) &saddr, &tktdata, + &v4kvno)) != 0) + goto error; + } + + error: /* create the reply */ p = msgdata.data; msgdata.length = 0; @@ -366,11 +381,6 @@ write_msg: ret = errno; if (debug) printf("reply written\n"); -/* If we have keys to clean up, do so.*/ - if (v5_service_key.contents) - krb5_free_keyblock_contents(context, &v5_service_key); - if (v4_service_key.contents) - krb5_free_keyblock_contents(context, &v4_service_key); if (v5tkt) krb5_free_ticket(context, v5tkt); @@ -392,7 +402,18 @@ krb5_error_code lookup_service_key(context, p, ktype, kvno, key, kvnop) if (use_keytab) { if ((ret = krb5_kt_get_entry(context, kt, p, kvno, ktype, &entry))) return ret; - memcpy(key, (char *) &entry.key, sizeof(krb5_keyblock)); + *key = entry.key; + key->contents = malloc(key->length); + if (key->contents) + memcpy(key->contents, entry.key.contents, key->length); + else if (key->length) { + /* out of memory? */ + ret = errno; + memset (key, 0, sizeof (*key)); + return ret; + } + + krb5_kt_free_entry(context, &entry); return 0; } else if (use_master) { return kdc_get_server_key(context, p, key, kvnop, ktype, kvno); @@ -412,9 +433,15 @@ krb5_error_code kdc_get_server_key(context, service, key, kvnop, ktype, kvno) kadm5_principal_ent_rec server; if ((ret = kadm5_get_principal(handle, service, &server, - KADM5_KEY_DATA))) + KADM5_KEY_DATA|KADM5_ATTRIBUTES))) return ret; + if (server.attributes & KRB5_KDB_DISALLOW_ALL_TIX + || server.attributes & KRB5_KDB_DISALLOW_SVR) { + kadm5_free_principal_ent(handle, &server); + return KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN; + } + /* * We try kadm5_decrypt_key twice because in the case of a * ENCTYPE_DES_CBC_CRC key, we prefer to find a krb4 salt type @@ -442,3 +469,110 @@ krb5_error_code kdc_get_server_key(context, service, key, kvnop, ktype, kvno) kadm5_free_principal_ent(handle, &server); return ret; } + +/* + * We support two kinds of v4 credentials. There are real v4 + * credentials, and a Kerberos v5 enc part masquerading as a krb4 + * credential to be used by modern AFS implementations; this function + * handles the classic v4 case. + */ + +static krb5_error_code +handle_classic_v4 (krb5_context context, krb5_ticket *v5tkt, + struct sockaddr_in *saddr, + krb5_data *tktdata, krb5_kvno *v4kvno) +{ + krb5_error_code ret; + krb5_keyblock v5_service_key, v4_service_key; + KTEXT_ST v4tkt; + + v5_service_key.contents = NULL; + v4_service_key.contents = NULL; + + if ((ret = lookup_service_key(context, v5tkt->server, + v5tkt->enc_part.enctype, + v5tkt->enc_part.kvno, + &v5_service_key, NULL))) + goto error; + + if ((ret = lookup_service_key(context, v5tkt->server, + ENCTYPE_DES3_CBC_RAW, + 0, /* highest kvno */ + &v4_service_key, v4kvno)) && + (ret = lookup_service_key(context, v5tkt->server, + ENCTYPE_LOCAL_DES3_HMAC_SHA1, + 0, + &v4_service_key, v4kvno)) && + (ret = lookup_service_key(context, v5tkt->server, + ENCTYPE_DES3_CBC_SHA1, + 0, + &v4_service_key, v4kvno)) && + (ret = lookup_service_key(context, v5tkt->server, + ENCTYPE_DES_CBC_CRC, + 0, + &v4_service_key, v4kvno))) + goto error; + + if (debug) + printf("service key retrieved\n"); + + ret = krb524_convert_tkt_skey(context, v5tkt, &v4tkt, &v5_service_key, + &v4_service_key, + (struct sockaddr_in *)saddr); + if (ret) + goto error; + + if (debug) + printf("credentials converted\n"); + + ret = encode_v4tkt(&v4tkt, tktdata->data, &tktdata->length); + if (ret) + goto error; + if (debug) + printf("v4 credentials encoded\n"); + + error: + if(v5_service_key.contents) + krb5_free_keyblock_contents(context, &v5_service_key); + if (v4_service_key.contents) + krb5_free_keyblock_contents(context, &v4_service_key); + return ret; +} + +/* + * afs_return_v4: a predicate to determine whether we want to try + * using the afs krb5 encrypted part encoding or whether we just + * return krb4. Takes a principal, and checks the configuration file. + */ +static krb5_error_code +afs_return_v4 (krb5_context context, const krb5_principal princ, + int *use_v5) +{ + krb5_error_code ret; + char *unparsed_name; + char *cp; + krb5_data realm; + assert(use_v5 != NULL); + ret = krb5_unparse_name(context, princ, &unparsed_name); + if (ret != 0) + return ret; +/* Trim out trailing realm component into separate string.*/ + for (cp = unparsed_name; *cp != '\0'; cp++) { + if (*cp == '\\') { + cp++; /* We trust unparse_name not to leave a singleton + * backslash*/ + continue; + } + if (*cp == '@') { + *cp = '\0'; + realm.data = cp+1; + realm.length = strlen((char *) realm.data); + break; + } + } + krb5_appdefault_boolean(context, "afs_krb5", + &realm, unparsed_name, 1, + use_v5); + krb5_free_unparsed_name(context, unparsed_name); + return ret; +} diff --git a/src/krb524/misc.c b/src/krb524/misc.c index e28f4d1..fe263c3 100644 --- a/src/krb524/misc.c +++ b/src/krb524/misc.c @@ -27,8 +27,13 @@ #include #include +#if TARGET_OS_MAC +#include +#include +#else #include #include "krb524.h" +#endif void krb524_init_ets(context) krb5_context context; diff --git a/src/krb524/sendmsg.c b/src/krb524/sendmsg.c index 77e8f3b..981ecdb 100644 --- a/src/krb524/sendmsg.c +++ b/src/krb524/sendmsg.c @@ -40,11 +40,16 @@ #include #endif +#if TARGET_OS_MAC +#include +#include +#else #include #include "krb524.h" +#endif /* For krb5_locate_kdc() */ -#include +#include "k5-int.h" /* * krb524_sendto_kdc: @@ -66,12 +71,17 @@ extern int krb5_max_skdc_timeout; extern int krb5_skdc_timeout_shift; extern int krb5_skdc_timeout_1; +/* returns the local address of the socket used to connect to the KDC. + If you don't need this information, pass NULL for the last two parameters */ + krb5_error_code -krb524_sendto_kdc (context, message, realm, reply) +krb524_sendto_kdc (context, message, realm, reply, local_addr, addrlen) krb5_context context; const krb5_data * message; const krb5_data * realm; krb5_data * reply; + struct sockaddr * local_addr; + int * addrlen; { register int timeout, host, i; struct sockaddr *addr; @@ -207,7 +217,7 @@ krb524_sendto_kdc (context, message, realm, reply) sent = 1; continue; } - + /* We might consider here verifying that the reply came from one of the KDC's listed for that address type, but that check can be fouled by some implementations of @@ -215,6 +225,15 @@ krb524_sendto_kdc (context, message, realm, reply) address, for example, if the KDC is on the same host as the client. */ + /* If the caller wants the local address of this socket + store it here */ + if ((local_addr != NULL) && (addrlen != NULL) && (addrlen > 0)) { + if (getsockname (socklist[host], local_addr, addrlen) == SOCKET_ERROR) { + /* no address to get... tell the caller we got nothing */ + *addrlen = 0; + } + } + reply->length = cc; retval = 0; goto out; diff --git a/src/lib/ChangeLog b/src/lib/ChangeLog index b5abe94..d1daec7 100644 --- a/src/lib/ChangeLog +++ b/src/lib/ChangeLog @@ -1,3 +1,63 @@ +2002-04-16 Danilo Almeida + + * krb5_32.def: Remove krb5_mcc_ops and krb5_cc_register() as + GSSAPI no longer needs those. + +2002-04-16 Danilo Almeida + + * krb5_32.def: Add krb5_free_ap_req() as private for GSSAPI. Add + krb5_get_host_realm() and krb5_free_host_realm() as public + functions. Reformat to make it easier to read and compare. + +2002-04-05 Danilo Almeida + + * krb5_32.def: Hopefully final cut at consistent exports between + Windows and MacOS X. Still has private stuff needed by gssapi and + krb4. + +2002-04-03 Danilo Almeida + + * krb5_32.def: First cut at consistent exports between Windows and + MacOS X. More work needs to be done. + +2001-11-29 Danilo Almeida + + * gssapi32.def: Export gss_mech_krb5 as DATA. Mark all exported + variables as DATA. [Copied over from trunk.] + +2000-06-02 Danilo Almeida + + * win_glue.c (GetCallingAppVerInfo, krb5_vercheck): Use + APPVERINFO_SIZE-sized buffers instead of hard-coding a number + everywhere. Document the buffer size in funciton documentation. + + * krb5_32.def: Add krb5int_cc_default for the benefit of GSS API DLL. + +2000-05-23 Nalin Dahyabhai + + * win_glue.c (GetCallingAppVerInfo): Don't overfill buffers + "AppTitle", "AppVer", and "AppIni". + +2000-05-15 Jeffrey Altman + + * krb5_32.def -- Added exports for new public functions + + krb5_appdefault_string + krb5_appdefault_boolean + +2000-05-04 Danilo Almeida + + * krb5_32.def: Reflect something closer to the reality of + what we would like to do for 1.3. + +2000-05-03 Nalin Dahyabhai + + * win_glue.c (do_timebomb): Don't overflow buffer "buf". + +2000-04-29 Jeffrey Altman + + * krb5_32.def: Add krb5_get_tgs_ktypes, krb5_free_ktypes for gssapi + 2000-03-15 Danilo Almeida * krb5_32.def: Add krb5_get_prompt_types. diff --git a/src/lib/crypto/ChangeLog b/src/lib/crypto/ChangeLog index a48ec1f..058576d 100644 --- a/src/lib/crypto/ChangeLog +++ b/src/lib/crypto/ChangeLog @@ -1,3 +1,24 @@ +2002-04-02 Ken Raeburn + + * valid_enctype.c (krb5_c_valid_enctype): New name on old + function, with old name kept as an alias (wrapper). + * keyed_cksum.c (krb5_c_is_keyed_cksum): Likewise. + * valid_cksumtype.c (krb5_c_valid_cksumtype): Likewise. + * coll_proof_cksum.c (krb5_c_is_coll_proof_cksum): Likewise. + +2002-02-28 Alexandra Ellwood + * crypto_libinit.h: Changed macros so you can include crypto_libinit.h + and krb5_libinit.h at the same time + +2001-01-29 Ken Raeburn + + * make_checksum.c (krb5_c_make_checksum): Clear checksum contents + pointer after freeing it in error case. + +2000-06-03 Tom Yu + + * Makefile.in(LIBMAJOR, LIBMINOR): Bump library version. + 2000-01-24 Tom Yu * crypto_libinit.c: Add terminating newline; use 0 and 1 instead diff --git a/src/lib/crypto/Makefile.in b/src/lib/crypto/Makefile.in index 71bddf5..64f19d1 100644 --- a/src/lib/crypto/Makefile.in +++ b/src/lib/crypto/Makefile.in @@ -106,8 +106,8 @@ SRCS=\ LIB=k5crypto -LIBMAJOR=2 -LIBMINOR=1 +LIBMAJOR=3 +LIBMINOR=0 RELDIR=crypto STOBJLISTS=crc32/OBJS.ST des/OBJS.ST dk/OBJS.ST enc_provider/OBJS.ST \ diff --git a/src/lib/crypto/coll_proof_cksum.c b/src/lib/crypto/coll_proof_cksum.c index 31bf1fe..95a2aef 100644 --- a/src/lib/crypto/coll_proof_cksum.c +++ b/src/lib/crypto/coll_proof_cksum.c @@ -28,7 +28,7 @@ #include "cksumtypes.h" KRB5_DLLIMP krb5_boolean KRB5_CALLCONV -is_coll_proof_cksum(ctype) +krb5_c_is_coll_proof_cksum(ctype) krb5_cksumtype ctype; { int i; @@ -43,3 +43,10 @@ is_coll_proof_cksum(ctype) old code would have done */ return(0); } + +#undef is_coll_proof_cksum +KRB5_DLLIMP krb5_boolean KRB5_CALLCONV +is_coll_proof_cksum(krb5_cksumtype ctype) +{ + return krb5_c_is_coll_proof_cksum (ctype); +} diff --git a/src/lib/crypto/crypto_libinit.h b/src/lib/crypto/crypto_libinit.h index 3586a63..44c7e16 100644 --- a/src/lib/crypto/crypto_libinit.h +++ b/src/lib/crypto/crypto_libinit.h @@ -1,7 +1,7 @@ -#ifndef KRB5_LIBINIT_H -#define KRB5_LIBINIT_H +#ifndef K5CRYPTO_LIBINIT_H +#define K5CRYPTO_LIBINIT_H int cryptoint_initialize_library (void); void cryptoint_cleanup_library (void); -#endif /* KRB5_LIBINIT_H */ +#endif /* K5CRYPTO_LIBINIT_H */ diff --git a/src/lib/crypto/des/ChangeLog b/src/lib/crypto/des/ChangeLog index 7a2155c..7438600 100644 --- a/src/lib/crypto/des/ChangeLog +++ b/src/lib/crypto/des/ChangeLog @@ -1,3 +1,21 @@ +2002-08-16 Tom Yu + + * string2key.c: Work around possible bug with AFS salts; + [krb5-clients/1146] from . + [port from trunk] + +2002-03-14 Alexandra Ellwood + * afsstring2key.c: made static data const to improve load time + on Mach-O + +2002-02-28 Alexandra Ellwood + * afsstring2key.c: fixed warnings about types defaulting to int + and two-dimensional array declaration without second-level braces + +2001-10-29 Miro Jurisic + * pullup from krb5-1-2 branch after krb5-1-2-2-bp + * des_int.h: use "" includes for k5-int.h + 2000-02-25 Ezra Peisach * t_verify.c: Add "const" to casts in calls to mit_des_cbc_encrypt(). diff --git a/src/lib/crypto/des/afsstring2key.c b/src/lib/crypto/des/afsstring2key.c index 7eac080..7c828ba 100644 --- a/src/lib/crypto/des/afsstring2key.c +++ b/src/lib/crypto/des/afsstring2key.c @@ -150,7 +150,7 @@ static void krb5_afs_encrypt PROTOTYPE((char*,long)); /* * Initial permutation, */ -static char IP[] = { +static const char IP[] = { 58,50,42,34,26,18,10, 2, 60,52,44,36,28,20,12, 4, 62,54,46,38,30,22,14, 6, @@ -164,7 +164,7 @@ static char IP[] = { /* * Final permutation, FP = IP^(-1) */ -static char FP[] = { +static const char FP[] = { 40, 8,48,16,56,24,64,32, 39, 7,47,15,55,23,63,31, 38, 6,46,14,54,22,62,30, @@ -179,14 +179,14 @@ static char FP[] = { * Permuted-choice 1 from the key bits to yield C and D. * Note that bits 8,16... are left out: They are intended for a parity check. */ -static char PC1_C[] = { +static const char PC1_C[] = { 57,49,41,33,25,17, 9, 1,58,50,42,34,26,18, 10, 2,59,51,43,35,27, 19,11, 3,60,52,44,36, }; -static char PC1_D[] = { +static const char PC1_D[] = { 63,55,47,39,31,23,15, 7,62,54,46,38,30,22, 14, 6,61,53,45,37,29, @@ -196,7 +196,7 @@ static char PC1_D[] = { /* * Sequence of shifts used for the key schedule. */ -static char shifts[] = { +static const char shifts[] = { 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1, }; @@ -204,14 +204,14 @@ static char shifts[] = { * Permuted-choice 2, to pick out the bits from * the CD array that generate the key schedule. */ -static char PC2_C[] = { +static const char PC2_C[] = { 14,17,11,24, 1, 5, 3,28,15, 6,21,10, 23,19,12, 4,26, 8, 16, 7,27,20,13, 2, }; -static char PC2_D[] = { +static const char PC2_D[] = { 41,52,31,37,47,55, 30,40,51,45,33,48, 44,49,39,56,34,53, @@ -222,7 +222,7 @@ static char PC2_D[] = { * The E bit-selection table. */ static char E[48]; -static char e[] = { +static const char e[] = { 32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9,10,11,12,13, @@ -237,7 +237,7 @@ static char e[] = { * P is a permutation on the selected combination * of the current L and key. */ -static char P[] = { +static const char P[] = { 16, 7,20,21, 29,12,28,17, 1,15,23,26, @@ -253,46 +253,46 @@ static char P[] = { * For some reason, they give a 0-origin * index, unlike everything else. */ -static char S[8][64] = { - 14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7, +static const char S[8][64] = { + {14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7, 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8, 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0, - 15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13, + 15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13}, - 15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10, + {15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10, 3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5, 0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15, - 13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9, + 13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9}, - 10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8, + {10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8, 13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1, 13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7, - 1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12, + 1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12}, - 7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15, + {7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15, 13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9, 10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4, - 3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14, + 3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14}, - 2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9, + {2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9, 14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6, 4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14, - 11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3, + 11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3}, - 12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11, + {12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11, 10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8, 9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6, - 4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13, + 4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13}, - 4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1, + {4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1, 13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6, 1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2, - 6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12, + 6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12}, - 13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7, + {13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7, 1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2, 7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8, - 2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11, + 2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11}, }; /* @@ -325,7 +325,7 @@ static char *afs_crypt(pw, salt) char *pw; char *salt; { - register i, j, c; + register int i, j, c; int temp; static char block[66], iobuf[16]; @@ -384,7 +384,7 @@ static char *afs_crypt(pw, salt) static void krb5_afs_crypt_setkey(key) char *key; { - register i, j, k; + register int i, j, k; int t; /* @@ -439,7 +439,7 @@ static void krb5_afs_encrypt(block, edflag) long edflag; { int i, ii; - register t, j, k; + register int t, j, k; /* * First, permute the bits in the input diff --git a/src/lib/crypto/des/des_int.h b/src/lib/crypto/des/des_int.h index de8f2a4..bd591ae 100644 --- a/src/lib/crypto/des/des_int.h +++ b/src/lib/crypto/des/des_int.h @@ -57,7 +57,7 @@ #ifndef DES_INTERNAL_DEFS #define DES_INTERNAL_DEFS -#include +#include "k5-int.h" /* * Begin "mit-des.h" */ diff --git a/src/lib/crypto/des/string2key.c b/src/lib/crypto/des/string2key.c index 5381fdb..d51145b 100644 --- a/src/lib/crypto/des/string2key.c +++ b/src/lib/crypto/des/string2key.c @@ -99,6 +99,9 @@ const krb5_data FAR * salt; if (salt) { if (salt->length == -1) { /* cheat and do AFS string2key instead */ + char *c; + c = strchr(salt->data, '@'); + if (c != NULL) *c = '\0'; /* workaround from krb5-clients/1146 */ return mit_afs_string_to_key (keyblock, data, salt); } else length = data->length + salt->length; diff --git a/src/lib/crypto/dk/ChangeLog b/src/lib/crypto/dk/ChangeLog index 90e34f8..7908f56 100644 --- a/src/lib/crypto/dk/ChangeLog +++ b/src/lib/crypto/dk/ChangeLog @@ -1,3 +1,17 @@ +2000-06-03 Tom Yu + + * dk_encrypt.c (krb5_dk_encrypt, krb5_marc_dk_encrypt): Chain + ivecs. + + * dk_decrypt.c (krb5_dk_decrypt, krb5_marc_dk_decrypt): Chain + ivecs. + +2000-04-28 Ken Raeburn + + * derive.c (krb5_derive_key): If memory allocation fails, release + other allocated blocks before returning, instead of trying to + release them after returning. + 2000-01-21 Ken Raeburn * checksum.c (krb5_dk_make_checksum): enc_providers are now diff --git a/src/lib/crypto/dk/derive.c b/src/lib/crypto/dk/derive.c index 8765605..dbd4a2a 100644 --- a/src/lib/crypto/dk/derive.c +++ b/src/lib/crypto/dk/derive.c @@ -51,14 +51,14 @@ krb5_derive_key(enc, inkey, outkey, in_constant) return(ENOMEM); if ((outblockdata = (unsigned char *) malloc(blocksize)) == NULL) { - return(ENOMEM); free(inblockdata); + return(ENOMEM); } if ((rawkey = (unsigned char *) malloc(keybytes)) == NULL) { - return(ENOMEM); free(outblockdata); free(inblockdata); + return(ENOMEM); } inblock.data = inblockdata; diff --git a/src/lib/crypto/dk/dk_decrypt.c b/src/lib/crypto/dk/dk_decrypt.c index d307761..d6e7c0d 100644 --- a/src/lib/crypto/dk/dk_decrypt.c +++ b/src/lib/crypto/dk/dk_decrypt.c @@ -41,7 +41,7 @@ krb5_dk_decrypt(enc, hash, key, usage, ivec, input, output) { krb5_error_code ret; size_t hashsize, blocksize, keybytes, keylength, enclen, plainlen; - unsigned char *plaindata, *kedata, *kidata, *cksum; + unsigned char *plaindata, *kedata, *kidata, *cksum, *cn; krb5_keyblock ke, ki; krb5_data d1, d2; unsigned char constantdata[K5CLENGTH]; @@ -108,6 +108,11 @@ krb5_dk_decrypt(enc, hash, key, usage, ivec, input, output) if ((ret = ((*(enc->decrypt))(&ke, ivec, &d1, &d2))) != 0) goto cleanup; + if (ivec != NULL && ivec->length == blocksize) + cn = d1.data + d1.length - blocksize; + else + cn = NULL; + /* verify the hash */ d1.length = hashsize; @@ -134,6 +139,9 @@ krb5_dk_decrypt(enc, hash, key, usage, ivec, input, output) memcpy(output->data, d2.data+blocksize, output->length); + if (cn != NULL) + memcpy(ivec->data, cn, blocksize); + ret = 0; cleanup: @@ -163,7 +171,7 @@ krb5_marc_dk_decrypt(enc, hash, key, usage, ivec, input, output) { krb5_error_code ret; size_t hashsize, blocksize, keybytes, keylength, enclen, plainlen; - unsigned char *plaindata, *kedata, *kidata, *cksum; + unsigned char *plaindata, *kedata, *kidata, *cksum, *cn; krb5_keyblock ke, ki; krb5_data d1, d2; unsigned char constantdata[K5CLENGTH]; @@ -230,6 +238,11 @@ krb5_marc_dk_decrypt(enc, hash, key, usage, ivec, input, output) if ((ret = ((*(enc->decrypt))(&ke, ivec, &d1, &d2))) != 0) goto cleanup; + if (ivec != NULL && ivec->length == blocksize) + cn = d1.data + d1.length - blocksize; + else + cn = NULL; + /* verify the hash */ d1.length = hashsize; @@ -264,6 +277,9 @@ krb5_marc_dk_decrypt(enc, hash, key, usage, ivec, input, output) memcpy(output->data, d2.data+4+blocksize, output->length); + if (cn != NULL) + memcpy(ivec->data, cn, blocksize); + ret = 0; cleanup: diff --git a/src/lib/crypto/dk/dk_encrypt.c b/src/lib/crypto/dk/dk_encrypt.c index 8627353..2bc2b6b 100644 --- a/src/lib/crypto/dk/dk_encrypt.c +++ b/src/lib/crypto/dk/dk_encrypt.c @@ -65,7 +65,7 @@ krb5_dk_encrypt(enc, hash, key, usage, ivec, input, output) krb5_error_code ret; unsigned char constantdata[K5CLENGTH]; krb5_data d1, d2; - unsigned char *plaintext, *kedata, *kidata; + unsigned char *plaintext, *kedata, *kidata, *cn; krb5_keyblock ke, ki; /* allocate and set up plaintext and to-be-derived keys */ @@ -142,6 +142,11 @@ krb5_dk_encrypt(enc, hash, key, usage, ivec, input, output) if ((ret = ((*(enc->encrypt))(&ke, ivec, &d1, &d2)))) goto cleanup; + if (ivec != NULL && ivec->length == blocksize) + cn = d2.data + d2.length - blocksize; + else + cn = NULL; + /* hash the plaintext */ d2.length = enclen - plainlen; @@ -149,8 +154,14 @@ krb5_dk_encrypt(enc, hash, key, usage, ivec, input, output) output->length = enclen; - if ((ret = krb5_hmac(hash, &ki, 1, &d1, &d2))) + if ((ret = krb5_hmac(hash, &ki, 1, &d1, &d2))) { memset(d2.data, 0, d2.length); + goto cleanup; + } + + /* update ivec */ + if (cn != NULL) + memcpy(ivec->data, cn, blocksize); /* ret is set correctly by the prior call */ @@ -196,7 +207,7 @@ krb5_marc_dk_encrypt(enc, hash, key, usage, ivec, input, output) krb5_error_code ret; unsigned char constantdata[K5CLENGTH]; krb5_data d1, d2; - unsigned char *plaintext, *kedata, *kidata; + unsigned char *plaintext, *kedata, *kidata, *cn; krb5_keyblock ke, ki; /* allocate and set up plaintext and to-be-derived keys */ @@ -278,6 +289,11 @@ krb5_marc_dk_encrypt(enc, hash, key, usage, ivec, input, output) if ((ret = ((*(enc->encrypt))(&ke, ivec, &d1, &d2)))) goto cleanup; + if (ivec != NULL && ivec->length == blocksize) + cn = d2.data + d2.length - blocksize; + else + cn = NULL; + /* hash the plaintext */ d2.length = enclen - plainlen; @@ -285,8 +301,14 @@ krb5_marc_dk_encrypt(enc, hash, key, usage, ivec, input, output) output->length = enclen; - if ((ret = krb5_hmac(hash, &ki, 1, &d1, &d2))) + if ((ret = krb5_hmac(hash, &ki, 1, &d1, &d2))) { memset(d2.data, 0, d2.length); + goto cleanup; + } + + /* update ivec */ + if (cn != NULL) + memcpy(ivec->data, cn, blocksize); /* ret is set correctly by the prior call */ diff --git a/src/lib/crypto/keyed_cksum.c b/src/lib/crypto/keyed_cksum.c index 39979c0..e32620e 100644 --- a/src/lib/crypto/keyed_cksum.c +++ b/src/lib/crypto/keyed_cksum.c @@ -28,7 +28,7 @@ #include "cksumtypes.h" KRB5_DLLIMP krb5_boolean KRB5_CALLCONV -is_keyed_cksum(ctype) +krb5_c_is_keyed_cksum(ctype) krb5_cksumtype ctype; { int i; @@ -48,3 +48,9 @@ is_keyed_cksum(ctype) old code would have done */ return(-1); } + +KRB5_DLLIMP krb5_boolean KRB5_CALLCONV +is_keyed_cksum(krb5_cksumtype ctype) +{ + return krb5_c_is_keyed_cksum (ctype); +} diff --git a/src/lib/crypto/make_checksum.c b/src/lib/crypto/make_checksum.c index 300f375..64f6389 100644 --- a/src/lib/crypto/make_checksum.c +++ b/src/lib/crypto/make_checksum.c @@ -114,6 +114,7 @@ cleanup: if (ret) { memset(cksum->contents, 0, cksum->length); free(cksum->contents); + cksum->contents = NULL; } return(ret); diff --git a/src/lib/crypto/old/ChangeLog b/src/lib/crypto/old/ChangeLog index cada473..74f994b 100644 --- a/src/lib/crypto/old/ChangeLog +++ b/src/lib/crypto/old/ChangeLog @@ -1,3 +1,9 @@ +2000-06-03 Tom Yu + + * old_encrypt.c (krb5_old_encrypt): Chain ivecs. + + * old_decrypt.c (krb5_old_decrypt): Chain ivecs. + 2000-01-21 Ken Raeburn * des_stringtokey.c (mit_des_string_to_key_int): Declare. diff --git a/src/lib/crypto/old/old_decrypt.c b/src/lib/crypto/old/old_decrypt.c index 1bcb0d3..bfbe56a 100644 --- a/src/lib/crypto/old/old_decrypt.c +++ b/src/lib/crypto/old/old_decrypt.c @@ -45,7 +45,7 @@ krb5_old_decrypt(enc, hash, key, usage, ivec, input, arg_output) { krb5_error_code ret; size_t blocksize, hashsize, plainsize; - unsigned char *cksumdata; + unsigned char *cksumdata, *cn; krb5_data output, cksum, crcivec; int alloced; @@ -82,6 +82,17 @@ krb5_old_decrypt(enc, hash, key, usage, ivec, input, arg_output) /* decrypt it */ + /* save last ciphertext block in case we decrypt in place */ + if (ivec != NULL && ivec->length == blocksize) { + cn = malloc(blocksize); + if (cn == NULL) { + ret = ENOMEM; + goto cleanup; + } + memcpy(cn, input->data + input->length - blocksize, blocksize); + } else + cn = NULL; + /* XXX this is gross, but I don't have much choice */ if ((key->enctype == ENCTYPE_DES_CBC_CRC) && (ivec == 0)) { crcivec.length = key->length; @@ -119,6 +130,10 @@ krb5_old_decrypt(enc, hash, key, usage, ivec, input, arg_output) } arg_output->length = plainsize; + /* update ivec */ + if (cn != NULL) + memcpy(ivec->data, cn, blocksize); + ret = 0; cleanup: @@ -127,6 +142,8 @@ cleanup: free(output.data); } + if (cn != NULL) + free(cn); memset(cksumdata, 0, hashsize); free(cksumdata); return(ret); diff --git a/src/lib/crypto/old/old_encrypt.c b/src/lib/crypto/old/old_encrypt.c index d90d0f8..8860ba5 100644 --- a/src/lib/crypto/old/old_encrypt.c +++ b/src/lib/crypto/old/old_encrypt.c @@ -55,6 +55,7 @@ krb5_old_encrypt(enc, hash, key, usage, ivec, input, output) krb5_error_code ret; size_t blocksize, hashsize, enclen; krb5_data datain, crcivec; + int real_ivec; (*(enc->block_size))(&blocksize); (*(hash->hash_size))(&hashsize); @@ -92,11 +93,17 @@ krb5_old_encrypt(enc, hash, key, usage, ivec, input, output) crcivec.length = key->length; crcivec.data = key->contents; ivec = &crcivec; - } + real_ivec = 0; + } else + real_ivec = 1; if ((ret = ((*(enc->encrypt))(key, ivec, output, output)))) goto cleanup; + /* update ivec */ + if (real_ivec && ivec != NULL && ivec->length == blocksize) + memcpy(ivec->data, output->data + output->length - blocksize, + blocksize); cleanup: if (ret) memset(output->data, 0, output->length); diff --git a/src/lib/crypto/prng.c b/src/lib/crypto/prng.c index 6d401a9..b22131e 100644 --- a/src/lib/crypto/prng.c +++ b/src/lib/crypto/prng.c @@ -158,4 +158,4 @@ void prng_cleanup (void) { free (random_state); inited = 0; -} \ No newline at end of file +} diff --git a/src/lib/crypto/sha1/ChangeLog b/src/lib/crypto/sha1/ChangeLog index a6a00f3..0030dc9 100644 --- a/src/lib/crypto/sha1/ChangeLog +++ b/src/lib/crypto/sha1/ChangeLog @@ -1,3 +1,26 @@ +2001-10-29 Miro Jurisic + * pullup from krb5-1-2 branch after krb5-1-2-2-bp + * shs.c: use "" include for k5-int.h + +2001-07-16 Ken Raeburn + + * t_shs3.c: New test file from Marcus Watts. + (longReverse): Resurrected function long since deleted from + shs.c. + * Makefile.in (check-unix, check-windows): Use t_shs3 test. + (clean): Delete it. + + * shs.c (SHSTransform): Make input data pointer point to const. + (SHSUpdate): Bugfixes suggested by Marcus Watts, to fix buffer + overruns, bugs with small or odd block sizes. + +2001-07-05 Danilo Almeida + + * shs.h, shs.c, t_shs.c: Fix sha1 on Windows by renaming LONG to + SHS_LONG to avoid problem with LONG being signed on Windows. + Rename BYTE to SHS_BYTE to avoid any name colisions with Windows + (where BYTE and LONG are types defined in the Platform SDK). + 2000-01-21 Ken Raeburn * shs.c (ROTL): Change (a&b|c) construct to make meaning clear, diff --git a/src/lib/crypto/sha1/Makefile.in b/src/lib/crypto/sha1/Makefile.in index 5d1b69c..2d0e209 100644 --- a/src/lib/crypto/sha1/Makefile.in +++ b/src/lib/crypto/sha1/Makefile.in @@ -33,13 +33,28 @@ t_shs: t_shs.o shs.o $(OUTPRE)t_shs.exe: $(OUTPRE)t_shs.obj $(OUTPRE)shs.obj link -out:$@ $** -check-unix:: t_shs +check-unix:: t_shs t_shs3 $(C)t_shs -x + $(C)t_shs3 -check-windows:: $(OUTPRE)t_shs.exe +check-windows:: $(OUTPRE)t_shs.exe $(OUTPRE)t_shs3.exe $(OUTPRE)$(C)t_shs.exe -x + $(OUTPRE)$(C)t_shs3.exe clean:: - $(RM) t_shs$(EXEEXT) t_shs.$(OBJEXT) + $(RM) t_shs$(EXEEXT) t_shs.$(OBJEXT) t_shs3$(EXEEXT) t_shs3.$(OBJEXT) clean-unix:: clean-libobjs + +t_shs3: t_shs3.o shs.o + $(CC) $(ALL_CFLAGS) $(LDFLAGS) -o t_shs3 t_shs3.o shs.o +# +++ Dependency line eater +++ +# +# Makefile dependencies follow. This must be the last section in +# the Makefile.in file +# +shs.o: shs.c shs.h $(SRCTOP)/include/k5-int.h $(BUILDTOP)/include/krb5/osconf.h \ + $(BUILDTOP)/include/krb5/autoconf.h $(BUILDTOP)/include/krb5.h \ + $(BUILDTOP)/include/profile.h $(BUILDTOP)/include/com_err.h \ + $(SRCTOP)/include/krb5/kdb.h + diff --git a/src/lib/crypto/sha1/shs.c b/src/lib/crypto/sha1/shs.c index 358e6ba..873f878 100644 --- a/src/lib/crypto/sha1/shs.c +++ b/src/lib/crypto/sha1/shs.c @@ -97,15 +97,15 @@ void shsInit(shsInfo) Note that this corrupts the shsInfo->data area */ -static void SHSTransform KRB5_PROTOTYPE((LONG *digest, LONG *data)); +static void SHSTransform (SHS_LONG *digest, const SHS_LONG *data); static void SHSTransform(digest, data) - LONG *digest; - LONG *data; + SHS_LONG *digest; + const SHS_LONG *data; { - LONG A, B, C, D, E; /* Local vars */ - LONG eData[ 16 ]; /* Expanded data */ + SHS_LONG A, B, C, D, E; /* Local vars */ + SHS_LONG eData[ 16 ]; /* Expanded data */ /* Set up first buffer and local data buffer */ A = digest[ 0 ]; @@ -217,16 +217,16 @@ void SHSTransform(digest, data) void shsUpdate(shsInfo, buffer, count) SHS_INFO *shsInfo; - BYTE *buffer; + SHS_BYTE *buffer; int count; { - LONG tmp; + SHS_LONG tmp; int dataCount, canfill; - LONG *lp; + SHS_LONG *lp; /* Update bitcount */ tmp = shsInfo->countLo; - shsInfo->countLo = tmp + (((LONG) count) << 3 ); + shsInfo->countLo = tmp + (((SHS_LONG) count) << 3 ); if ((shsInfo->countLo &= 0xffffffff) < tmp) shsInfo->countHi++; /* Carry from low to high */ shsInfo->countHi += count >> 29; @@ -237,37 +237,38 @@ void shsUpdate(shsInfo, buffer, count) /* Handle any leading odd-sized chunks */ if (dataCount) { lp = shsInfo->data + dataCount / 4; - canfill = (count >= dataCount); dataCount = SHS_DATASIZE - dataCount; + canfill = (count >= dataCount); if (dataCount % 4) { /* Fill out a full 32 bit word first if needed -- this is not very efficient (computed shift amount), but it shouldn't happen often. */ while (dataCount % 4 && count > 0) { - *lp |= (LONG) *buffer++ << ((3 - dataCount++ % 4) * 8); + *lp |= (SHS_LONG) *buffer++ << ((--dataCount % 4) * 8); count--; } lp++; } while (lp < shsInfo->data + 16) { - *lp = (LONG) *buffer++ << 24; - *lp |= (LONG) *buffer++ << 16; - *lp |= (LONG) *buffer++ << 8; - *lp++ |= (LONG) *buffer++; - if ((count -= 4) < 4 && lp < shsInfo->data + 16) { + if (count < 4) { *lp = 0; switch (count % 4) { case 3: - *lp |= (LONG) buffer[2] << 8; + *lp |= (SHS_LONG) buffer[2] << 8; case 2: - *lp |= (LONG) buffer[1] << 16; + *lp |= (SHS_LONG) buffer[1] << 16; case 1: - *lp |= (LONG) buffer[0] << 24; + *lp |= (SHS_LONG) buffer[0] << 24; } - break; count = 0; + break; /* out of while loop */ } + *lp = (SHS_LONG) *buffer++ << 24; + *lp |= (SHS_LONG) *buffer++ << 16; + *lp |= (SHS_LONG) *buffer++ << 8; + *lp++ |= (SHS_LONG) *buffer++; + count -= 4; } if (canfill) { SHSTransform(shsInfo->digest, shsInfo->data); @@ -278,10 +279,10 @@ void shsUpdate(shsInfo, buffer, count) while (count >= SHS_DATASIZE) { lp = shsInfo->data; while (lp < shsInfo->data + 16) { - *lp = ((LONG) *buffer++) << 24; - *lp |= ((LONG) *buffer++) << 16; - *lp |= ((LONG) *buffer++) << 8; - *lp++ |= (LONG) *buffer++; + *lp = ((SHS_LONG) *buffer++) << 24; + *lp |= ((SHS_LONG) *buffer++) << 16; + *lp |= ((SHS_LONG) *buffer++) << 8; + *lp++ |= (SHS_LONG) *buffer++; } SHSTransform(shsInfo->digest, shsInfo->data); count -= SHS_DATASIZE; @@ -290,22 +291,22 @@ void shsUpdate(shsInfo, buffer, count) if (count > 0) { lp = shsInfo->data; while (count > 4) { - *lp = ((LONG) *buffer++) << 24; - *lp |= ((LONG) *buffer++) << 16; - *lp |= ((LONG) *buffer++) << 8; - *lp++ |= (LONG) *buffer++; + *lp = ((SHS_LONG) *buffer++) << 24; + *lp |= ((SHS_LONG) *buffer++) << 16; + *lp |= ((SHS_LONG) *buffer++) << 8; + *lp++ |= (SHS_LONG) *buffer++; count -= 4; } *lp = 0; switch (count % 4) { case 0: - *lp |= ((LONG) buffer[3]); + *lp |= ((SHS_LONG) buffer[3]); case 3: - *lp |= ((LONG) buffer[2]) << 8; + *lp |= ((SHS_LONG) buffer[2]) << 8; case 2: - *lp |= ((LONG) buffer[1]) << 16; + *lp |= ((SHS_LONG) buffer[1]) << 16; case 1: - *lp |= ((LONG) buffer[0]) << 24; + *lp |= ((SHS_LONG) buffer[0]) << 24; } } } @@ -317,7 +318,7 @@ void shsFinal(shsInfo) SHS_INFO *shsInfo; { int count; - LONG *lp; + SHS_LONG *lp; /* Compute number of bytes mod 64 */ count = (int) shsInfo->countLo; @@ -328,16 +329,16 @@ void shsFinal(shsInfo) lp = shsInfo->data + count / 4; switch (count % 4) { case 3: - *lp++ |= (LONG) 0x80; + *lp++ |= (SHS_LONG) 0x80; break; case 2: - *lp++ |= (LONG) 0x80 << 8; + *lp++ |= (SHS_LONG) 0x80 << 8; break; case 1: - *lp++ |= (LONG) 0x80 << 16; + *lp++ |= (SHS_LONG) 0x80 << 16; break; case 0: - *lp++ = (LONG) 0x80 << 24; + *lp++ = (SHS_LONG) 0x80 << 24; } /* at this point, lp can point *past* shsInfo->data. If it points diff --git a/src/lib/crypto/sha1/shs.h b/src/lib/crypto/sha1/shs.h index 01acddb..24eda9e 100644 --- a/src/lib/crypto/sha1/shs.h +++ b/src/lib/crypto/sha1/shs.h @@ -1,18 +1,13 @@ #ifndef _SHS_DEFINED -#include +#include "k5-int.h" #define _SHS_DEFINED /* Some useful types */ -typedef krb5_octet BYTE; - -/* Old DOS/Windows compilers are case-insensitive */ -#if !defined(_MSDOS) && !defined(_WIN32) -typedef krb5_ui_4 LONG; -#endif - +typedef krb5_octet SHS_BYTE; +typedef krb5_ui_4 SHS_LONG; /* Define the following to use the updated SHS implementation */ #define NEW_SHS /**/ @@ -25,16 +20,16 @@ typedef krb5_ui_4 LONG; /* The structure for storing SHS info */ typedef struct { - LONG digest[ 5 ]; /* Message digest */ - LONG countLo, countHi; /* 64-bit bit count */ - LONG data[ 16 ]; /* SHS data buffer */ + SHS_LONG digest[ 5 ]; /* Message digest */ + SHS_LONG countLo, countHi; /* 64-bit bit count */ + SHS_LONG data[ 16 ]; /* SHS data buffer */ } SHS_INFO; /* Message digest functions (shs.c) */ void shsInit KRB5_PROTOTYPE((SHS_INFO *shsInfo)); void shsUpdate - KRB5_PROTOTYPE((SHS_INFO *shsInfo, BYTE *buffer, int count)); + KRB5_PROTOTYPE((SHS_INFO *shsInfo, SHS_BYTE *buffer, int count)); void shsFinal KRB5_PROTOTYPE((SHS_INFO *shsInfo)); diff --git a/src/lib/crypto/sha1/t_shs.c b/src/lib/crypto/sha1/t_shs.c index da55992..de021bb 100644 --- a/src/lib/crypto/sha1/t_shs.c +++ b/src/lib/crypto/sha1/t_shs.c @@ -13,7 +13,7 @@ #ifdef NEW_SHS -static LONG shsTestResults[][ 5 ] = { +static SHS_LONG shsTestResults[][ 5 ] = { { 0xA9993E36L, 0x4706816AL, 0xBA3E2571L, 0x7850C26CL, 0x9CD0D89DL, }, { 0x84983E44L, 0x1C3BD26EL, 0xBAAE4AA1L, 0xF95129E5L, 0xE54670F1L, }, { 0x34AA973CL, 0xD4C4DAA4L, 0xF61EEB2BL, 0xDBAD2731L, 0x6534016FL, } @@ -21,7 +21,7 @@ static LONG shsTestResults[][ 5 ] = { #else -static LONG shsTestResults[][ 5 ] = { +static SHS_LONG shsTestResults[][ 5 ] = { { 0x0164B8A9L, 0x14CD2A5EL, 0x74C4F7FFL, 0x082C4D97L, 0xF1EDF880L }, { 0xD2516EE1L, 0xACFA5BAFL, 0x33DFC1C4L, 0x71E43844L, 0x9EF134C8L }, { 0x3232AFFAL, 0x48628A26L, 0x653B5AAAL, 0x44541FD9L, 0x0D690603L } @@ -58,7 +58,7 @@ main() SHS_INFO shsInfo; unsigned int i; time_t secondCount; - BYTE data[ 200 ]; + SHS_BYTE data[ 200 ]; /* Make sure we've got the endianness set right. If the machine is big-endian (up to 64 bits) the following value will be signed, @@ -69,7 +69,7 @@ main() /* Test SHS against values given in SHS standards document */ printf( "Running SHS test 1 ... " ); shsInit( &shsInfo ); - shsUpdate( &shsInfo, ( BYTE * ) "abc", 3 ); + shsUpdate( &shsInfo, ( SHS_BYTE * ) "abc", 3 ); shsFinal( &shsInfo ); if( compareSHSresults( &shsInfo, 0 ) == -1 ) { @@ -85,7 +85,7 @@ main() printf( "Running SHS test 2 ... " ); shsInit( &shsInfo ); - shsUpdate( &shsInfo, ( BYTE * ) "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56 ); + shsUpdate( &shsInfo, ( SHS_BYTE * ) "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56 ); shsFinal( &shsInfo ); if( compareSHSresults( &shsInfo, 1 ) == -1 ) { @@ -102,7 +102,7 @@ main() printf( "Running SHS test 3 ... " ); shsInit( &shsInfo ); for( i = 0; i < 15625; i++ ) - shsUpdate( &shsInfo, ( BYTE * ) "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 64 ); + shsUpdate( &shsInfo, ( SHS_BYTE * ) "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 64 ); shsFinal( &shsInfo ); if( compareSHSresults( &shsInfo, 2 ) == -1 ) { diff --git a/src/lib/crypto/sha1/t_shs3.c b/src/lib/crypto/sha1/t_shs3.c new file mode 100644 index 0000000..1ba030d --- /dev/null +++ b/src/lib/crypto/sha1/t_shs3.c @@ -0,0 +1,583 @@ +/* test shs code */ + +#include +#include +#include +#include "shs.h" + +/* When run on a little-endian CPU we need to perform byte reversal on an + array of longwords. It is possible to make the code endianness- + independant by fiddling around with data at the byte level, but this + makes for very slow code, so we rely on the user to sort out endianness + at compile time */ + +void longReverse( SHS_LONG *buffer, int byteCount ) +{ + SHS_LONG value; + static int init = 0; + char *cp; + + switch (init) { + case 0: + init=1; + cp = (char *) &init; + if (*cp == 1) { + init=2; + break; + } + init=1; + /* fall through - MSB */ + case 1: + return; + } + + byteCount /= sizeof( SHS_LONG ); + while( byteCount-- ) { + value = *buffer; + value = ( ( value & 0xFF00FF00L ) >> 8 ) | + ( ( value & 0x00FF00FFL ) << 8 ); + *buffer++ = ( value << 16 ) | ( value >> 16 ); + } +} + +int rc; +int mode; +int Dflag; + +main(argc,argv) + char **argv; +{ + int f = 0; + char *argp; + + while (--argc > 0) if (*(argp = *++argv)=='-') + while (*++argp) switch(*argp) + { + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + if (mode) goto Usage; + mode = *argp; + break; + case 'D': + if (argc <= 1) goto Usage; + --argc; + Dflag = atoi(*++argv); + break; + case '-': + break; + default: + fprintf (stderr,"Bad switch char <%c>\n", *argp); + Usage: + fprintf(stderr, "Usage: t_shs [-1234567] [-D #]\n"); + exit(1); + } + else goto Usage; + + process(); + exit(rc); +} + +process() +{ + switch(mode) + { + case '1': + test1(); + break; + case '2': + test2(); + break; + case '3': + test3(); + break; + case '4': + test4(); + break; + case '5': + test5(); + break; + case '6': + test6(); + break; + case '7': + test7(); + break; + default: + test1(); + test2(); + test3(); + test4(); + test5(); + test6(); + test7(); + } +} + +#ifndef shsDigest +unsigned char * +shsDigest(si) + SHS_INFO *si; +{ + longReverse(si->digest, SHS_DIGESTSIZE); + return (unsigned char*) si->digest; +} +#endif + +unsigned char results1[SHS_DIGESTSIZE] = { +0xa9,0x99,0x3e,0x36,0x47,0x06,0x81,0x6a,0xba,0x3e, +0x25,0x71,0x78,0x50,0xc2,0x6c,0x9c,0xd0,0xd8,0x9d}; + +test1() +{ + SHS_INFO si[1]; + unsigned char digest[SHS_DIGESTSIZE]; + int failed; + int i; + + printf("Running SHS test 1 ...\n"); + shsInit(si); + shsUpdate(si, "abc", 3); + shsFinal(si); + memcpy(digest, shsDigest(si), SHS_DIGESTSIZE); + if (failed = memcmp(digest, results1, SHS_DIGESTSIZE)) + { + fprintf(stderr,"SHS test 1 failed!\n"); + rc = 1; + } + printf ("%s, results = ", failed ? "Failed" : "Passed"); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",digest[i]); + if (failed) + { + printf ("\n, expected "); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",results1[i]); + } + printf("\n"); +} + +unsigned char results2[SHS_DIGESTSIZE] = { +0x84,0x98,0x3e,0x44,0x1c,0x3b,0xd2,0x6e,0xba,0xae, +0x4a,0xa1,0xf9,0x51,0x29,0xe5,0xe5,0x46,0x70,0xf1}; + +test2() +{ + SHS_INFO si[1]; + unsigned char digest[SHS_DIGESTSIZE]; + int failed; + int i; + + printf("Running SHS test 2 ...\n"); + shsInit(si); + shsUpdate(si, +"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + 56); + shsFinal(si); + memcpy(digest, shsDigest(si), SHS_DIGESTSIZE); + if (failed = memcmp(digest, results2, SHS_DIGESTSIZE)) + { + fprintf(stderr,"SHS test 2 failed!\n"); + rc = 1; + } + printf ("%s, results = ", failed ? "Failed" : "Passed"); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",digest[i]); + if (failed) + { + printf ("\n, expected "); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",results2[i]); + } + printf("\n"); +} + +unsigned char results3[SHS_DIGESTSIZE] = { +0x34,0xaa,0x97,0x3c,0xd4,0xc4,0xda,0xa4,0xf6,0x1e, +0xeb,0x2b,0xdb,0xad,0x27,0x31,0x65,0x34,0x01,0x6f}; + +test3() +{ + SHS_INFO si[1]; + unsigned char digest[SHS_DIGESTSIZE]; + int failed; + int i; + + printf("Running SHS test 3 ...\n"); + shsInit(si); + for (i = 0; i < 15625; ++i) + shsUpdate(si, +"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + 64); + shsFinal(si); + memcpy(digest, shsDigest(si), SHS_DIGESTSIZE); + if (failed = memcmp(digest, results3, SHS_DIGESTSIZE)) + { + fprintf(stderr,"SHS test 3 failed!\n"); + rc = 1; + } + printf ("%s, results = ", failed ? "Failed" : "Passed"); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",digest[i]); + if (failed) + { + printf ("\n, expected "); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",results3[i]); + } + printf("\n"); +} + +unsigned char randdata[] = { +0xfe,0x28,0x79,0x25,0xf5,0x03,0xf9,0x1c,0xcd,0x70,0x7b,0xb0,0x42,0x02,0xb8,0x2f, +0xf3,0x63,0xa2,0x79,0x8e,0x9b,0x33,0xd7,0x2b,0xc4,0xb4,0xd2,0xcb,0x61,0xec,0xbb, +0x94,0xe1,0x8f,0x53,0x80,0x55,0xd9,0x90,0xb2,0x03,0x58,0xfa,0xa6,0xe5,0x18,0x57, +0x68,0x04,0x24,0x98,0x41,0x7e,0x84,0xeb,0xc1,0x39,0xbc,0x1d,0xf7,0x4e,0x92,0x72, +0x1a,0x5b,0xb6,0x99,0x43,0xa5,0x0a,0x45,0x73,0x55,0xfd,0x57,0x83,0x45,0x36,0x5c, +0xfd,0x39,0x08,0x6e,0xe2,0x01,0x9a,0x8c,0x4e,0x39,0xd2,0x0d,0x5f,0x0e,0x35,0x15, +0xb9,0xac,0x5f,0xa1,0x8a,0xe6,0xdd,0x6e,0x68,0x9d,0xf6,0x29,0x95,0xf6,0x7d,0x7b, +0xd9,0x5e,0xf4,0x67,0x25,0xbd,0xee,0xed,0x53,0x60,0xb0,0x47,0xdf,0xef,0xf4,0x41, +0xbd,0x45,0xcf,0x5c,0x93,0x41,0x87,0x97,0x82,0x39,0x20,0x66,0xb4,0xda,0xcb,0x66, +0x93,0x02,0x2e,0x7f,0x94,0x4c,0xc7,0x3b,0x2c,0xcf,0xf6,0x99,0x6f,0x13,0xf1,0xc5, +0x28,0x2b,0xa6,0x6c,0x39,0x26,0x7f,0x76,0x24,0x4a,0x6e,0x01,0x40,0x63,0xf8,0x00, +0x06,0x23,0x5a,0xaa,0xa6,0x2f,0xd1,0x37,0xc7,0xcc,0x76,0xe9,0x54,0x1e,0x57,0x73, +0xf5,0x33,0xaa,0x96,0xbe,0x35,0xcd,0x1d,0xd5,0x7d,0xac,0x50,0xd5,0xf8,0x47,0x2d, +0xd6,0x93,0x5f,0x6e,0x38,0xd3,0xac,0xd0,0x7e,0xad,0x9e,0xf8,0x87,0x95,0x63,0x15, +0x65,0xa3,0xd4,0xb3,0x9a,0x6c,0xac,0xcd,0x2a,0x54,0x83,0x13,0xc4,0xb4,0x94,0xfa, +0x76,0x87,0xc5,0x8b,0x4a,0x10,0x92,0x05,0xd1,0x0e,0x97,0xfd,0xc8,0xfb,0xc5,0xdc, +0x21,0x4c,0xc8,0x77,0x5c,0xed,0x32,0x22,0x77,0xc1,0x38,0x30,0xd7,0x8e,0x2a,0x70, +0x72,0x67,0x13,0xe4,0xb7,0x18,0xd4,0x76,0xdd,0x32,0x12,0xf4,0x5d,0xc9,0xec,0xc1, +0x2c,0x8a,0xfe,0x08,0x6c,0xea,0xf6,0xab,0x5a,0x0e,0x8e,0x81,0x1d,0xc8,0x5a,0x4b, +0xed,0xb9,0x7f,0x4b,0x67,0xe3,0x65,0x46,0xc9,0xf2,0xab,0x37,0x0a,0x98,0x67,0x5b, +0xb1,0x3b,0x02,0x91,0x38,0x71,0xea,0x62,0x88,0xae,0xb6,0xdb,0xfc,0x55,0x79,0x33, +0x69,0x95,0x51,0xb6,0xe1,0x3b,0xab,0x22,0x68,0x54,0xf9,0x89,0x9c,0x94,0xe0,0xe3, +0xd3,0x48,0x5c,0xe9,0x78,0x5b,0xb3,0x4b,0xba,0xd8,0x48,0xd8,0xaf,0x91,0x4e,0x23, +0x38,0x23,0x23,0x6c,0xdf,0x2e,0xf0,0xff,0xac,0x1d,0x2d,0x27,0x10,0x45,0xa3,0x2d, +0x8b,0x00,0xcd,0xe2,0xfc,0xb7,0xdb,0x52,0x13,0xb7,0x66,0x79,0xd9,0xd8,0x29,0x0e, +0x32,0xbd,0x52,0x6b,0x75,0x71,0x08,0x83,0x1b,0x67,0x28,0x93,0x97,0x97,0x32,0xff, +0x8b,0xd3,0x98,0xa3,0xce,0x2b,0x88,0x37,0x1c,0xcc,0xa0,0xd1,0x19,0x9b,0xe6,0x11, +0xfc,0xc0,0x3c,0x4e,0xe1,0x35,0x49,0x29,0x19,0xcf,0x1d,0xe1,0x60,0x74,0xc0,0xe9, +0xf7,0xb4,0x99,0xa0,0x23,0x50,0x51,0x78,0xcf,0xc0,0xe5,0xc2,0x1c,0x16,0xd2,0x24, +0x5a,0x63,0x54,0x83,0xaa,0x74,0x3d,0x41,0x0d,0x52,0xee,0xfe,0x0f,0x4d,0x13,0xe1, +0x27,0x00,0xc4,0xf3,0x2b,0x55,0xe0,0x9c,0x81,0xe0,0xfc,0xc2,0x13,0xd4,0x39,0x09 +}; + +unsigned char results4[SHS_DIGESTSIZE] = { +0x13,0x62,0xfc,0x87,0x68,0x33,0xd5,0x1d,0x2f,0x0c, +0x73,0xe3,0xfb,0x87,0x6a,0x6b,0xc3,0x25,0x54,0xfc}; + +test4() +{ + SHS_INFO si[1]; + unsigned char digest[SHS_DIGESTSIZE]; + int failed; + int i, j, k; + + printf("Running SHS test 4 ...\n"); + shsInit(si); + shsUpdate(si, randdata, 19); + shsFinal(si); + memcpy(digest, shsDigest(si), SHS_DIGESTSIZE); + if (failed = memcmp(digest, results4, SHS_DIGESTSIZE)) + { + fprintf(stderr,"SHS test 4 failed!\n"); + rc = 1; + } + printf ("%s, results = ", failed ? "Failed" : "Passed"); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",digest[i]); + if (failed) + { + printf ("\n, expected "); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",results4[i]); + } + printf("\n"); +} + +unsigned char results5[SHS_DIGESTSIZE] = { +0x19,0x4d,0xf6,0xeb,0x8e,0x02,0x6d,0x37,0x58,0x64, +0xe5,0x95,0x19,0x2a,0xdd,0x1c,0xc4,0x3c,0x24,0x86}; + +test5() +{ + SHS_INFO si[1]; + unsigned char digest[SHS_DIGESTSIZE]; + int failed; + int i, j, k; + + printf("Running SHS test 5 ...\n"); + shsInit(si); + shsUpdate(si, randdata, 19); + shsUpdate(si, randdata+32, 15); + shsFinal(si); + memcpy(digest, shsDigest(si), SHS_DIGESTSIZE); + if (failed = memcmp(digest, results5, SHS_DIGESTSIZE)) + { + fprintf(stderr,"SHS test 5 failed!\n"); + rc = 1; + } + printf ("%s, results = ", failed ? "Failed" : "Passed"); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",digest[i]); + if (failed) + { + printf ("\n, expected "); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",results5[i]); + } + printf("\n"); +} + +unsigned char results6[SHS_DIGESTSIZE] = { +0x4e,0x16,0x57,0x9d,0x4b,0x48,0xa9,0x1c,0x88,0x72, +0x83,0xdb,0x88,0xd1,0xea,0x3a,0x45,0xdf,0xa1,0x10}; + +test6() +{ + struct { + long pad1; + SHS_INFO si1; + long pad2; + SHS_INFO si2; + long pad3; + } sdata; + unsigned char digest[SHS_DIGESTSIZE]; + int failed; + int i, j, k; + + printf("Running SHS test 6 ...\n"); + sdata.pad1 = 0x12345678; + sdata.pad2 = 0x87654321; + sdata.pad3 = 0x78563412; + shsInit((&sdata.si2)); +if (sdata.pad2 != 0x87654321) { +printf ("Overrun #20 %#lx\n", +sdata.pad2); +sdata.pad2 = 0x87654321; +} +if (sdata.pad3 != 0x78563412) { +printf ("Overrun #21 %#lx\n", +sdata.pad3); +sdata.pad3 = 0x78563412; +} + for (i = 0; i < 400; ++i) + { + shsInit(&sdata.si1); +if (sdata.pad1 != 0x12345678) { +printf ("Overrun #22 %#lx at %d\n", +sdata.pad1, i); +sdata.pad1 = 0x12345678; +} +if (sdata.pad2 != 0x87654321) { +printf ("Overrun #23 %#lx at %d\n", +sdata.pad2, i); +sdata.pad2 = 0x87654321; +} + shsUpdate(&sdata.si1, (randdata+sizeof(randdata))-i, i); +if (sdata.pad1 != 0x12345678) { +printf ("Overrun #24 %#lx at %d\n", +sdata.pad1, i); +sdata.pad1 = 0x12345678; +} +if (sdata.pad2 != 0x87654321) { +printf ("Overrun #25 %#lx at %d\n", +sdata.pad2, i); +sdata.pad2 = 0x87654321; +} + shsFinal(&sdata.si1); +if (sdata.pad1 != 0x12345678) { +printf ("Overrun #26 %#lx at %d\n", +sdata.pad1, i); +sdata.pad1 = 0x12345678; +} +if (sdata.pad2 != 0x87654321) { +printf ("Overrun #27 %#lx at %d\n", +sdata.pad2, i); +sdata.pad2 = 0x87654321; +} + memcpy(digest, shsDigest(&sdata.si1), SHS_DIGESTSIZE); + if (Dflag & 1) + { + printf ("%d: ", i); + for (j = 0; j < SHS_DIGESTSIZE; ++j) + printf("%02x",digest[j]); + printf("\n"); + } + shsUpdate((&sdata.si2), digest, SHS_DIGESTSIZE); +if (sdata.pad2 != 0x87654321) { +printf ("Overrun #28 %#lx at %d\n", +sdata.pad2, i); +sdata.pad2 = 0x87654321; +} +if (sdata.pad3 != 0x78563412) { +printf ("Overrun #29 %#lx at %d\n", +sdata.pad3, i); +sdata.pad3 = 0x78563412; +} + if (Dflag & 2) + printf ("%d: %08lx%08lx%08lx%08lx%08lx\n", + i, + sdata.si2.digest[0], + sdata.si2.digest[1], + sdata.si2.digest[2], + sdata.si2.digest[3], + sdata.si2.digest[4]); + } + shsFinal((&sdata.si2)); +if (sdata.pad2 != 0x87654321) { +printf ("Overrun #30 %#lx\n", +sdata.pad2); +sdata.pad2 = 0x87654321; +} +if (sdata.pad3 != 0x78563412) { +printf ("Overrun #31 %#lx\n", +sdata.pad3); +sdata.pad3 = 0x78563412; +} + memcpy(digest, shsDigest((&sdata.si2)), SHS_DIGESTSIZE); + if (failed = memcmp(digest, results6, SHS_DIGESTSIZE)) + { + fprintf(stderr,"SHS test 6 failed!\n"); + rc = 1; + } + printf ("%s, results = ", failed ? "Failed" : "Passed"); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",digest[i]); + if (failed) + { + printf ("\n, expected "); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",results6[i]); + } + printf("\n"); +} + +unsigned char results7[SHS_DIGESTSIZE] = { +0x89,0x41,0x65,0xce,0x76,0xc1,0xd1,0xd1,0xc3,0x6f, +0xab,0x92,0x79,0x30,0x01,0x71,0x63,0x1f,0x74,0xfe}; + +int jfsize[] = {0,1,31,32, + 33,55,56,63, + 64,65,71,72, + 73,95,96,97, + 119,120,123,127}; +int kfsize[] = {0,1,31,32,33,55,56,63}; + +test7() +{ + struct { + long pad1; + SHS_INFO si1; + long pad2; + SHS_INFO si2; + long pad3; + } sdata; + unsigned char digest[SHS_DIGESTSIZE]; + int failed; + int i, j, k, l; + + printf("Running SHS test 7 ...\n"); + sdata.pad1 = 0x12345678; + sdata.pad2 = 0x87654321; + sdata.pad3 = 0x78563412; + shsInit((&sdata.si2)); + for (i = 1; i <= 128; ++i) + for (j = 0; j < 20; ++j) + for (k = 0; k < 8; ++k) + { + shsInit(&sdata.si1); + shsUpdate(&sdata.si1, (randdata+80+j), i); +if (sdata.pad1 != 0x12345678) { +printf ("Overrun #1 %#lx at %d,%d,%d\n", +sdata.pad1, i,j,k); +sdata.pad1 = 0x12345678; +} +if (sdata.pad2 != 0x87654321) { +printf ("Overrun #2 %#lx at %d,%d,%d\n", +sdata.pad2, i,j,k); +sdata.pad2 = 0x87654321; +} + shsUpdate(&sdata.si1, randdata+i, jfsize[j]); +if (sdata.pad1 != 0x12345678) { +printf ("Overrun #3 %#lx at %d,%d,%d\n", +sdata.pad1, i,j,k); +sdata.pad1 = 0x12345678; +} +if (sdata.pad2 != 0x87654321) { +printf ("Overrun #4 %#lx at %d,%d,%d\n", +sdata.pad2, i,j,k); +sdata.pad2 = 0x87654321; +} + if (k) shsUpdate(&sdata.si1, randdata+(i^j), kfsize[k]); +if (sdata.pad1 != 0x12345678) { +printf ("Overrun #5 %#lx at %d,%d,%d\n", +sdata.pad1, i,j,k); +sdata.pad1 = 0x12345678; +} +if (sdata.pad2 != 0x87654321) { +printf ("Overrun #6 %#lx at %d,%d,%d\n", +sdata.pad2, i,j,k); +sdata.pad2 = 0x87654321; +} + shsFinal(&sdata.si1); +if (sdata.pad1 != 0x12345678) { +printf ("Overrun #7 %#lx at %d,%d,%d\n", +sdata.pad1, i,j,k); +sdata.pad1 = 0x12345678; +} +if (sdata.pad2 != 0x87654321) { +printf ("Overrun #8 %#lx at %d,%d,%d\n", +sdata.pad2, i,j,k); +sdata.pad2 = 0x87654321; +} + memcpy(digest, shsDigest(&sdata.si1), SHS_DIGESTSIZE); + if (Dflag & 1) + { + printf ("%d,%d,%d: ", i, j, k); + for (l = 0; l < SHS_DIGESTSIZE; ++l) + printf("%02x",digest[l]); + printf("\n"); + } + shsUpdate((&sdata.si2), digest, SHS_DIGESTSIZE); +if (sdata.pad2 != 0x87654321) { +printf ("Overrun #9 %#lx at %d,%d,%d\n", +sdata.pad2, i,j,k); +sdata.pad2 = 0x87654321; +} +if (sdata.pad3 != 0x78563412) { +printf ("Overrun #10 %#lx at %d,%d,%d\n", +sdata.pad3, i,j,k); +sdata.pad3 = 0x78563412; +} + if (Dflag & 2) + printf ("%d,%d,%d: %08lx%08lx%08lx%08lx%08lx\n", + i,j,k, + sdata.si2.digest[0], + sdata.si2.digest[1], + sdata.si2.digest[2], + sdata.si2.digest[3], + sdata.si2.digest[4]); + } + shsFinal((&sdata.si2)); + memcpy(digest, shsDigest((&sdata.si2)), SHS_DIGESTSIZE); + if (failed = memcmp(digest, results7, SHS_DIGESTSIZE)) + { + fprintf(stderr,"SHS test 7 failed!\n"); + rc = 1; + } + printf ("%s, results = ", failed ? "Failed" : "Passed"); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",digest[i]); + if (failed) + { + printf ("\n, expected "); + for (i = 0; i < SHS_DIGESTSIZE; ++i) + printf("%02x",results7[i]); + } + printf("\n"); +} diff --git a/src/lib/crypto/valid_cksumtype.c b/src/lib/crypto/valid_cksumtype.c index 68000be..16efdc6 100644 --- a/src/lib/crypto/valid_cksumtype.c +++ b/src/lib/crypto/valid_cksumtype.c @@ -28,7 +28,7 @@ #include "cksumtypes.h" KRB5_DLLIMP krb5_boolean KRB5_CALLCONV -valid_cksumtype(ctype) +krb5_c_valid_cksumtype(ctype) krb5_cksumtype ctype; { int i; @@ -40,3 +40,9 @@ valid_cksumtype(ctype) return(0); } + +KRB5_DLLIMP krb5_boolean KRB5_CALLCONV +valid_cksumtype(krb5_cksumtype ctype) +{ + return krb5_c_valid_cksumtype (ctype); +} diff --git a/src/lib/crypto/valid_enctype.c b/src/lib/crypto/valid_enctype.c index 39e48c0..ce955d8 100644 --- a/src/lib/crypto/valid_enctype.c +++ b/src/lib/crypto/valid_enctype.c @@ -28,7 +28,7 @@ #include "etypes.h" KRB5_DLLIMP krb5_boolean KRB5_CALLCONV -valid_enctype(etype) +krb5_c_valid_enctype(etype) krb5_enctype etype; { int i; @@ -40,3 +40,9 @@ valid_enctype(etype) return(0); } + +KRB5_DLLIMP krb5_boolean KRB5_CALLCONV +valid_enctype(krb5_enctype etype) +{ + return krb5_c_valid_enctype (etype); +} diff --git a/src/lib/gssapi/ChangeLog b/src/lib/gssapi/ChangeLog index 1e0213f..37b9d26 100644 --- a/src/lib/gssapi/ChangeLog +++ b/src/lib/gssapi/ChangeLog @@ -1,3 +1,16 @@ +2002-05-22 Alexandra Ellwood + * gss_libinit.c: Conditionalized error table loading for + Mac OS X. Error tables should always be loaded on other + platforms. + +2002-03-03 Alexandra Ellwood + * gss_libinit.c: updated for Mac OS X header paths and added + include of gssapiP_krb5.h to get function prototypes. + +2000-06-03 Tom Yu + + * Makefile.in(LIBMINOR): Bump library version. + Tue Feb 22 10:23:19 2000 Ezra Peisach * Makefile.in (clean-unix): Add clean-libobjs. diff --git a/src/lib/gssapi/Makefile.in b/src/lib/gssapi/Makefile.in index bee2b85..20936da 100644 --- a/src/lib/gssapi/Makefile.in +++ b/src/lib/gssapi/Makefile.in @@ -24,7 +24,7 @@ SRCS=\ LIB=gssapi_krb5 LIBMAJOR=2 -LIBMINOR=1 +LIBMINOR=2 STOBJLISTS=OBJS.ST generic/OBJS.ST krb5/OBJS.ST SHLIB_EXPDEPS=\ $(TOPLIBD)/libkrb5$(SHLIBEXT) \ diff --git a/src/lib/gssapi/generic/ChangeLog b/src/lib/gssapi/generic/ChangeLog index 234c953..1bbf501 100644 --- a/src/lib/gssapi/generic/ChangeLog +++ b/src/lib/gssapi/generic/ChangeLog @@ -1,3 +1,50 @@ +2002-05-05 Alexandra Ellwood + * gssapi_generic.h: allow inclusion by C++ + +2002-03-28 Alexandra Ellwood + * gssapi.hin: Conditionalized pragmas for Metrowerks + +2002-03-07 Alexandra Ellwood + * gssapi.hin: Added check for CFM compiles. Removed dependency on + PRAGMA_* macros. Moved check struct alignment check before struct declarations. + +2002-03-03 Alexandra Ellwood + * disp_com_err_status.c: Updated Mac OS X headers to new + framework layout... this time for real. + +2002-02-28 Alexandra Ellwood + * disp_com_err_status.c, gssapi.hin, gssapi_generic.h: + Updated Mac OS X headers to new framework layout + +2000-11-19 Alexandra Ellwood + * gssapi_generic.h: Fixed check for Mac OS X includes. + +2001-10-29 Miro Jurisic + * pullup from krb5-1-2 branch after krb5-1-2-2-bp + * gssapi.hin, gssapi_generic.h, gssapi_generic.c: + added oids from rfc 2744. Kept old oids for compatibility. + * gssapi.hin: Changed KerberosConditionalMacros.h to + KerberosSupport.h. + * gssapi.hin: Fixed Mac OS preprocessor test + * gssapi_generic.h: corrected Mac OS include to + * gssapiP_generic.h: use "" include for krb5.h + * disp_com_err_status.c, gssapi.hin: Updated Mac OS #defines + and #includes for new header layout and Mac OS X frameworks + * gssapi_generic.h: Added check for Mac OS X includes. This will + not break autoconf-style builds because they do not include + ConditionalMacros.h. + +2001-10-20 Ken Raeburn + + * gssapiP_generic.h (g_*): For every g_ function declared here, + first define the name as a macro using a gssint_ prefix to avoid + conflicting with glib function names. + +2000-09-11 Alexandra Ellwood + * gssapi_generic.h: Added check for Mac OS X includes. This will + not break autoconf-style builds because they do not include + ConditionalMacros.h. + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/lib/gssapi/generic/disp_com_err_status.c b/src/lib/gssapi/generic/disp_com_err_status.c index c4db913..71c7505 100644 --- a/src/lib/gssapi/generic/disp_com_err_status.c +++ b/src/lib/gssapi/generic/disp_com_err_status.c @@ -25,7 +25,12 @@ */ #include "gssapiP_generic.h" + +#if TARGET_OS_MAC +#include +#else #include "com_err.h" +#endif /* XXXX internationalization!! */ diff --git a/src/lib/gssapi/generic/gssapi.hin b/src/lib/gssapi/generic/gssapi.hin index f6a0f57..05edd74 100644 --- a/src/lib/gssapi/generic/gssapi.hin +++ b/src/lib/gssapi/generic/gssapi.hin @@ -27,13 +27,33 @@ * Determine platform-dependent configuration. */ -#if defined(_MSDOS) || defined(_WIN32) || defined(macintosh) -#include +#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__)) + #include + #if TARGET_RT_MAC_CFM + #error "Use KfM 4.0 SDK headers for CFM compilation." + #endif + + /* This is an API divergence in 1.2.3. This will be reconciled in 1.3, when + all platforms will have RFC-compliant OID declarations. */ + #define GSS_RFC_COMPLIANT_OIDS 1 +#else + #define GSS_RFC_COMPLIANT_OIDS 0 +#endif -/* Macintoh CFM-68K magic incantation */ -#if defined(macintosh) && defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__) -#pragma import on +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#if TARGET_OS_MAC + #if defined(__MWERKS__) + #pragma import on + #pragma enumsalwaysint on + #endif + #pragma options align=mac68k #endif + +#if defined(_MSDOS) || defined(_WIN32) +#include #endif #ifndef KRB5_CALLCONV @@ -327,9 +347,106 @@ typedef int gss_cred_usage_t; * Finally, function prototypes for the GSSAPI routines. */ -#ifdef __cplusplus -extern "C" { -#endif +/* RFC-compliant GSS_oids will be present on all platforms in 1.3 */ +#if GSS_RFC_COMPLIANT_OIDS + +/* Reserved static storage for GSS_oids. Comments are quotes from RFC 2744. + * + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) user_name(1)}. The constant + * GSS_C_NT_USER_NAME should be initialized to point + * to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_USER_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) machine_uid_name(2)}. + * The constant GSS_C_NT_MACHINE_UID_NAME should be + * initialized to point to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_MACHINE_UID_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x03"}, + * corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) string_uid_name(3)}. + * The constant GSS_C_NT_STRING_UID_NAME should be + * initialized to point to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_STRING_UID_NAME; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\x01\x05\x06\x02"}, + * corresponding to an object-identifier value of + * {iso(1) org(3) dod(6) internet(1) security(5) + * nametypes(6) gss-host-based-services(2)). The constant + * GSS_C_NT_HOSTBASED_SERVICE_X should be initialized to point + * to that gss_OID_desc. This is a deprecated OID value, and + * implementations wishing to support hostbased-service names + * should instead use the GSS_C_NT_HOSTBASED_SERVICE OID, + * defined below, to identify such names; + * GSS_C_NT_HOSTBASED_SERVICE_X should be accepted a synonym + * for GSS_C_NT_HOSTBASED_SERVICE when presented as an input + * parameter, but should not be emitted by GSS-API + * implementations + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_HOSTBASED_SERVICE_X; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {10, (void *)"\x2a\x86\x48\x86\xf7\x12" + * "\x01\x02\x01\x04"}, corresponding to an + * object-identifier value of {iso(1) member-body(2) + * Unites States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) service_name(4)}. The constant + * GSS_C_NT_HOSTBASED_SERVICE should be initialized + * to point to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_HOSTBASED_SERVICE; + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\01\x05\x06\x03"}, + * corresponding to an object identifier value of + * {1(iso), 3(org), 6(dod), 1(internet), 5(security), + * 6(nametypes), 3(gss-anonymous-name)}. The constant + * and GSS_C_NT_ANONYMOUS should be initialized to point + * to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_ANONYMOUS; + + +/* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value + * {6, (void *)"\x2b\x06\x01\x05\x06\x04"}, + * corresponding to an object-identifier value of + * {1(iso), 3(org), 6(dod), 1(internet), 5(security), + * 6(nametypes), 4(gss-api-exported-name)}. The constant + * GSS_C_NT_EXPORT_NAME should be initialized to point + * to that gss_OID_desc. + */ +GSS_DLLIMP extern gss_OID GSS_C_NT_EXPORT_NAME; + +#endif /* GSS_RFC_COMPLIANT_OIDS */ + +/* Function Prototypes */ GSS_DLLIMP OM_uint32 KRB5_CALLCONV gss_acquire_cred PROTOTYPE( (OM_uint32 FAR *, /* minor_status */ @@ -684,9 +801,17 @@ PROTOTYPE( (OM_uint32 *, /* minor_status */ gss_name_t * /* output_name */ )); +#if TARGET_OS_MAC + #if defined(__MWERKS__) + #pragma enumsalwaysint reset + #pragma import reset + #endif + #pragma options align=reset +#endif + #ifdef __cplusplus } -#endif +#endif /* __cplusplus */ /* XXXX these are not part of the GSSAPI C bindings! (but should be) */ @@ -700,9 +825,4 @@ PROTOTYPE( (OM_uint32 *, /* minor_status */ /* XXXX This is a necessary evil until the spec is fixed */ #define GSS_S_CRED_UNAVAIL GSS_S_FAILURE -/* Macintoh CFM-68K magic incantation */ -#if defined(macintosh) && defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__) -#pragma import reset -#endif - #endif /* _GSSAPI_H_ */ diff --git a/src/lib/gssapi/generic/gssapiP_generic.h b/src/lib/gssapi/generic/gssapiP_generic.h index a0fa7c4..3f7fd75 100644 --- a/src/lib/gssapi/generic/gssapiP_generic.h +++ b/src/lib/gssapi/generic/gssapiP_generic.h @@ -28,7 +28,7 @@ */ #if (defined(_MSDOS) || defined(_WIN32) || defined(macintosh)) -#include +#include "k5-int.h" #else #ifdef HAVE_STDLIB_H #include @@ -97,6 +97,38 @@ /** helper functions **/ +/* hide names from applications, especially glib applications */ +#define g_set_init gssint_g_set_init +#define g_set_destroy gssint_g_set_destroy +#define g_set_entry_add gssint_g_set_entry_add +#define g_set_entry_delete gssint_g_set_entry_delete +#define g_set_entry_get gssint_g_set_entry_get +#define g_save_name gssint_g_save_name +#define g_save_cred_id gssint_g_save_cred_id +#define g_save_ctx_id gssint_g_save_ctx_id +#define g_validate_name gssint_g_validate_name +#define g_validate_cred_id gssint_g_validate_cred_id +#define g_validate_ctx_id gssint_g_validate_ctx_id +#define g_delete_name gssint_g_delete_name +#define g_delete_cred_id gssint_g_delete_cred_id +#define g_delete_ctx_id gssint_g_delete_ctx_id +#define g_make_string_buffer gssint_g_make_string_buffer +#define g_copy_OID_set gssint_g_copy_OID_set +#define g_token_size gssint_g_token_size +#define g_make_token_header gssint_g_make_token_header +#define g_verify_token_header gssint_g_verify_token_header +#define g_display_major_status gssint_g_display_major_status +#define g_display_com_err_status gssint_g_display_com_err_status +#define g_order_init gssint_g_order_init +#define g_order_check gssint_g_order_check +#define g_order_free gssint_g_order_free +#define g_queue_size gssint_g_queue_size +#define g_queue_externalize gssint_g_queue_externalize +#define g_queue_internalize gssint_g_queue_internalize +#define g_canonicalize_host gssint_g_canonicalize_host +#define g_local_host_name gssint_g_local_host_name +#define g_strdup gssint_g_strdup + typedef struct _g_set *g_set; int g_set_init PROTOTYPE((g_set *s)); diff --git a/src/lib/gssapi/generic/gssapi_generic.c b/src/lib/gssapi/generic/gssapi_generic.c index 10cc4d7..ea7cb82 100644 --- a/src/lib/gssapi/generic/gssapi_generic.c +++ b/src/lib/gssapi/generic/gssapi_generic.c @@ -53,17 +53,111 @@ */ static gss_OID_desc oids[] = { - {10, "\052\206\110\206\367\022\001\002\001\001"}, - {10, "\052\206\110\206\367\022\001\002\001\002"}, - {10, "\052\206\110\206\367\022\001\002\001\003"}, - {10, "\052\206\110\206\367\022\001\002\001\004"}, - { 6, "\053\006\001\005\006\004"}, - { 6, "\053\006\001\005\006\002"}, + /* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value */ + {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x01"}, + /* corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) user_name(1)}. The constant + * GSS_C_NT_USER_NAME should be initialized to point + * to that gss_OID_desc. + */ + + /* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value */ + {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x02"}, + /* corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) machine_uid_name(2)}. + * The constant GSS_C_NT_MACHINE_UID_NAME should be + * initialized to point to that gss_OID_desc. + */ + + /* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value */ + {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x03"}, + /* corresponding to an object-identifier value of + * {iso(1) member-body(2) United States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) string_uid_name(3)}. + * The constant GSS_C_NT_STRING_UID_NAME should be + * initialized to point to that gss_OID_desc. + */ + + /* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value */ + {6, (void *)"\x2b\x06\x01\x05\x06\x02"}, + /* corresponding to an object-identifier value of + * {iso(1) org(3) dod(6) internet(1) security(5) + * nametypes(6) gss-host-based-services(2)). The constant + * GSS_C_NT_HOSTBASED_SERVICE_X should be initialized to point + * to that gss_OID_desc. This is a deprecated OID value, and + * implementations wishing to support hostbased-service names + * should instead use the GSS_C_NT_HOSTBASED_SERVICE OID, + * defined below, to identify such names; + * GSS_C_NT_HOSTBASED_SERVICE_X should be accepted a synonym + * for GSS_C_NT_HOSTBASED_SERVICE when presented as an input + * parameter, but should not be emitted by GSS-API + * implementations + */ + + /* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value */ + {10, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x01\x04"}, + /* corresponding to an object-identifier value of + * {iso(1) member-body(2) Unites States(840) mit(113554) + * infosys(1) gssapi(2) generic(1) service_name(4)}. + * The constant GSS_C_NT_HOSTBASED_SERVICE should be + * initialized to point to that gss_OID_desc. + */ + + /* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value */ + {6, (void *)"\x2b\x06\01\x05\x06\x03"}, + /* corresponding to an object identifier value of + * {1(iso), 3(org), 6(dod), 1(internet), 5(security), + * 6(nametypes), 3(gss-anonymous-name)}. The constant + * and GSS_C_NT_ANONYMOUS should be initialized to point + * to that gss_OID_desc. + */ + + /* + * The implementation must reserve static storage for a + * gss_OID_desc object containing the value */ + {6, (void *)"\x2b\x06\x01\x05\x06\x04"}, + /* corresponding to an object-identifier value of + * {1(iso), 3(org), 6(dod), 1(internet), 5(security), + * 6(nametypes), 4(gss-api-exported-name)}. The constant + * GSS_C_NT_EXPORT_NAME should be initialized to point + * to that gss_OID_desc. + */ }; -GSS_DLLIMP gss_OID gss_nt_user_name = oids+0; -GSS_DLLIMP gss_OID gss_nt_machine_uid_name = oids+1; -GSS_DLLIMP gss_OID gss_nt_string_uid_name = oids+2; -GSS_DLLIMP gss_OID gss_nt_service_name = oids+3; -GSS_DLLIMP gss_OID gss_nt_exported_name = oids+4; -GSS_DLLIMP gss_OID gss_nt_service_name_v2 = oids+5; +/* Here are the constants which point to the static structure above. + * + * Constants of the form GSS_C_NT_* are specified by rfc 2744. + * + * Constants of the form gss_nt_* are the original MIT krb5 names + * found in gssapi_generic.h. They are provided for compatibility. */ + +#if GSS_RFC_COMPLIANT_OIDS +GSS_DLLIMP gss_OID GSS_C_NT_USER_NAME = oids+0; +GSS_DLLIMP gss_OID GSS_C_NT_MACHINE_UID_NAME = oids+1; +GSS_DLLIMP gss_OID GSS_C_NT_STRING_UID_NAME = oids+2; +GSS_DLLIMP gss_OID GSS_C_NT_HOSTBASED_SERVICE_X = oids+3; +GSS_DLLIMP gss_OID GSS_C_NT_HOSTBASED_SERVICE = oids+4; +GSS_DLLIMP gss_OID GSS_C_NT_ANONYMOUS = oids+5; +GSS_DLLIMP gss_OID GSS_C_NT_EXPORT_NAME = oids+6; +#endif /* GSS_RFC_COMPLIANT_OIDS */ + +GSS_DLLIMP gss_OID gss_nt_user_name = oids+0; +GSS_DLLIMP gss_OID gss_nt_machine_uid_name = oids+1; +GSS_DLLIMP gss_OID gss_nt_string_uid_name = oids+2; +GSS_DLLIMP gss_OID gss_nt_service_name_v2 = oids+3; +GSS_DLLIMP gss_OID gss_nt_service_name = oids+4; +GSS_DLLIMP gss_OID gss_nt_exported_name = oids+6; diff --git a/src/lib/gssapi/generic/gssapi_generic.h b/src/lib/gssapi/generic/gssapi_generic.h index 8317cad..337558a 100644 --- a/src/lib/gssapi/generic/gssapi_generic.h +++ b/src/lib/gssapi/generic/gssapi_generic.h @@ -27,17 +27,33 @@ * $Id$ */ -#if defined(__MWERKS__) || defined(applec) || defined(THINK_C) -#include +#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__)) +#include #else #include #endif +#if defined(__cplusplus) && !defined(GSSAPIGENERIC_BEGIN_DECLS) +#define GSSAPIGENERIC_BEGIN_DECLS extern "C" { +#define GSSAPIGENERIC_END_DECLS } +#else +#define GSSAPIGENERIC_BEGIN_DECLS +#define GSSAPIGENERIC_END_DECLS +#endif + +GSSAPIGENERIC_BEGIN_DECLS + +/* Deprecated MIT krb5 oid names provided for compatibility. + * The correct oids (GSS_C_NT_USER_NAME, etc) from rfc 2744 + * are defined in gssapi.h. */ + GSS_DLLIMP extern gss_OID gss_nt_user_name; GSS_DLLIMP extern gss_OID gss_nt_machine_uid_name; GSS_DLLIMP extern gss_OID gss_nt_string_uid_name; +GSS_DLLIMP extern gss_OID gss_nt_service_name_v2; GSS_DLLIMP extern gss_OID gss_nt_service_name; GSS_DLLIMP extern gss_OID gss_nt_exported_name; -GSS_DLLIMP extern gss_OID gss_nt_service_name_v2; + +GSSAPIGENERIC_END_DECLS #endif /* _GSSAPI_GENERIC_H_ */ diff --git a/src/lib/gssapi/gss_libinit.c b/src/lib/gssapi/gss_libinit.c index e011ebd..3c57203 100644 --- a/src/lib/gssapi/gss_libinit.c +++ b/src/lib/gssapi/gss_libinit.c @@ -1,5 +1,11 @@ #include +#if TARGET_OS_MAC +// Mac OS X com_err files do not include com_err for you +#include +#endif + +#include "gssapiP_krb5.h" #include "gssapi_err_generic.h" #include "gssapi_err_krb5.h" @@ -15,8 +21,10 @@ OM_uint32 gssint_initialize_library (void) { if (!initialized) { +#if !TARGET_OS_MAC || USE_HARDCODED_FALLBACK_ERROR_TABLES add_error_table(&et_k5g_error_table); add_error_table(&et_ggss_error_table); +#endif initialized = 1; } diff --git a/src/lib/gssapi/krb5/3des.txt b/src/lib/gssapi/krb5/3des.txt new file mode 100644 index 0000000..f39c6fc --- /dev/null +++ b/src/lib/gssapi/krb5/3des.txt @@ -0,0 +1,274 @@ +CAT Working Group K. Raeburn +Internet-draft MIT +Category: June xx, 2000 +Updates: RFC 1964 +Document: draft-raeburn-gssapi-krb5-3des-XX.txt + + Triple-DES Support for the Kerberos 5 GSSAPI Mechanism + +Status of this Memo + + This document is an Internet-Draft and is in full conformance with + all provisions of Section 10 of RFC2026 [1]. Internet-Drafts are + working documents of the Internet Engineering Task Force (IETF), + its areas, and its working groups. Note that other groups may also + distribute working documents as Internet-Drafts. Internet-Drafts + are draft documents valid for a maximum of six months and may be + updated, replaced, or obsoleted by other documents at any time. It + is inappropriate to use Internet-Drafts as reference material or to + cite them other than as "work in progress." + + The list of current Internet-Drafts can be accessed at + http://www.ietf.org/ietf/1id-abstracts.txt + + The list of Internet-Draft Shadow Directories can be accessed at + http://www.ietf.org/shadow.html. + +1. Abstract + + The MIT Kerberos 5 release version 1.2 includes support for + triple-DES with key derivation [KrbRev]. Recent work by the EFF + [EFF] has demonstrated the vulnerability of single-DES mechanisms + to brute-force attacks by sufficiently motivated and well-funded + parties. + + The GSSAPI Kerberos 5 mechanism definition [GSSAPI-KRB5] + specifically enumerates encryption and checksum types, + independently of how such schemes may be used in Kerberos. In the + long run, a new Kerberos-based mechanism, which does not require + separately enumerating for the GSSAPI mechanism each of the various + encryption types defined by Kerberos, is a better approach. + Efforts to produce such a specification are under way. + + In the interest of providing increased security in the near term, + however, MIT is adding support for triple-DES to the existing + mechanism implementation we ship, as described here. + +2. New Algorithm Identifiers + + One new sealing algorithm is defined, for use in WRAP tokens: + + 02 00 - DES3-KD + + This algorithm uses triple-DES with key derivation, with a usage + value KG_USAGE_SEAL. Padding is still to 8-byte multiples, and the + IV for encrypting application data is zero. + + One new signing algorithm is defined, for use in MIC, Wrap, and + Delete tokens: + + 04 00 - HMAC SHA1 DES3-KD + + This algorithm generates an HMAC using SHA-1 and a derived DES3 key + with usage KG_USAGE_SIGN, as (should be described) in [KrbRev]. + [XXX: The current [KrbRev] description refers to out-of-date I-Ds + from Marc Horowitz. The text in [KrbRev] may be inadequate to + produce an interoperable implementation.] + + The checksum size for this algorithm is 20 octets. See section 4.3 + below for the use of checksum lengths of other than eight bytes. + +3. Key Derivation + + For purposes of key derivation, we add three new usage values to the + list defined in [KrbRev]; one for signing messages, one for + sealing messages, and one for encrypting sequence numbers: + + #define KG_USAGE_SEAL 22 + #define KG_USAGE_SIGN 23 + #define KG_USAGE_SEQ 24 + +4. Adjustments to Previous Definitions + +4.1. Quality of Protection + + The GSSAPI specification [GSSAPI] says that a zero QOP value + indicates the "default". The original specification for the + Kerberos 5 mechanism says that a zero QOP value (or a QOP value + with the appropriate bits clear) means DES encryption. + + Rather than continue to force the use of plain DES when the + application doesn't use mechanism-specific QOP values, the better + choice appears to be to redefine the DES QOP value as some non-zero + value, and define a triple-DES value as well. Then a zero value + continues to imply the default, which would be triple-DES + protection when given a triple-DES session key. + + Our values are: + + GSS_KRB5_INTEG_C_QOP_HMAC_SHA1 0x0004 + /* SHA-1 checksum encrypted with key derivation */ + + GSS_KRB5_CONF_C_QOP_DES 0x0100 + /* plain DES encryption */ + GSS_KRB5_CONF_C_QOP_DES3_KD 0x0200 + /* triple-DES with key derivation */ + + Rather than open the question of whether to specify means for + deriving a key of one type given a key of another type, and the + security implications of whether to generate a long key from a + shorter one, our implementation will simply return an error if the + QOP value specified does not correspond to the session key type. + + [XXX: Not implemented yet. Currently an error is reported for all + non-zero values. This should be changed before the release, so an + application can insist on getting no less than triple-DES + protection.] + +4.2. MIC Sequence Number Encryption + + The sequence numbers are encrypted in the context key (as defined + in [GSSAPI-KRB5] -- this will be either the Kerberos session key or + asubkey provided by the context initiator), using whatever + encryption system is designated by the type of that context key. + The IV is formed from the first N bytes of the SGN_CKSUM field, + where N is the number of bytes needed for the IV. (With all + algorithms described here and in [GSSAPI-KRB5], the checksum is at + least as large as the IV.) + +4.3. Message Layout + + Both MIC and Wrap tokens, as defined in [GSSAPI-KRB5], contain an + checksum field SGN_CKSUM. In [GSSAPI-KRB5], this field was + specified as being 8 bytes long. We now change this size to be + "defined by the checksum algorithm", and retroactively amend the + descriptions of all the checksum algorithms described in + [GSSAPI-KRB5] to explicitly specify 8-byte output. Application + data continues to immediately follow the checksum field in the Wrap + token. + + The revised message descriptions are thus: + + MIC: + + Byte no Name Description + 0..1 TOK_ID Identification field. + 2..3 SGN_ALG Integrity algorithm indicator. + 4..7 Filler Contains ff ff ff ff + 8..15 SND_SEQ Sequence number field. + 16..s+15 SGN_CKSUM Checksum of "to-be-signed data", + calculated according to algorithm + specified in SGN_ALG field. + + Wrap: + + Byte no Name Description + 0..1 TOK_ID Identification field. + Tokens emitted by GSS_Wrap() contain + the hex value 02 01 in this field. + 2..3 SGN_ALG Checksum algorithm indicator. + 4..5 SEAL_ALG Sealing algorithm indicator. + 6..7 Filler Contains ff ff + 8..15 SND_SEQ Encrypted sequence number field. + 16..s+15 SGN_CKSUM Checksum of plaintext padded data, + calculated according to algorithm + specified in SGN_ALG field. + s+16..last Data encrypted or plaintext padded data + + Where "s" indicates the size of the checksum. + + As indicated above in section 2, we define the HMAC SHA1 DES3-KD + checksum algorithm to produce a 20-byte output, so encrypted data + begins at byte 36. + +5. Backwards Compatibility Considerations + + The context initiator should request of the KDC credentials using + session-key cryptosystem types supported by that implementation; if + the only types returned by the KDC are not supported by the + mechanism implementation, it should indicate a failure. This may + seem obvious, but early implementations of both Kerberos and the + GSSAPI Kerberos mechanism supported only DES keys, so the + cryptosystem compatibility question was easy to overlook. + + Under the current mechanism, no negotiation of algorithm types + occurs, so server-side (acceptor) implementations cannot request + that clients not use algorithm types not understood by the server. + However, administration of the server's Kerberos data has to be + done in communication with the KDC, and it is from the KDC that the + client will request credentials. The KDC could therefore be tasked + with limiting session keys for a given service to types actually + supported by the Kerberos and GSSAPI software on the server. + + This does have a drawback for cases where a service principal name + is used both for GSSAPI-based and non-GSSAPI-based communication, + if the GSSAPI implementation does not understand triple-DES but the + Kerberos implementation does. It means that triple-DES session + keys cannot be issued for that service principal, which keeps the + protection of non-GSSAPI services weaker than necessary. However, + in the most recent MIT releases thus far, while triple-DES support + has been present, it has required additional work to enable, so it + should not be in use for many services. + + It would also be possible to have clients attempt to get single-DES + session keys before trying to get triple-DES session keys, and have + the KDC refuse to issue the single-DES keys only for the most + critical of services, for which single-DES protection is considered + inadequate. However, that would eliminate the possibility of + connecting with the more secure cryptosystem to any service that + can be accessed with the weaker cryptosystem. + + We have chosen to go with the former approach, putting the burden + on the KDC administration and gaining the best protection possible + for GSSAPI services, possibly at the cost of protection of + non-GSSAPI Kerberos services running earlier versions of the + software. + [XXX: Actually, we haven't entirely decided and cast it in stone + yet, it's just what I've implemented; it's easy to change.] + +6. Security Considerations + + Various tradeoffs arise regarding the mixing of new and old + software, or GSSAPI-based and non-GSSAPI Kerberos authentication. + They are discussed in section 4. + +7. References + + [EFF] Electronic Frontier Foundation, "Cracking DES: Secrets of + Encryption Research, Wiretap Politics, and Chip Design", O'Reilly & + Associates, Inc., May, 1998. + + [GSSAPI] Linn, J., "Generic Security Service Application Program + Interface Version 2, Update 1", RFC 2743, January, 2000. + + [GSSAPI-KRB5] Linn, J., "The Kerberos Version 5 GSS-API Mechanism", + RFC 1964, June, 1996. + + [KrbRev] Neuman, C., Kohl, J., Ts'o, T., "The Kerberos Network + Authentication Service (V5)", + draft-ietf-cat-kerberos-revisions-05.txt, March 10, 2000. + +8. Author's Address + + Kenneth Raeburn + Massachusetts Institute of Technology + 77 Massachusetts Avenue + Cambridge, MA 02139 + +9. Full Copyright Statement + + Copyright (C) The Internet Society (2000). All Rights Reserved. + + This document and translations of it may be copied and furnished to + others, and derivative works that comment on or otherwise explain it + or assist in its implementation may be prepared, copied, published + and distributed, in whole or in part, without restriction of any + kind, provided that the above copyright notice and this paragraph + are included on all such copies and derivative works. However, this + document itself may not be modified in any way, such as by removing + the copyright notice or references to the Internet Society or other + Internet organizations, except as needed for the purpose of + developing Internet standards in which case the procedures for + copyrights defined in the Internet Standards process must be + followed, or as required to translate it into languages other than + English. + + The limited permissions granted above are perpetual and will not be + revoked by the Internet Society or its successors or assigns. + + This document and the information contained herein is provided on an + "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING + TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING + BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION + HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF + MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE." diff --git a/src/lib/gssapi/krb5/ChangeLog b/src/lib/gssapi/krb5/ChangeLog index 06639d4..3803df1 100644 --- a/src/lib/gssapi/krb5/ChangeLog +++ b/src/lib/gssapi/krb5/ChangeLog @@ -1,4 +1,195 @@ -2000-01-27 Ken Raeburn +2002-04-16 Danilo Almeida + + * accept_sec_context.c (rd_and_store_for_creds): Remove + registration of MEMORY cache type since that's already registered. + +2002-04-16 Alexandra Ellwood + * gssapi_krb5.h: Added #include of gssapi.h and gssapi_generic.h for the + Mac because we can't assume people will include them and get the OID + macro and the old names on the Mac. + +2002-03-03 Sam Hartman + + * accept_sec_context.c (rd_and_store_for_creds): Patch from Steven + Michaud to accept encrypted or + unencrypted credentials. This is important because Heimdal (and + sometimes Microsoft) send encrypted credentials. + +2002-03-03 Alexandra Ellwood + * accept_sec_context.c, ser_sctx.c, util_crypt.c, wrap_size_limit.c: + Removed unused variables. + * acquire_cred.c: Added include of k5-int.h to get prototypes. + * disp_status.c: Updated Mac OS X header paths. + * gssapi_krb5.c: Added include of k5-int.h to get prototypes. + * gssapiP_krb5.h: Updated Mac OS X header paths and added prototype on Mac. + * init_sec_context.c: Removed unused function on the mac to avoid warning. + +2002-02-28 Alexandra Ellwood + * gssapi_krb5.h: Updated Mac OS X headers to new framework layout + +2002-02-19 Danilo Almeida + + * init_sec_context.c (krb5_gss_init_sec_context): Remove unsused + variables. Fix fencepost error in loop that prevents duplicates + while trying to figure out the desired enctype. Make the loop + structure in a little more readable. + (get_credentials): Remove unused variable. + +2001-12-07 Ken Raeburn + + * init_sec_context.c (krb5_gss_init_sec_context): When supplying a + list of enctypes to use, use the subset and ordering indicated by + krb5.conf. + +2001-10-29 Miro Jurisic + * pullup from krb5-1-2 branch after krb5-1-2-2-bp + * add_cred.c (krb5_gss_add_cred): Added constness to some char*s to make + them compiler with strict compilers. + * gssapi_krb5.h, gssapi_krb5.c: Added oids from rfc 1964 using the + suggested names. + * gssapi_krb5.h: Added #include of KerberosSupport.h in case this header + is included by itself. + * disp-status.c, gssapiP_krb5.h, gssapi_krb5.h: Updated Mac OS #defines + and #includes for new header layout and Mac OS X frameworks + +2001-10-04 Tom Yu + + * accept_sec_context.c (krb5_gss_accept_sec_context): Ignore + unrecognized options properly. [krb5-libs/738] + +2001-10-01 Tom Yu + + * accept_sec_context.c (rd_and_store_for_creds): Handle error + returns from krb5_rd_cred more sanely. + +2001-01-30 Ezra Peisach + + * accept_sec_context.c (krb5_gss_accept_sec_context): If an error + occurs after the auth_context is established, but before the + krb5_gss_ctx_id_rec is established, release our pointer to the + replay cache and invoke krb5_auth_con_free(). [krb5-libs/855] + +2000-09-19 Miro Jurisic + + * accept_sec_context.c (krb5_gss_accept_sec_context) + * acquire_cred.c (krb5_gss_acquire_cred) + * import_sec_context.c (krb5_gss_convert_static_mech_oid) + * init_sec_context.c (krb5_gss_init_sec_context) + * inq_cred.c (krb5_gss_inquire_cred) + Cast away constness from gss_OID where necessary to compile + with strict compilers + +2000-06-27 Tom Yu + + * init_sec_context.c (get_credentials): Add initial iteration of + krb5_get_credentials in order to differentiate between an actual + missing credential and merely a bad match based on enctype. This + was causing problems with kadmin. + +2000-06-09 Tom Yu + + * init_sec_context.c (get_credentials): The KDC as well as the + ccache may indicate that an enctype is not supported; reflect that + in the loop breakout condition. + +2000-06-07 Tom Yu + + * init_sec_context.c (get_credentials): Rework the enctype loop + again. + + * accept_sec_context.c (krb5_gss_accept_sec_context): Remove + explicit check of mech OID against credential. + +2000-06-04 Tom Yu + + * init_sec_context.c (get_credentials): Reverse sense of test; + break out of enctype loop if one succeeds. + +2000-06-03 Tom Yu + + * util_crypt.c (kg_encrypt): Copy ivec, since c_encrypt() now + updates ivecs. + (kg_decrypt): Copy ivec, since c_decrypt() now updates ivecs. + +2000-06-02 Ken Raeburn + + * init_sec_context.c (get_credentials): Don't check each enctype + against a list from the krb5 library; instead, just try to use it, + and go on to the next if the error code indicates we can't use it. + +2000-05-31 Ken Raeburn + + * gssapiP_krb5.h (KG_USAGE_SEQ): New value. + (enum qop): New type, derived from spec but currently not used. + * util_crypt.c (kg_encrypt, kg_decrypt): Added key derivation + usage value as an argument. Prototypes and callers updated; all + callers use KG_USAGE_SEAL, except KG_USAGE_SEQ when encrypting + sequence numbers. + * 3des.txt: New file. + +2000-5-19 Alexandra Ellwood + + * acquire_cred.c: Changed to use krb5int_cc_default. This function + supports the Kerberos Login Library and pops up a dialog if the cache does + not contain valid tickets. This is used to automatically get a tgt before + obtaining service tickets. Note that this should be an internal function + because callers don't expect krb5_cc_default to pop up a dialog! + (We found this out the hard way :-) + +2000-05-03 Nalin Dahyabhai + + * add_cred.c (krb5_gss_add_cred): Don't overflow buffers "ktboth" + or "ccboth". + +2000-04-21 Ken Raeburn + + * gssapiP_krb5.h (struct _krb5_gss_ctx_id_rec): Delete field + gsskrb5_version. + (struct _krb5_gss_cred_id_rec): Delete field rfcv2_mech. + * accept_sec_context.c, acquire_cred.c, add_cred.c, inq_cred.c, + k5seal.c, k5unseal.c, ser_ctx.c: + Delete krb5-mech2 support. + + * init_sec_context.c (get_credentials): Enctype argument is now a + pointer to a list of enctypes. Explicitly try each in order until + success or an error other than cryptosystem not being supported. + (krb5_gss_init_sec_context): Pass list of cryptosystems, starting + with 3DES. + + * gssapiP_krb5.h (enum sgn_alg, enum seal_alg): New types, + giving symbolic names for values from RFC 1964, a Microsoft win2k + I-D, and our proposed 3des-sha1 values. + (KG_USAGE_SEAL, KG_USAGE_SIGN): New macros. + + * accept_sec_context.c (rd_req_keyproc): Already-disabled routine + deleted. + (krb5_gss_accept_sec_context): Use sgn_alg and seal_alg symbolic + names. Add a case for des3-hmac-sha1. + * k5seal.c (make_seal_token_v1): Likewise. Do key derivation for + checksums. + * k5unseal.c (kg_unseal_v1): Likewise. + * util_crypt.c (kg_encrypt, kg_decrypt): Do key derivation for + encryption. + + * util_crypt.c (zeros): Unused variable deleted. + +2000-04-18 Ken Raeburn + + * wrap_size_limit.c: Remove mech2 support. Add MIT copyright. + +2000-04-08 Tom Yu + + * wrap_size_limit.c (krb5_gss_wrap_size_limit): Fix up + wrap_size_limit() to deal with integrity wrap tokens properly. + The rfc1964 mech always pads and confounds regardless of whether + confidentiality is requested. + +2000-03-20 Ken Raeburn + + * accept_sec_context.c, init_sec_context.c: Disable krb5-mech2 + stuff for now. (Tom Yu's krb5-1.1 patch.) + +2000-01-27 Ken Raeburn * init_sec_context.c (krb5_gss_init_sec_context): Default to des-cbc-crc. diff --git a/src/lib/gssapi/krb5/accept_sec_context.c b/src/lib/gssapi/krb5/accept_sec_context.c index fc920ec..c8e7916 100644 --- a/src/lib/gssapi/krb5/accept_sec_context.c +++ b/src/lib/gssapi/krb5/accept_sec_context.c @@ -1,4 +1,28 @@ /* + * Copyright 2000 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. + * + */ +/* * Copyright 1993 by OpenVision Technologies, Inc. * * Permission to use, copy, modify, distribute, and sell this software @@ -49,65 +73,61 @@ #include "k5-int.h" #include "gssapiP_krb5.h" #include +#include /* * $Id$ */ -#if 0 - -/* XXXX This widen/narrow stuff is bletcherous, but it seems to be - necessary. Perhaps there is a "better" way, but I don't know what it - is */ - -#include -static krb5_error_code -rd_req_keyproc(krb5_pointer keyprocarg, krb5_principal server, - krb5_kvno kvno, krb5_keyblock **keyblock) -#include -{ - krb5_error_code code; - krb5_keytab_entry ktentry; - - if (code = krb5_kt_get_entry((krb5_keytab) keyprocarg, server, kvno, - &ktentry)) - return(code); - - code = krb5_copy_keyblock(&ktentry.key, keyblock); - - (void) krb5_kt_free_entry(&ktentry); - - return(code); -} - -#endif - /* Decode, decrypt and store the forwarded creds in the local ccache. */ static krb5_error_code -rd_and_store_for_creds(context, inbuf, out_cred) +rd_and_store_for_creds(context, auth_context, inbuf, out_cred) krb5_context context; + krb5_auth_context auth_context; krb5_data *inbuf; krb5_gss_cred_id_t *out_cred; { - krb5_creds ** creds; + krb5_creds ** creds = NULL; krb5_error_code retval; - krb5_ccache ccache; + krb5_ccache ccache = NULL; krb5_gss_cred_id_t cred = NULL; - extern krb5_cc_ops krb5_mcc_ops; - krb5_auth_context auth_context = NULL; - - if ((retval = krb5_auth_con_init(context, &auth_context))) - return(retval); - - krb5_auth_con_setflags(context, auth_context, 0); - - if ((retval = krb5_rd_cred(context, auth_context, inbuf, &creds, NULL))) - goto cleanup; + krb5_auth_context new_auth_ctx = NULL; + krb5_int32 flags_org; + + if (retval = krb5_auth_con_getflags(context, auth_context, &flags_org)) + return retval; + krb5_auth_con_setflags(context, auth_context, 0); + + /* By the time krb5_rd_cred is called here (after krb5_rd_req has been */ + /* called in krb5_gss_accept_sec_context), the "keyblock" field of */ + /* auth_context contains a pointer to the session key, and the */ + /* "remote_subkey" field might contain a session subkey. Either of */ + /* these (the "remote_subkey" if it isn't NULL, otherwise the */ + /* "keyblock") might have been used to encrypt the encrypted part of */ + /* the KRB_CRED message that contains the forwarded credentials. (The */ + /* Java Crypto and Security Implementation from the DSTC in Australia */ + /* always uses the session key. But apparently it never negotiates a */ + /* subkey, so this code works fine against a JCSI client.) Up to the */ + /* present, though, GSSAPI clients linked against the MIT code (which */ + /* is almost all GSSAPI clients) don't encrypt the KRB_CRED message at */ + /* all -- at this level. So if the first call to krb5_rd_cred fails, */ + /* we should call it a second time with another auth context freshly */ + /* created by krb5_auth_con_init. All of its keyblock fields will be */ + /* NULL, so krb5_rd_cred will assume that the KRB_CRED message is */ + /* unencrypted. (The MIT code doesn't actually send the KRB_CRED */ + /* message in the clear -- the "authenticator" whose "checksum" ends up */ + /* containing the KRB_CRED message does get encrypted.) */ + if (krb5_rd_cred(context, auth_context, inbuf, &creds, NULL)) { + if (retval = krb5_auth_con_init(context, &new_auth_ctx)) + goto cleanup; + krb5_auth_con_setflags(context, new_auth_ctx, 0); + if (retval = krb5_rd_cred(context, new_auth_ctx, inbuf, &creds, NULL)) + goto cleanup; + } /* Lots of kludging going on here... Some day the ccache interface will be rewritten though */ - krb5_cc_register(context, &krb5_mcc_ops, 0); if ((retval = krb5_cc_resolve(context, "MEMORY:GSSAPI", &ccache))) goto cleanup; @@ -145,7 +165,6 @@ rd_and_store_for_creds(context, inbuf, out_cred) /* cred->princ already set */ cred->prerfc_mech = 1; /* this cred will work with all three mechs */ cred->rfc_mech = 1; - cred->rfcv2_mech = 1; cred->keytab = NULL; /* no keytab associated with this... */ cred->ccache = ccache; /* but there is a credential cache */ cred->tgt_expire = creds[0]->times.endtime; /* store the end time */ @@ -157,7 +176,8 @@ rd_and_store_for_creds(context, inbuf, out_cred) goto cleanup; */ cleanup: - krb5_free_tgt_creds(context, creds); + if (creds) + krb5_free_tgt_creds(context, creds); if (!cred && ccache) (void)krb5_cc_close(context, ccache); @@ -165,8 +185,10 @@ cleanup: if (out_cred) *out_cred = cred; /* return credential */ - if (auth_context) - krb5_auth_con_free(context, auth_context); + if (new_auth_ctx) + krb5_auth_con_free(context, new_auth_ctx); + + krb5_auth_con_setflags(context, auth_context, flags_org); return retval; } @@ -206,9 +228,6 @@ krb5_gss_accept_sec_context(minor_status, context_handle, krb5_ui_4 gss_flags = 0; int decode_req_message = 0; krb5_gss_ctx_id_rec *ctx = 0; -#if 0 - krb5_enctype enctype; -#endif krb5_timestamp now; gss_buffer_desc token; krb5_auth_context auth_context = NULL; @@ -221,11 +240,7 @@ krb5_gss_accept_sec_context(minor_status, context_handle, krb5_data scratch; gss_cred_id_t cred_handle = NULL; krb5_gss_cred_id_t deleg_cred = NULL; - int token_length; - int gsskrb5_vers; - int nctypes; krb5_cksumtype *ctypes = 0; - struct kg2_option fwcred; if (GSS_ERROR(kg_get_context(minor_status, &context))) return(GSS_S_FAILURE); @@ -296,13 +311,7 @@ krb5_gss_accept_sec_context(minor_status, context_handle, &(ap_req.length), &ptr, KG_TOK_CTX_AP_REQ, input_token->length))) { - if (! cred->rfc_mech) { - code = G_WRONG_MECH; - major_status = GSS_S_DEFECTIVE_TOKEN; - goto fail; - } mech_used = gss_mech_krb5; - gsskrb5_vers = 1000; } else if ((code == G_WRONG_MECH) && !(code = g_verify_token_header((gss_OID) gss_mech_krb5_old, &(ap_req.length), @@ -315,56 +324,15 @@ krb5_gss_accept_sec_context(minor_status, context_handle, * compatibility, and use it to decide when to use the * old behavior. */ - if (! cred->prerfc_mech) { - code = G_WRONG_MECH; - major_status = GSS_S_DEFECTIVE_TOKEN; - goto fail; - } mech_used = gss_mech_krb5_old; - gsskrb5_vers = 1000; - } else if ((code == G_WRONG_MECH) && - !(code = g_verify_token_header((gss_OID) gss_mech_krb5_v2, - &token_length, - &ptr, KG2_TOK_INITIAL, - input_token->length))) { - if (! cred->rfcv2_mech) { - code = G_WRONG_MECH; - major_status = GSS_S_DEFECTIVE_TOKEN; - goto fail; - } - mech_used = gss_mech_krb5_v2; - gsskrb5_vers = 2000; } else { major_status = GSS_S_DEFECTIVE_TOKEN; goto fail; } - if (gsskrb5_vers == 2000) { - /* gss krb5 v2 */ - - fwcred.option_id = KRB5_GSS_FOR_CREDS_OPTION; - fwcred.data = NULL; - - if (GSS_ERROR(major_status = - kg2_parse_token(&code, ptr, token_length, - &gss_flags, &nctypes, &ctypes, - delegated_cred_handle?1:0, - &fwcred, &ap_req, NULL))) { - goto fail; - } - - gss_flags = (ptr[0]<<24) | (ptr[1]<<16) | (ptr[2]<<8) | ptr[3]; - - gss_flags &= ~GSS_C_DELEG_FLAG; /* mask out the delegation flag; - if there's a delegation, we'll - set it below */ - } else { - /* gss krb5 v1 */ - - sptr = (char *) ptr; - TREAD_STR(sptr, ap_req.data, ap_req.length); - decode_req_message = 1; - } + sptr = (char *) ptr; + TREAD_STR(sptr, ap_req.data, ap_req.length); + decode_req_message = 1; /* construct the sender_addr */ @@ -416,9 +384,7 @@ krb5_gss_accept_sec_context(minor_status, context_handle, } #endif - if (gsskrb5_vers == 2000) { - bigend = 1; - } else { + { /* gss krb5 v1 */ /* stash this now, for later. */ @@ -480,12 +446,16 @@ krb5_gss_accept_sec_context(minor_status, context_handle, goto fail; } - TREAD_STR(ptr, ptr2, reqcksum.length); - if (memcmp(ptr2, reqcksum.contents, reqcksum.length) != 0) { - code = 0; - major_status = GSS_S_BAD_BINDINGS; - goto fail; - } + TREAD_STR(ptr, ptr2, reqcksum.length); + /* If server has chosen not to use channel bindings, ignore */ + /* any channel bindings sent by the client. */ + if (input_chan_bindings != GSS_C_NO_CHANNEL_BINDINGS) { + if (memcmp(ptr2, reqcksum.contents, reqcksum.length) != 0) { + code = 0; + major_status = GSS_S_BAD_BINDINGS; + goto fail; + } + } xfree(reqcksum.contents); reqcksum.contents = 0; @@ -502,33 +472,41 @@ krb5_gss_accept_sec_context(minor_status, context_handle, i = authdat->checksum->length - 24; - while(i>0) { + while (i >= 4) { TREAD_INT16(ptr, option_id, bigend); - switch(option_id) { + TREAD_INT16(ptr, option.length, bigend); - case KRB5_GSS_FOR_CREDS_OPTION: + i -= 4; - TREAD_INT16(ptr, option.length, bigend); + /* have to use ptr2, since option.data is wrong type and + macro uses ptr as both lvalue and rvalue */ - /* have to use ptr2, since option.data is wrong type and - macro uses ptr as both lvalue and rvalue */ + if (i < option.length || option.length < 0) { + code = KG_BAD_LENGTH; + major_status = GSS_S_FAILURE; + goto fail; + } + + TREAD_STR(ptr, ptr2, bigend); + option.data = (char FAR *) ptr2; + + i -= option.length; + + switch(option_id) { - TREAD_STR(ptr, ptr2, bigend); - option.data = (char FAR *) ptr2; + case KRB5_GSS_FOR_CREDS_OPTION: /* store the delegated credential */ - if (code = rd_and_store_for_creds(context, &option, + if (code = rd_and_store_for_creds(context, auth_context, &option, (delegated_cred_handle) ? &deleg_cred : NULL)) { major_status = GSS_S_FAILURE; goto fail; } - i -= option.length + 4; - gss_flags |= GSS_C_DELEG_FLAG; /* got a delegation */ break; @@ -551,13 +529,12 @@ krb5_gss_accept_sec_context(minor_status, context_handle, } memset(ctx, 0, sizeof(krb5_gss_ctx_id_rec)); - ctx->mech_used = mech_used; + ctx->mech_used = (gss_OID) mech_used; ctx->auth_context = auth_context; ctx->initiate = 0; ctx->gss_flags = KG_IMPLFLAGS(gss_flags); ctx->seed_init = 0; ctx->big_endian = bigend; - ctx->gsskrb5_version = gsskrb5_vers; /* Intern the ctx pointer so that delete_sec_context works */ if (! kg_save_ctx_id((gss_ctx_id_t) ctx)) { @@ -603,114 +580,37 @@ krb5_gss_accept_sec_context(minor_status, context_handle, goto fail; } - if (gsskrb5_vers == 2000) { - int cblen; - krb5_boolean valid; - - /* intersect the token ctypes with the local ctypes */ - - if (code = krb5_c_keyed_checksum_types(context, ctx->subkey->enctype, - &ctx->nctypes, &ctx->ctypes)) - goto fail; - - if (nctypes == 0) { - code = KRB5_CRYPTO_INTERNAL; - goto fail; - } - - kg2_intersect_ctypes(&ctx->nctypes, ctx->ctypes, nctypes, ctypes); - - if (nctypes == 0) { - code = KG_NO_CTYPES; - goto fail; - } - - /* process the delegated cred, if any */ - - if (fwcred.data) { - krb5_data option; - - option.length = fwcred.length; - option.data = fwcred.data; - - if (code = rd_and_store_for_creds(context, &option, &deleg_cred)) { - major_status = GSS_S_FAILURE; - goto fail; - } - - gss_flags |= GSS_C_DELEG_FLAG; /* got a delegation */ - } - - /* construct the checksum buffer */ - - cblen = 4*5; - if (input_chan_bindings) - cblen += (input_chan_bindings->initiator_address.length+ - input_chan_bindings->acceptor_address.length+ - input_chan_bindings->application_data.length); + switch(ctx->subkey->enctype) { + case ENCTYPE_DES_CBC_MD5: + case ENCTYPE_DES_CBC_CRC: + ctx->subkey->enctype = ENCTYPE_DES_CBC_RAW; + ctx->signalg = SGN_ALG_DES_MAC_MD5; + ctx->cksum_size = 8; + ctx->sealalg = SEAL_ALG_DES; - cksumdata.length = cblen + ((char *)(ap_req.data-2) - (char *)(ptr-2)); + /* fill in the encryption descriptors */ - if ((cksumdata.data = (char *) malloc(cksumdata.length)) == NULL) { - code = ENOMEM; + if ((code = krb5_copy_keyblock(context, ctx->subkey, &ctx->enc))) { major_status = GSS_S_FAILURE; goto fail; } - ptr2 = cksumdata.data; - - if (input_chan_bindings) { - TWRITE_INT(ptr2, input_chan_bindings->initiator_addrtype, 1); - TWRITE_BUF(ptr2, input_chan_bindings->initiator_address, 1); - TWRITE_INT(ptr2, input_chan_bindings->acceptor_addrtype, 1); - TWRITE_BUF(ptr2, input_chan_bindings->acceptor_address, 1); - TWRITE_BUF(ptr2, input_chan_bindings->application_data, 1); - } else { - memset(ptr2, 0, cblen); - ptr2 += cblen; - } - - memcpy(ptr2, ptr-2, ((char *)(ap_req.data-2) - (char *)(ptr-2))); + for (i=0; ienc->length; i++) + /*SUPPRESS 113*/ + ctx->enc->contents[i] ^= 0xf0; - if (code = krb5_c_verify_checksum(context, ctx->subkey, - KRB5_KEYUSAGE_AP_REQ_AUTH_CKSUM, - &cksumdata, authdat->checksum, - &valid)) { + if ((code = krb5_copy_keyblock(context, ctx->subkey, &ctx->seq))) { major_status = GSS_S_FAILURE; goto fail; } - free(cksumdata.data); - cksumdata.data = 0; + break; - if (!valid) { - code = 0; - major_status = GSS_S_BAD_SIG; - goto fail; - } - } else { - /* gss krb5 v1 */ - - switch(ctx->subkey->enctype) { - case ENCTYPE_DES_CBC_MD5: - case ENCTYPE_DES_CBC_CRC: - ctx->subkey->enctype = ENCTYPE_DES_CBC_RAW; - ctx->signalg = 0; - ctx->cksum_size = 8; - ctx->sealalg = 0; - break; -#if 0 - case ENCTYPE_DES3_CBC_MD5: - enctype = ENCTYPE_DES3_CBC_RAW; - ctx->signalg = 3; - ctx->cksum_size = 16; - ctx->sealalg = 1; - break; -#endif - default: - code = KRB5_BAD_ENCTYPE; - goto fail; - } + case ENCTYPE_DES3_CBC_SHA1: + ctx->subkey->enctype = ENCTYPE_DES3_CBC_RAW; + ctx->signalg = SGN_ALG_HMAC_SHA1_DES3_KD; + ctx->cksum_size = 20; + ctx->sealalg = SEAL_ALG_DES3KD; /* fill in the encryption descriptors */ @@ -719,14 +619,16 @@ krb5_gss_accept_sec_context(minor_status, context_handle, goto fail; } - for (i=0; ienc->length; i++) - /*SUPPRESS 113*/ - ctx->enc->contents[i] ^= 0xf0; - if ((code = krb5_copy_keyblock(context, ctx->subkey, &ctx->seq))) { major_status = GSS_S_FAILURE; goto fail; } + + break; + + default: + code = KRB5_BAD_ENCTYPE; + goto fail; } ctx->endtime = ticket->enc_part2->times.endtime; @@ -769,122 +671,22 @@ krb5_gss_accept_sec_context(minor_status, context_handle, /* the reply token hasn't been sent yet, but that's ok. */ ctx->established = 1; - if (ctx->gsskrb5_version == 2000) { - krb5_ui_4 tok_flags; - - tok_flags = - (ctx->gss_flags & GSS_C_DELEG_FLAG)?KG2_RESP_FLAG_DELEG_OK:0; - - cksumdata.length = 8 + 4*ctx->nctypes + 4; - - if ((cksumdata.data = (char *) malloc(cksumdata.length)) == NULL) { - code = ENOMEM; - major_status = GSS_S_FAILURE; - goto fail; - } - - /* construct the token fields */ - - ptr = cksumdata.data; - - ptr[0] = (KG2_TOK_RESPONSE >> 8) & 0xff; - ptr[1] = KG2_TOK_RESPONSE & 0xff; - - ptr[2] = (tok_flags >> 24) & 0xff; - ptr[3] = (tok_flags >> 16) & 0xff; - ptr[4] = (tok_flags >> 8) & 0xff; - ptr[5] = tok_flags & 0xff; - - ptr[6] = (ctx->nctypes >> 8) & 0xff; - ptr[7] = ctx->nctypes & 0xff; - - ptr += 8; - - for (i=0; inctypes; i++) { - ptr[i] = (ctx->ctypes[i] >> 24) & 0xff; - ptr[i+1] = (ctx->ctypes[i] >> 16) & 0xff; - ptr[i+2] = (ctx->ctypes[i] >> 8) & 0xff; - ptr[i+3] = ctx->ctypes[i] & 0xff; - - ptr += 4; - } - - memset(ptr, 0, 4); - - /* make the MIC token */ - - { - gss_buffer_desc text, token; - - text.length = cksumdata.length; - text.value = cksumdata.data; - - /* ctx->seq_send must be set before this call */ - - if (GSS_ERROR(major_status = - krb5_gss_get_mic(&code, ctx, - GSS_C_QOP_DEFAULT, - &text, &token))) - goto fail; - - mic.length = token.length; - mic.data = token.value; - } - - token.length = g_token_size((gss_OID) mech_used, - (cksumdata.length-2)+4+ap_rep.length+ - mic.length); - - if ((token.value = (unsigned char *) xmalloc(token.length)) - == NULL) { - code = ENOMEM; - major_status = GSS_S_FAILURE; - goto fail; - } - ptr = token.value; - g_make_token_header((gss_OID) mech_used, - (cksumdata.length-2)+4+ap_rep.length+mic.length, - &ptr, KG2_TOK_RESPONSE); - - memcpy(ptr, cksumdata.data+2, cksumdata.length-2); - ptr += cksumdata.length-2; - - ptr[0] = (ap_rep.length >> 8) & 0xff; - ptr[1] = ap_rep.length & 0xff; - memcpy(ptr+2, ap_rep.data, ap_rep.length); - - ptr += (2+ap_rep.length); - - ptr[0] = (mic.length >> 8) & 0xff; - ptr[1] = mic.length & 0xff; - memcpy(ptr+2, mic.data, mic.length); - - ptr += (2+mic.length); - - free(cksumdata.data); - cksumdata.data = 0; + token.length = g_token_size((gss_OID) mech_used, ap_rep.length); - /* gss krb5 v2 */ - } else { - /* gss krb5 v1 */ - - token.length = g_token_size((gss_OID) mech_used, ap_rep.length); - - if ((token.value = (unsigned char *) xmalloc(token.length)) - == NULL) { - major_status = GSS_S_FAILURE; - code = ENOMEM; - goto fail; - } - ptr = token.value; - g_make_token_header((gss_OID) mech_used, ap_rep.length, - &ptr, KG_TOK_CTX_AP_REP); + if ((token.value = (unsigned char *) xmalloc(token.length)) + == NULL) { + major_status = GSS_S_FAILURE; + code = ENOMEM; + goto fail; + } + ptr = token.value; + g_make_token_header((gss_OID) mech_used, ap_rep.length, + &ptr, KG_TOK_CTX_AP_REP); - TWRITE_STR(ptr, ap_rep.data, ap_rep.length); + TWRITE_STR(ptr, ap_rep.data, ap_rep.length); - ctx->established = 1; + ctx->established = 1; - } } else { token.length = 0; token.value = NULL; @@ -943,6 +745,11 @@ krb5_gss_accept_sec_context(minor_status, context_handle, free(ctypes); if (authdat) krb5_free_authenticator(context, authdat); + /* The ctx structure has the handle of the auth_context */ + if (auth_context && !ctx) { + (void)krb5_auth_con_setrcache(context, auth_context, NULL); + krb5_auth_con_free(context, auth_context); + } if (reqcksum.contents) xfree(reqcksum.contents); if (ap_rep.data) @@ -1014,13 +821,8 @@ krb5_gss_accept_sec_context(minor_status, context_handle, if (code) return (major_status); - if (gsskrb5_vers == 2000) { - tmsglen = 12+scratch.length; - toktype = KG2_TOK_RESPONSE; - } else { - tmsglen = scratch.length; - toktype = KG_TOK_CTX_ERROR; - } + tmsglen = scratch.length; + toktype = KG_TOK_CTX_ERROR; token.length = g_token_size((gss_OID) mech_used, tmsglen); token.value = (unsigned char *) xmalloc(token.length); @@ -1030,24 +832,6 @@ krb5_gss_accept_sec_context(minor_status, context_handle, ptr = token.value; g_make_token_header((gss_OID) mech_used, tmsglen, &ptr, toktype); - if (gsskrb5_vers == 2000) { - krb5_ui_4 flags; - - flags = KG2_RESP_FLAG_ERROR; - - ptr[0] = (flags << 24) & 0xff; - ptr[1] = (flags << 16) & 0xff; - ptr[2] = (flags << 8) & 0xff; - ptr[3] = flags & 0xff; - - memset(ptr+4, 0, 6); - - ptr[10] = (scratch.length << 8) & 0xff; - ptr[11] = scratch.length & 0xff; - - ptr += 12; - } - TWRITE_STR(ptr, scratch.data, scratch.length); xfree(scratch.data); diff --git a/src/lib/gssapi/krb5/acquire_cred.c b/src/lib/gssapi/krb5/acquire_cred.c index b67eb4f..0cdff4a 100644 --- a/src/lib/gssapi/krb5/acquire_cred.c +++ b/src/lib/gssapi/krb5/acquire_cred.c @@ -1,4 +1,28 @@ /* + * Copyright 2000 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. + * + */ +/* * Copyright 1993 by OpenVision Technologies, Inc. * * Permission to use, copy, modify, distribute, and sell this software @@ -47,6 +71,7 @@ */ #include "gssapiP_krb5.h" +#include "k5-int.h" #ifdef HAVE_STRING_H #include #else @@ -154,7 +179,7 @@ acquire_init_cred(context, minor_status, desired_name, output_princ, cred) /* open the default credential cache */ - if ((code = krb5_cc_default(context, &ccache))) { + if ((code = krb5int_cc_default(context, &ccache))) { *minor_status = code; return(GSS_S_CRED_UNAVAIL); } @@ -283,7 +308,7 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req, size_t i; krb5_gss_cred_id_t cred; gss_OID_set ret_mechs; - int req_old, req_new, req_v2; + int req_old, req_new; OM_uint32 ret; krb5_error_code code; @@ -313,22 +338,18 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req, if (desired_mechs == GSS_C_NULL_OID_SET) { req_old = 1; req_new = 1; - req_v2 = 1; } else { req_old = 0; req_new = 0; - req_v2 = 0; for (i=0; icount; i++) { if (g_OID_equal(gss_mech_krb5_old, &(desired_mechs->elements[i]))) req_old++; if (g_OID_equal(gss_mech_krb5, &(desired_mechs->elements[i]))) req_new++; - if (g_OID_equal(gss_mech_krb5_v2, &(desired_mechs->elements[i]))) - req_v2++; } - if (!req_old && !req_new && !req_v2) { + if (!req_old && !req_new) { *minor_status = 0; return(GSS_S_BAD_MECH); } @@ -347,7 +368,6 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req, cred->princ = NULL; cred->prerfc_mech = req_old; cred->rfc_mech = req_new; - cred->rfcv2_mech = req_v2; cred->keytab = NULL; cred->ccache = NULL; @@ -442,15 +462,11 @@ krb5_gss_acquire_cred(minor_status, desired_name, time_req, &ret_mechs)) || (cred->prerfc_mech && GSS_ERROR(ret = generic_gss_add_oid_set_member(minor_status, - gss_mech_krb5_old, + (gss_OID) gss_mech_krb5_old, &ret_mechs))) || (cred->rfc_mech && GSS_ERROR(ret = generic_gss_add_oid_set_member(minor_status, - gss_mech_krb5, - &ret_mechs))) || - (cred->rfcv2_mech && - GSS_ERROR(ret = generic_gss_add_oid_set_member(minor_status, - gss_mech_krb5_v2, + (gss_OID) gss_mech_krb5, &ret_mechs)))) { if (cred->ccache) (void)krb5_cc_close(context, cred->ccache); diff --git a/src/lib/gssapi/krb5/add_cred.c b/src/lib/gssapi/krb5/add_cred.c index 2a6fdb4..a13ba52 100644 --- a/src/lib/gssapi/krb5/add_cred.c +++ b/src/lib/gssapi/krb5/add_cred.c @@ -1,4 +1,28 @@ /* + * Copyright 2000 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. + * + */ +/* * Copyright (C) 1998 by the FundsXpress, INC. * * All rights reserved. @@ -110,8 +134,7 @@ krb5_gss_add_cred(minor_status, input_cred_handle, /* check that desired_mech isn't already in the credential */ if ((g_OID_equal(desired_mech, gss_mech_krb5_old) && cred->prerfc_mech) || - (g_OID_equal(desired_mech, gss_mech_krb5) && cred->rfc_mech) || - (g_OID_equal(desired_mech, gss_mech_krb5_v2) && cred->rfcv2_mech)) { + (g_OID_equal(desired_mech, gss_mech_krb5) && cred->rfc_mech)) { *minor_status = 0; return(GSS_S_DUPLICATE_ELEMENT); } @@ -143,7 +166,9 @@ krb5_gss_add_cred(minor_status, input_cred_handle, /* make a copy */ krb5_gss_cred_id_t new_cred; char *kttype, ktboth[1024]; - char *cctype, *ccname, ccboth[1024]; + char ccboth[1024]; + const char *ccname; + const char *cctype; if ((new_cred = (krb5_gss_cred_id_t) xmalloc(sizeof(krb5_gss_cred_id_rec))) @@ -156,7 +181,6 @@ krb5_gss_add_cred(minor_status, input_cred_handle, new_cred->usage = cred_usage; new_cred->prerfc_mech = cred->prerfc_mech; new_cred->rfc_mech = cred->rfc_mech; - new_cred->rfcv2_mech = cred->rfcv2_mech; new_cred->tgt_expire = cred->tgt_expire; if (code = krb5_copy_principal(context, cred->princ, @@ -177,8 +201,9 @@ krb5_gss_add_cred(minor_status, input_cred_handle, return(GSS_S_FAILURE); } - strcpy(ktboth, kttype); - strcat(ktboth, ":"); + strncpy(ktboth, kttype, sizeof(ktboth) - 1); + ktboth[sizeof(ktboth) - 1] = '\0'; + strncat(ktboth, ":", sizeof(ktboth) - 1 - strlen(ktboth)); if (code = krb5_kt_get_name(context, cred->keytab, ktboth+strlen(ktboth), @@ -234,9 +259,10 @@ krb5_gss_add_cred(minor_status, input_cred_handle, return(GSS_S_FAILURE); } - strcpy(ccboth, cctype); - strcat(ccboth, ":"); - strcat(ccboth, ccname); + strncpy(ccboth, cctype, sizeof(ccboth) - 1); + ccboth[sizeof(ccboth) - 1] = '\0'; + strncat(ccboth, ":", sizeof(ccboth) - 1 - strlen(ccboth)); + strncat(ccboth, ccname, sizeof(ccboth) - 1 - strlen(ccboth)); if (code = krb5_cc_resolve(context, ccboth, &new_cred->ccache)) { if (new_cred->rcache) @@ -280,8 +306,6 @@ krb5_gss_add_cred(minor_status, input_cred_handle, cred->prerfc_mech = 1; else if (g_OID_equal(desired_mech, gss_mech_krb5)) cred->rfc_mech = 1; - else if (g_OID_equal(desired_mech, gss_mech_krb5_v2)) - cred->rfcv2_mech = 1; /* set the outputs */ diff --git a/src/lib/gssapi/krb5/disp_status.c b/src/lib/gssapi/krb5/disp_status.c index 3a6ba7b..5991f87 100644 --- a/src/lib/gssapi/krb5/disp_status.c +++ b/src/lib/gssapi/krb5/disp_status.c @@ -21,7 +21,12 @@ */ #include "gssapiP_krb5.h" + +#if TARGET_OS_MAC +#include +#else #include "com_err.h" +#endif /* XXXX internationalization!! */ diff --git a/src/lib/gssapi/krb5/gssapiP_krb5.h b/src/lib/gssapi/krb5/gssapiP_krb5.h index e344b4f..a234530 100644 --- a/src/lib/gssapi/krb5/gssapiP_krb5.h +++ b/src/lib/gssapi/krb5/gssapiP_krb5.h @@ -1,4 +1,28 @@ /* + * Copyright 2000 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. + * + */ +/* * Copyright 1993 by OpenVision Technologies, Inc. * * Permission to use, copy, modify, distribute, and sell this software @@ -27,7 +51,12 @@ * $Id$ */ +#if TARGET_OS_MAC +#include +#else #include +#endif + #include /* work around sunos braindamage */ @@ -38,11 +67,7 @@ #undef minor #endif -#ifndef macintosh -#include "../generic/gssapiP_generic.h" -#else #include "gssapiP_generic.h" -#endif /* The include of gssapi_krb5.h will dtrt with the above #defines in * effect. @@ -79,6 +104,39 @@ #define KG2_RESP_FLAG_ERROR 0x0001 #define KG2_RESP_FLAG_DELEG_OK 0x0002 +/* These are to be stored in little-endian order, i.e., des-mac is + stored as 02 00. */ +enum sgn_alg { + SGN_ALG_DES_MAC_MD5 = 0x0000, + SGN_ALG_MD2_5 = 0x0001, + SGN_ALG_DES_MAC = 0x0002, + SGN_ALG_3 = 0x0003, /* not published */ + SGN_ALG_HMAC_MD5 = 0x0011, /* microsoft w2k; no support */ + SGN_ALG_HMAC_SHA1_DES3_KD = 0x0004 +}; +enum seal_alg { + SEAL_ALG_NONE = 0xffff, + SEAL_ALG_DES = 0x0000, + SEAL_ALG_1 = 0x0001, /* not published */ + SEAL_ALG_MICROSOFT_RC4 = 0x0010, /* microsoft w2k; no support */ + SEAL_ALG_DES3KD = 0x0002 +}; + +#define KG_USAGE_SEAL 22 +#define KG_USAGE_SIGN 23 +#define KG_USAGE_SEQ 24 + +enum qop { + GSS_KRB5_INTEG_C_QOP_MD5 = 0x0001, /* *partial* MD5 = "MD2.5" */ + GSS_KRB5_INTEG_C_QOP_DES_MD5 = 0x0002, + GSS_KRB5_INTEG_C_QOP_DES_MAC = 0x0003, + GSS_KRB5_INTEG_C_QOP_HMAC_SHA1 = 0x0004, + GSS_KRB5_INTEG_C_QOP_MASK = 0x00ff, + GSS_KRB5_CONF_C_QOP_DES = 0x0100, + GSS_KRB5_CONF_C_QOP_DES3_KD = 0x0200, + GSS_KRB5_CONF_C_QOP_MASK = 0xff00 +}; + /** internal types **/ typedef krb5_principal krb5_gss_name_t; @@ -89,7 +147,6 @@ typedef struct _krb5_gss_cred_id_rec { krb5_principal princ; /* this is not interned as a gss_name_t */ int prerfc_mech; int rfc_mech; - int rfcv2_mech; /* keytab (accept) data */ krb5_keytab keytab; @@ -125,7 +182,6 @@ typedef struct _krb5_gss_ctx_id_rec { int big_endian; krb5_auth_context auth_context; gss_OID_desc *mech_used; - int gsskrb5_version; int nctypes; krb5_cksumtype *ctypes; } krb5_gss_ctx_id_rec, *krb5_gss_ctx_id_t; @@ -190,12 +246,18 @@ int kg_encrypt_size PROTOTYPE((krb5_context context, krb5_keyblock *key, int n)); krb5_error_code kg_encrypt PROTOTYPE((krb5_context context, - krb5_keyblock *key, - krb5_pointer iv, krb5_pointer in, krb5_pointer out, int length)); + krb5_keyblock *key, int usage, + krb5_pointer iv, + krb5_pointer in, + krb5_pointer out, + int length)); krb5_error_code kg_decrypt PROTOTYPE((krb5_context context, - krb5_keyblock *key, - krb5_pointer iv, krb5_pointer in, krb5_pointer out, int length)); + krb5_keyblock *key, int usage, + krb5_pointer iv, + krb5_pointer in, + krb5_pointer out, + int length)); OM_uint32 kg_seal PROTOTYPE((krb5_context context, OM_uint32 *minor_status, @@ -517,7 +579,8 @@ PROTOTYPE( (OM_uint32 *, /* minor_status */ gss_ctx_id_t * /* context_handle */ )); -#if 0 +#if TARGET_OS_MAC +/* need prototypes on Mac OS X -- why *was* this #if 0? */ OM_uint32 krb5_gss_release_oid PROTOTYPE( (OM_uint32 *, /* minor_status */ gss_OID * /* oid */ diff --git a/src/lib/gssapi/krb5/gssapi_krb5.c b/src/lib/gssapi/krb5/gssapi_krb5.c index e700bb8..70ef491 100644 --- a/src/lib/gssapi/krb5/gssapi_krb5.c +++ b/src/lib/gssapi/krb5/gssapi_krb5.c @@ -51,6 +51,7 @@ */ #include "gssapiP_krb5.h" +#include "k5-int.h" /** exported constants defined in gssapi_krb5{,_nx}.h **/ @@ -90,16 +91,28 @@ const gss_OID_desc krb5_gss_oid_array[] = { /* this is the v2 assigned OID */ {9, "\052\206\110\206\367\022\001\002\003"}, /* these two are name type OID's */ + + /* 2.1.1. Kerberos Principal Name Form: (rfc 1964) + * This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * krb5(2) krb5_name(1)}. The recommended symbolic name for this type + * is "GSS_KRB5_NT_PRINCIPAL_NAME". */ {10, "\052\206\110\206\367\022\001\002\002\001"}, + + /* gss_nt_krb5_principal. Object identifier for a krb5_principal. Do not use. */ {10, "\052\206\110\206\367\022\001\002\002\002"}, { 0, 0 } }; -const gss_OID_desc * const gss_mech_krb5 = krb5_gss_oid_array+0; -const gss_OID_desc * const gss_mech_krb5_old = krb5_gss_oid_array+1; -const gss_OID_desc * const gss_mech_krb5_v2 = krb5_gss_oid_array+2; -const gss_OID_desc * const gss_nt_krb5_name = krb5_gss_oid_array+3; -const gss_OID_desc * const gss_nt_krb5_principal = krb5_gss_oid_array+4; +const gss_OID_desc * const gss_mech_krb5 = krb5_gss_oid_array+0; +const gss_OID_desc * const gss_mech_krb5_old = krb5_gss_oid_array+1; +const gss_OID_desc * const gss_mech_krb5_v2 = krb5_gss_oid_array+2; +const gss_OID_desc * const gss_nt_krb5_name = krb5_gss_oid_array+3; +const gss_OID_desc * const gss_nt_krb5_principal = krb5_gss_oid_array+4; +#if GSS_RFC_COMPLIANT_OIDS +const gss_OID_desc * const GSS_KRB5_NT_PRINCIPAL_NAME = krb5_gss_oid_array+3; +#endif /* GSS_RFC_COMPLIANT_OIDS */ + static const gss_OID_set_desc oidsets[] = { {1, (gss_OID) krb5_gss_oid_array+0}, diff --git a/src/lib/gssapi/krb5/gssapi_krb5.h b/src/lib/gssapi/krb5/gssapi_krb5.h index e4bac76..c1ad99f 100644 --- a/src/lib/gssapi/krb5/gssapi_krb5.h +++ b/src/lib/gssapi/krb5/gssapi_krb5.h @@ -23,13 +23,65 @@ #ifndef _GSSAPI_KRB5_H_ #define _GSSAPI_KRB5_H_ -#include +#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__)) + #include +#endif + +#if TARGET_OS_MAC + #include + #include + #include +#else + #include +#endif /* C++ friendlyness */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ +#if GSS_RFC_COMPLIANT_OIDS +/* Reserved static storage for GSS_oids. See rfc 1964 for more details. */ + +/* 2.1.1. Kerberos Principal Name Form: */ +GSS_DLLIMP extern const gss_OID_desc * const GSS_KRB5_NT_PRINCIPAL_NAME; +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * krb5(2) krb5_name(1)}. The recommended symbolic name for this type + * is "GSS_KRB5_NT_PRINCIPAL_NAME". */ + +/* 2.1.2. Host-Based Service Name Form */ +#define GSS_KRB5_NT_HOSTBASED_SERVICE_NAME GSS_C_NT_HOSTBASED_SERVICE +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) service_name(4)}. The previously recommended symbolic + * name for this type is "GSS_KRB5_NT_HOSTBASED_SERVICE_NAME". The + * currently preferred symbolic name for this type is + * "GSS_C_NT_HOSTBASED_SERVICE". */ + +/* 2.2.1. User Name Form */ +#define GSS_KRB5_NT_USER_NAME GSS_C_NT_USER_NAME +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) user_name(1)}. The recommended symbolic name for this + * type is "GSS_KRB5_NT_USER_NAME". */ + +/* 2.2.2. Machine UID Form */ +#define GSS_KRB5_NT_MACHINE_UID_NAME GSS_C_NT_MACHINE_UID_NAME +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) machine_uid_name(2)}. The recommended symbolic name for + * this type is "GSS_KRB5_NT_MACHINE_UID_NAME". */ + +/* 2.2.3. String UID Form */ +#define GSS_KRB5_NT_STRING_UID_NAME GSS_C_NT_STRING_UID_NAME +/* This name form shall be represented by the Object Identifier {iso(1) + * member-body(2) United States(840) mit(113554) infosys(1) gssapi(2) + * generic(1) string_uid_name(3)}. The recommended symbolic name for + * this type is "GSS_KRB5_NT_STRING_UID_NAME". */ + +#endif /* GSS_RFC_COMPLIANT_OIDS */ + extern const gss_OID_desc * const gss_mech_krb5; extern const gss_OID_desc * const gss_mech_krb5_old; extern const gss_OID_desc * const gss_mech_krb5_v2; diff --git a/src/lib/gssapi/krb5/import_sec_context.c b/src/lib/gssapi/krb5/import_sec_context.c index fd5415a..659cdc2 100644 --- a/src/lib/gssapi/krb5/import_sec_context.c +++ b/src/lib/gssapi/krb5/import_sec_context.c @@ -44,7 +44,7 @@ gss_OID krb5_gss_convert_static_mech_oid(oid) if ((oid->length == p->length) && (memcmp(oid->elements, p->elements, p->length) == 0)) { gss_release_oid(&minor_status, &oid); - return p; + return (gss_OID) p; } } return oid; diff --git a/src/lib/gssapi/krb5/init_sec_context.c b/src/lib/gssapi/krb5/init_sec_context.c index d0c8bc9..40c50cb 100644 --- a/src/lib/gssapi/krb5/init_sec_context.c +++ b/src/lib/gssapi/krb5/init_sec_context.c @@ -1,4 +1,28 @@ /* + * Copyright 2000 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. + * + */ +/* * Copyright 1993 by OpenVision Technologies, Inc. * * Permission to use, copy, modify, distribute, and sell this software @@ -49,6 +73,7 @@ #include "gssapiP_krb5.h" #include #include +#include /* * $Id$ @@ -63,13 +88,13 @@ int krb5_gss_dbg_client_expcreds = 0; * ccache. */ static krb5_error_code get_credentials(context, cred, server, now, - endtime, enctype, out_creds) + endtime, enctypes, out_creds) krb5_context context; krb5_gss_cred_id_t cred; krb5_principal server; krb5_timestamp now; krb5_timestamp endtime; - krb5_enctype enctype; + const krb5_enctype *enctypes; krb5_creds **out_creds; { krb5_error_code code; @@ -82,10 +107,15 @@ static krb5_error_code get_credentials(context, cred, server, now, if ((code = krb5_copy_principal(context, server, &in_creds.server))) goto cleanup; in_creds.times.endtime = endtime; - in_creds.keyblock.enctype = enctype; - if ((code = krb5_get_credentials(context, 0, cred->ccache, - &in_creds, out_creds))) + in_creds.keyblock.enctype = 0; + + code = krb5_set_default_tgs_enctypes (context, enctypes); + if (code) + goto cleanup; + code = krb5_get_credentials(context, 0, cred->ccache, + &in_creds, out_creds); + if (code) goto cleanup; /* @@ -93,7 +123,8 @@ static krb5_error_code get_credentials(context, cred, server, now, * boundaries) because accept_sec_context code is also similarly * non-forgiving. */ - if (!krb5_gss_dbg_client_expcreds && (*out_creds)->times.endtime < now) { + if (!krb5_gss_dbg_client_expcreds && *out_creds != NULL && + (*out_creds)->times.endtime < now) { code = KRB5KRB_AP_ERR_TKT_EXPIRED; goto cleanup; } @@ -106,7 +137,7 @@ cleanup: return code; } - +#if !defined(TARGET_OS_MAC) || !TARGET_OS_MAC static krb5_error_code make_ap_req_v2(context, ctx, cred, k_cred, chan_bindings, mech_type, token) krb5_context context; @@ -117,197 +148,10 @@ make_ap_req_v2(context, ctx, cred, k_cred, chan_bindings, mech_type, token) gss_OID mech_type; gss_buffer_t token; { - krb5_flags mk_req_flags = 0; - krb5_int32 con_flags; - krb5_error_code code; - krb5_data credmsg, cksumdata, ap_req; - int i, tlen, cblen, nctypes; - krb5_cksumtype *ctypes; - unsigned char *t, *ptr; - - credmsg.data = 0; - cksumdata.data = 0; - ap_req.data = 0; - ctypes = 0; - - /* create the option data if necessary */ - if (ctx->gss_flags & GSS_C_DELEG_FLAG) { - /* first get KRB_CRED message, so we know its length */ - - /* clear the time check flag that was set in krb5_auth_con_init() */ - krb5_auth_con_getflags(context, ctx->auth_context, &con_flags); - krb5_auth_con_setflags(context, ctx->auth_context, - con_flags & ~KRB5_AUTH_CONTEXT_DO_TIME); - - code = krb5_fwd_tgt_creds(context, ctx->auth_context, 0, - cred->princ, ctx->there, cred->ccache, 1, - &credmsg); - - /* turn KRB5_AUTH_CONTEXT_DO_TIME back on */ - krb5_auth_con_setflags(context, ctx->auth_context, con_flags); - - if (code) { - /* don't fail here; just don't accept/do the delegation - request */ - ctx->gss_flags &= ~GSS_C_DELEG_FLAG; - } else { - if (credmsg.length > KRB5_INT16_MAX) { - krb5_free_data_contents(context, &credmsg); - return(KRB5KRB_ERR_FIELD_TOOLONG); - } - } - } else { - credmsg.length = 0; - } - - /* construct the list of compatible cksum types */ - - if ((code = krb5_c_keyed_checksum_types(context, - k_cred->keyblock.enctype, - &nctypes, &ctypes))) - goto cleanup; - - if (nctypes == 0) { - code = KRB5_CRYPTO_INTERNAL; - goto cleanup; - } - - /* construct the checksum fields */ - - cblen = 4*5; - if (chan_bindings) - cblen += (chan_bindings->initiator_address.length+ - chan_bindings->acceptor_address.length+ - chan_bindings->application_data.length); - - cksumdata.length = cblen + 8 + 4*nctypes + 4; - if (credmsg.length) - cksumdata.length += 4 + credmsg.length; - - if ((cksumdata.data = (char *) malloc(cksumdata.length)) == NULL) - goto cleanup; - - /* helper macros. This code currently depends on a long being 32 - bits, and htonl dtrt. */ - - ptr = cksumdata.data; - - if (chan_bindings) { - TWRITE_INT(ptr, chan_bindings->initiator_addrtype, 1); - TWRITE_BUF(ptr, chan_bindings->initiator_address, 1); - TWRITE_INT(ptr, chan_bindings->acceptor_addrtype, 1); - TWRITE_BUF(ptr, chan_bindings->acceptor_address, 1); - TWRITE_BUF(ptr, chan_bindings->application_data, 1); - } else { - memset(ptr, 0, cblen); - ptr += cblen; - } - - /* construct the token fields */ - - ptr[0] = (KG2_TOK_INITIAL >> 8) & 0xff; - ptr[1] = KG2_TOK_INITIAL & 0xff; - - ptr[2] = (ctx->gss_flags >> 24) & 0xff; - ptr[3] = (ctx->gss_flags >> 16) & 0xff; - ptr[4] = (ctx->gss_flags >> 8) & 0xff; - ptr[5] = ctx->gss_flags & 0xff; - - ptr[6] = (nctypes >> 8) & 0xff; - ptr[7] = nctypes & 0xff; - - ptr += 8; - - for (i=0; i> 24) & 0xff; - ptr[1] = (ctypes[i] >> 16) & 0xff; - ptr[2] = (ctypes[i] >> 8) & 0xff; - ptr[3] = ctypes[i] & 0xff; - - ptr += 4; - } - - if (credmsg.length) { - ptr[0] = (KRB5_GSS_FOR_CREDS_OPTION >> 8) & 0xff; - ptr[1] = KRB5_GSS_FOR_CREDS_OPTION & 0xff; - - ptr[2] = (credmsg.length >> 8) & 0xff; - ptr[3] = credmsg.length & 0xff; - - ptr += 4; - - memcpy(ptr, credmsg.data, credmsg.length); - - ptr += credmsg.length; - } - - memset(ptr, 0, 4); - - /* call mk_req. subkey and ap_req need to be used or destroyed */ - - mk_req_flags = AP_OPTS_USE_SUBKEY; - - if (ctx->gss_flags & GSS_C_MUTUAL_FLAG) - mk_req_flags |= AP_OPTS_MUTUAL_REQUIRED; - - if ((code = krb5_mk_req_extended(context, &ctx->auth_context, mk_req_flags, - &cksumdata, k_cred, &ap_req))) - goto cleanup; - - /* store the interesting stuff from creds and authent */ - ctx->endtime = k_cred->times.endtime; - ctx->krb_flags = k_cred->ticket_flags; - - /* build up the token */ - - /* allocate space for the token */ - tlen = g_token_size((gss_OID) mech_type, - (cksumdata.length-(2+cblen))+2+ap_req.length); - - if ((t = (unsigned char *) xmalloc(tlen)) == NULL) { - code = ENOMEM; - goto cleanup; - } - - ptr = t; - - g_make_token_header((gss_OID) mech_type, - (cksumdata.length-(2+cblen))+2+ap_req.length, - &ptr, KG2_TOK_INITIAL); - - /* skip over the channel bindings and the token id */ - memcpy(ptr, cksumdata.data+cblen+2, cksumdata.length-(cblen+2)); - ptr += cksumdata.length-(cblen+2); - ptr[0] = (ap_req.length >> 8) & 0xff; - ptr[1] = ap_req.length & 0xff; - ptr += 2; - memcpy(ptr, ap_req.data, ap_req.length); - - /* pass allocated data back */ - - ctx->nctypes = nctypes; - ctx->ctypes = ctypes; - - token->length = tlen; - token->value = (void *) t; - - code = 0; - -cleanup: - if (code) { - if (ctypes) - krb5_free_cksumtypes(context, ctypes); - } - - if (credmsg.data) - free(credmsg.data); - if (ap_req.data) - free(ap_req.data); - if (cksumdata.data) - free(cksumdata.data); - - return(code); + int krb5_mech2_supported = 0; + assert(krb5_mech2_supported); } +#endif static krb5_error_code make_ap_req_v1(context, ctx, cred, k_cred, chan_bindings, mech_type, token) @@ -480,15 +324,22 @@ krb5_gss_init_sec_context(minor_status, claimant_cred_handle, krb5_context context; krb5_gss_cred_id_t cred; krb5_creds *k_cred = 0; - krb5_enctype enctype = ENCTYPE_DES_CBC_CRC; + static const krb5_enctype wanted_enctypes[] = { +#if 1 + ENCTYPE_DES3_CBC_SHA1, +#endif + ENCTYPE_DES_CBC_CRC, + ENCTYPE_DES_CBC_MD5, ENCTYPE_DES_CBC_MD4, + }; +#define N_WANTED_ENCTYPES (sizeof(wanted_enctypes)/sizeof(wanted_enctypes[0])) + krb5_enctype requested_enctypes[N_WANTED_ENCTYPES + 1]; + krb5_enctype *default_enctypes = 0; krb5_error_code code; krb5_gss_ctx_id_rec *ctx, *ctx_free; krb5_timestamp now; gss_buffer_desc token; - int gsskrb5_vers = 0; - int i, err; + int i, j, k, err; int default_mech = 0; - krb5_ui_4 resp_flags; OM_uint32 major_status; if (GSS_ERROR(kg_get_context(minor_status, &context))) @@ -528,32 +379,19 @@ krb5_gss_init_sec_context(minor_status, claimant_cred_handle, err = 0; if (mech_type == GSS_C_NULL_OID) { default_mech = 1; - if (cred->rfcv2_mech) { - mech_type = gss_mech_krb5_v2; - gsskrb5_vers = 2000; - } else if (cred->rfc_mech) { - mech_type = gss_mech_krb5; - gsskrb5_vers = 1000; - enctype = ENCTYPE_DES_CBC_CRC; + if (cred->rfc_mech) { + mech_type = (gss_OID) gss_mech_krb5; } else if (cred->prerfc_mech) { - mech_type = gss_mech_krb5_old; - gsskrb5_vers = 1000; - enctype = ENCTYPE_DES_CBC_CRC; + mech_type = (gss_OID) gss_mech_krb5_old; } else { err = 1; } - } else if (g_OID_equal(mech_type, gss_mech_krb5_v2)) { - if (!cred->rfcv2_mech) - err = 1; - gsskrb5_vers = 2000; } else if (g_OID_equal(mech_type, gss_mech_krb5)) { if (!cred->rfc_mech) err = 1; - gsskrb5_vers = 1000; } else if (g_OID_equal(mech_type, gss_mech_krb5_old)) { if (!cred->prerfc_mech) err = 1; - gsskrb5_vers = 1000; } else { err = 1; } @@ -607,7 +445,6 @@ krb5_gss_init_sec_context(minor_status, claimant_cred_handle, ctx->seed_init = 0; ctx->big_endian = 0; /* all initiators do little-endian, as per spec */ ctx->seqstate = 0; - ctx->gsskrb5_version = gsskrb5_vers; ctx->nctypes = 0; ctx->ctypes = 0; @@ -627,28 +464,57 @@ krb5_gss_init_sec_context(minor_status, claimant_cred_handle, &ctx->there))) goto fail; + code = krb5_get_tgs_ktypes (context, 0, &default_enctypes); + if (code) + goto fail; + /* "i" denotes *next* slot to fill. Don't forget to save room + for a trailing zero. */ + i = 0; + for (j = 0; + (default_enctypes[j] != 0 + /* This part should be redundant, but let's be paranoid. */ + && i < N_WANTED_ENCTYPES); + j++) { + + int is_duplicate_enctype; + int is_wanted_enctype; + + krb5_enctype e = default_enctypes[j]; + + /* Is this enctype one of the ones we want for GSSAPI? */ + is_wanted_enctype = 0; + for (k = 0; k < N_WANTED_ENCTYPES; k++) { + if (wanted_enctypes[k] == e) { + is_wanted_enctype = 1; + break; + } + } + /* If unwanted, go to the next one. */ + if (!is_wanted_enctype) + continue; + + /* Is this enctype already in the list of enctypes to + request? (Is it a duplicate?) */ + is_duplicate_enctype = 0; + for (k = 0; k < i; k++) { + if (requested_enctypes[k] == e) { + is_duplicate_enctype = 1; + break; + } + } + /* If it is not a duplicate, add it. */ + if (!is_duplicate_enctype) + requested_enctypes[i++] = e; + } + requested_enctypes[i++] = 0; + if ((code = get_credentials(context, cred, ctx->there, now, - ctx->endtime, enctype, &k_cred))) + ctx->endtime, requested_enctypes, &k_cred))) goto fail; - /* - * If the default mechanism was requested, and the keytype is - * DES_CBC, force the old mechanism - */ - if (default_mech && - ((k_cred->keyblock.enctype == ENCTYPE_DES_CBC_CRC) || - (k_cred->keyblock.enctype == ENCTYPE_DES_CBC_MD4) || - (k_cred->keyblock.enctype == ENCTYPE_DES_CBC_MD5))) { - ctx->gsskrb5_version = gsskrb5_vers = 1000; - mech_type = gss_mech_krb5; - if (k_cred->keyblock.enctype != ENCTYPE_DES_CBC_CRC) { - krb5_free_creds(context, k_cred); - enctype = ENCTYPE_DES_CBC_CRC; - if ((code = get_credentials(context, cred, ctx->there, now, - ctx->endtime, enctype, &k_cred))) - goto fail; - } - } + if (default_mech) { + mech_type = (gss_OID) gss_mech_krb5; + } if (generic_gss_copy_oid(minor_status, mech_type, &ctx->mech_used) != GSS_S_COMPLETE) { @@ -660,24 +526,7 @@ krb5_gss_init_sec_context(minor_status, claimant_cred_handle, */ ctx->mech_used = krb5_gss_convert_static_mech_oid(ctx->mech_used); - if (ctx->gsskrb5_version == 2000) { - /* gsskrb5 v2 */ - if ((code = make_ap_req_v2(context, ctx, - cred, k_cred, input_chan_bindings, - mech_type, &token))) { - if ((code == KRB5_FCC_NOFILE) || (code == KRB5_CC_NOTFOUND) || - (code == KG_EMPTY_CCACHE)) - major_status = GSS_S_NO_CRED; - if (code == KRB5KRB_AP_ERR_TKT_EXPIRED) - major_status = GSS_S_CREDENTIALS_EXPIRED; - goto fail; - } - - krb5_auth_con_getlocalseqnumber(context, ctx->auth_context, - &ctx->seq_send); - krb5_auth_con_getlocalsubkey(context, ctx->auth_context, - &ctx->subkey); - } else { + { /* gsskrb5 v1 */ if ((code = make_ap_req_v1(context, ctx, cred, k_cred, input_chan_bindings, @@ -699,11 +548,41 @@ krb5_gss_init_sec_context(minor_status, claimant_cred_handle, switch(ctx->subkey->enctype) { case ENCTYPE_DES_CBC_MD5: + case ENCTYPE_DES_CBC_MD4: case ENCTYPE_DES_CBC_CRC: ctx->subkey->enctype = ENCTYPE_DES_CBC_RAW; - ctx->signalg = 0; + ctx->signalg = SGN_ALG_DES_MAC_MD5; ctx->cksum_size = 8; - ctx->sealalg = 0; + ctx->sealalg = SEAL_ALG_DES; + + /* The encryption key is the session key XOR + 0xf0f0f0f0f0f0f0f0. */ + if ((code = krb5_copy_keyblock(context, ctx->subkey, &ctx->enc))) + goto fail; + + for (i=0; ienc->length; i++) + /*SUPPRESS 113*/ + ctx->enc->contents[i] ^= 0xf0; + + if ((code = krb5_copy_keyblock(context, ctx->subkey, &ctx->seq))) + goto fail; + + break; + + case ENCTYPE_DES3_CBC_SHA1: + ctx->subkey->enctype = ENCTYPE_DES3_CBC_RAW; + ctx->signalg = SGN_ALG_HMAC_SHA1_DES3_KD; + ctx->cksum_size = 20; + ctx->sealalg = SEAL_ALG_DES3KD; + + code = krb5_copy_keyblock (context, ctx->subkey, &ctx->enc); + if (code) + goto fail; + code = krb5_copy_keyblock (context, ctx->subkey, &ctx->seq); + if (code) { + krb5_free_keyblock (context, ctx->enc); + goto fail; + } break; #if 0 case ENCTYPE_DES3_CBC_MD5: @@ -714,20 +593,10 @@ krb5_gss_init_sec_context(minor_status, claimant_cred_handle, break; #endif default: + *minor_status = KRB5_BAD_ENCTYPE; return GSS_S_FAILURE; } - /* the encryption key is the session key XOR 0xf0f0f0f0f0f0f0f0 */ - - if ((code = krb5_copy_keyblock(context, ctx->subkey, &ctx->enc))) - goto fail; - - for (i=0; ienc->length; i++) - /*SUPPRESS 113*/ - ctx->enc->contents[i] ^= 0xf0; - - if ((code = krb5_copy_keyblock(context, ctx->subkey, &ctx->seq))) - goto fail; } if (k_cred) { @@ -780,7 +649,7 @@ krb5_gss_init_sec_context(minor_status, claimant_cred_handle, } else { unsigned char *ptr; char *sptr; - krb5_data ap_rep, mic; + krb5_data ap_rep; krb5_ap_rep_enc_part *ap_rep_data; krb5_error *krb_error; @@ -824,94 +693,38 @@ krb5_gss_init_sec_context(minor_status, claimant_cred_handle, ptr = (unsigned char *) input_token->value; - if (ctx->gsskrb5_version == 2000) { - int token_length; - int nctypes; - krb5_cksumtype *ctypes = 0; - - /* gsskrb5 v2 */ - - if ((code = g_verify_token_header((gss_OID) ctx->mech_used, - &token_length, - &ptr, KG2_TOK_RESPONSE, - input_token->length))) { - major_status = GSS_S_DEFECTIVE_TOKEN; - goto fail; - } - - if (GSS_ERROR(major_status = - kg2_parse_token(minor_status, ptr, token_length, - &resp_flags, &nctypes, &ctypes, - 0, NULL, &ap_rep, &mic))) { - if (ctypes) - free(ctypes); - code = *minor_status; - goto fail; - } - major_status = GSS_S_FAILURE; - - kg2_intersect_ctypes(&ctx->nctypes, ctx->ctypes, nctypes, ctypes); + if ((err = g_verify_token_header((gss_OID) ctx->mech_used, + &(ap_rep.length), + &ptr, KG_TOK_CTX_AP_REP, + input_token->length))) { + if (g_verify_token_header((gss_OID) ctx->mech_used, + &(ap_rep.length), + &ptr, KG_TOK_CTX_ERROR, + input_token->length) == 0) { - free(ctypes); + /* Handle a KRB_ERROR message from the server */ - if (ctx->nctypes == 0) { - code = KG_NO_CTYPES; - goto fail; - } - - if (resp_flags & KG2_RESP_FLAG_ERROR) { - if ((code = krb5_rd_error(context, &ap_rep, &krb_error))) + sptr = (char *) ptr; /* PC compiler bug */ + TREAD_STR(sptr, ap_rep.data, ap_rep.length); + + code = krb5_rd_error(context, &ap_rep, &krb_error); + if (code) goto fail; - if (krb_error->error) code = krb_error->error + ERROR_TABLE_BASE_krb5; else code = 0; - krb5_free_error(context, krb_error); goto fail; + } else { + *minor_status = 0; + return(GSS_S_DEFECTIVE_TOKEN); } - - if (resp_flags & KG2_RESP_FLAG_DELEG_OK) - ctx->gss_flags |= GSS_C_DELEG_FLAG; - - /* drop through to ap_rep handling */ - } else { - /* gsskrb5 v1 */ - - if ((err = g_verify_token_header((gss_OID) ctx->mech_used, - &(ap_rep.length), - &ptr, KG_TOK_CTX_AP_REP, - input_token->length))) { - if (g_verify_token_header((gss_OID) ctx->mech_used, - &(ap_rep.length), - &ptr, KG_TOK_CTX_ERROR, - input_token->length) == 0) { - - /* Handle a KRB_ERROR message from the server */ - - sptr = (char *) ptr; /* PC compiler bug */ - TREAD_STR(sptr, ap_rep.data, ap_rep.length); - - code = krb5_rd_error(context, &ap_rep, &krb_error); - if (code) - goto fail; - if (krb_error->error) - code = krb_error->error + ERROR_TABLE_BASE_krb5; - else - code = 0; - krb5_free_error(context, krb_error); - goto fail; - } else { - *minor_status = 0; - return(GSS_S_DEFECTIVE_TOKEN); - } - } - - sptr = (char *) ptr; /* PC compiler bug */ - TREAD_STR(sptr, ap_rep.data, ap_rep.length); } + sptr = (char *) ptr; /* PC compiler bug */ + TREAD_STR(sptr, ap_rep.data, ap_rep.length); + /* decode the ap_rep */ if ((code = krb5_rd_rep(context, ctx->auth_context, &ap_rep, &ap_rep_data))) { @@ -938,26 +751,6 @@ krb5_gss_init_sec_context(minor_status, claimant_cred_handle, /* set established */ ctx->established = 1; - if (ctx->gsskrb5_version == 2000) { - gss_buffer_desc mic_data, mic_token; - - /* start with the token id */ - mic_data.value = ptr-2; - /* end before the ap-rep length */ - mic_data.length = ((char*)(ap_rep.data-2)-(char*)(ptr-2)); - - mic_token.length = mic.length; - mic_token.value = mic.data; - - if (GSS_ERROR(major_status = - krb5_gss_verify_mic(minor_status, *context_handle, - &mic_data, &mic_token, NULL))) { - code = *minor_status; - goto fail; - } - major_status = GSS_S_FAILURE; - } - /* set returns */ if (time_rec) { diff --git a/src/lib/gssapi/krb5/inq_cred.c b/src/lib/gssapi/krb5/inq_cred.c index c800012..6fbbadc 100644 --- a/src/lib/gssapi/krb5/inq_cred.c +++ b/src/lib/gssapi/krb5/inq_cred.c @@ -1,4 +1,28 @@ /* + * Copyright 2000 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. + * + */ +/* * Copyright 1993 by OpenVision Technologies, Inc. * * Permission to use, copy, modify, distribute, and sell this software @@ -116,15 +140,11 @@ krb5_gss_inquire_cred(minor_status, cred_handle, name, lifetime_ret, &mechs)) || (cred->prerfc_mech && GSS_ERROR(ret = generic_gss_add_oid_set_member(minor_status, - gss_mech_krb5_old, + (gss_OID) gss_mech_krb5_old, &mechs))) || (cred->rfc_mech && GSS_ERROR(ret = generic_gss_add_oid_set_member(minor_status, - gss_mech_krb5, - &mechs))) || - (cred->rfcv2_mech && - GSS_ERROR(ret = generic_gss_add_oid_set_member(minor_status, - gss_mech_krb5_v2, + (gss_OID) gss_mech_krb5, &mechs)))) { krb5_free_principal(context, ret_name); /* *minor_status set above */ diff --git a/src/lib/gssapi/krb5/k5seal.c b/src/lib/gssapi/krb5/k5seal.c index ae8cc75..1ca108e 100644 --- a/src/lib/gssapi/krb5/k5seal.c +++ b/src/lib/gssapi/krb5/k5seal.c @@ -1,6 +1,6 @@ /* * Copyright 1993 by OpenVision Technologies, Inc. - * + * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appears in all copies and @@ -10,7 +10,7 @@ * without specific, written prior permission. OpenVision makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. - * + * * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR @@ -22,14 +22,14 @@ /* * Copyright (C) 1998 by the FundsXpress, INC. - * + * * All rights reserved. - * + * * Export of this software from the United States of America may 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 @@ -40,7 +40,7 @@ * permission. FundsXpress makes no representations about the suitability of * this software for any purpose. It is provided "as is" without express * or implied warranty. - * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. @@ -49,196 +49,280 @@ #include "gssapiP_krb5.h" static krb5_error_code -make_priv_token_v2 PROTOTYPE((krb5_context context, - krb5_keyblock *subkey, +make_seal_token_v1 PROTOTYPE((krb5_context context, + krb5_keyblock *enc, + krb5_keyblock *seq, krb5_int32 *seqnum, int direction, gss_buffer_t text, gss_buffer_t token, + int signalg, + int cksum_size, + int sealalg, + int encrypt, + int toktype, + int bigend, gss_OID oid)); static krb5_error_code -make_priv_token_v2(context, subkey, seqnum, direction, text, token, oid) - krb5_context context; - krb5_keyblock *subkey; - krb5_int32 *seqnum; - int direction; - gss_buffer_t text; - gss_buffer_t token; - gss_OID oid; -{ - krb5_data plain; - krb5_enc_data cipher; - krb5_error_code code; - size_t enclen; - int tlen; - unsigned char *t, *ptr; - - plain.data = 0; - cipher.ciphertext.data = 0; - t = 0; - - plain.length = 7+text->length; - if ((plain.data = (void *) malloc(plain.length)) == NULL) { - code = ENOMEM; - goto cleanup; - } - - plain.data[0] = (*seqnum >> 24) & 0xff; - plain.data[1] = (*seqnum >> 16) & 0xff; - plain.data[2] = (*seqnum >> 8) & 0xff; - plain.data[3] = *seqnum & 0xff; - - plain.data[4] = direction?0:0xff; - - plain.data[5] = (text->length >> 8) & 0xff; - plain.data[6] = text->length & 0xff; - - memcpy(plain.data+7, text->value, text->length); - - if (code = krb5_c_encrypt_length(context, subkey->enctype, - plain.length, &enclen)) - goto cleanup; - - tlen = g_token_size((gss_OID) oid, 2+enclen); - - if ((t = (unsigned char *) xmalloc(tlen)) == NULL) - return(ENOMEM); - - ptr = t; - - g_make_token_header((gss_OID) oid, 2+enclen, &ptr, - KG2_TOK_WRAP_PRIV); - - ptr[0] = (enclen >> 8) & 0xff; - ptr[1] = enclen & 0xff; - - cipher.ciphertext.length = enclen; - cipher.ciphertext.data = ptr+2; - - if (code = krb5_c_encrypt(context, subkey, - KRB5_KEYUSAGE_GSS_TOK_WRAP_PRIV, - 0, &plain, &cipher)) - goto cleanup; - - /* that's it. return the token */ - - (*seqnum)++; - - token->length = tlen; - token->value = (void *) t; - - code = 0; - -cleanup: - if (plain.data) - free(plain.data); - if (code) { - if (t) - free(t); - } - - return(code); -} - -static krb5_error_code -make_integ_token_v2 PROTOTYPE((krb5_context context, - krb5_keyblock *subkey, - krb5_cksumtype ctype, - krb5_int32 *seqnum, - int direction, - gss_buffer_t text, - gss_buffer_t token, - int toktype, - gss_OID oid)); - -static krb5_error_code -make_integ_token_v2(context, subkey, ctype, seqnum, direction, text, token, - toktype, oid) - krb5_context context; - krb5_keyblock *subkey; - krb5_cksumtype ctype; - krb5_int32 *seqnum; - int direction; - gss_buffer_t text; - gss_buffer_t token; - int toktype; - gss_OID oid; +make_seal_token_v1(context, enc, seq, seqnum, direction, text, token, + signalg, cksum_size, sealalg, encrypt, toktype, + bigend, oid) + krb5_context context; + krb5_keyblock *enc; + krb5_keyblock *seq; + krb5_int32 *seqnum; + int direction; + gss_buffer_t text; + gss_buffer_t token; + int signalg; + int cksum_size; + int sealalg; + int encrypt; + int toktype; + int bigend; + gss_OID oid; { krb5_error_code code; - int tmp, tlen; - unsigned char *t, *ptr; - krb5_data plain; + size_t sumlen; + char *data_ptr; + krb5_data plaind; + krb5_checksum md5cksum; krb5_checksum cksum; + int conflen=0, tmsglen, tlen; + unsigned char *t, *ptr; - plain.data = 0; - t = 0; - cksum.contents = 0; + int encblksize, sumblksize; + + switch (signalg) { + case SGN_ALG_DES_MAC_MD5: + case SGN_ALG_MD2_5: + case SGN_ALG_HMAC_MD5: + sumblksize = 1; + break; + case SGN_ALG_DES_MAC: + sumblksize = 8; + break; + case SGN_ALG_HMAC_SHA1_DES3_KD: + sumblksize = 1; + break; + default: + abort (); + return 123; /* find error code */ + } - /* assemble the checksum buffer and compute the checksum */ + switch (sealalg) { + case SEAL_ALG_NONE: + case SEAL_ALG_DES: + case SEAL_ALG_DES3KD: + encblksize = 8; + break; + default: + abort (); + return 12345654321; + } - plain.length = 7+text->length; + /* create the token buffer */ - if ((plain.data = (char *) malloc(plain.length)) == NULL) { - code = errno; - goto cleanup; + if (toktype == KG_TOK_SEAL_MSG) { + if (bigend && !encrypt) { + tmsglen = text->length; + } else { + conflen = kg_confounder_size(context, enc); + /* XXX knows that des block size is 8 */ + tmsglen = (conflen+text->length+8)&(~7); + } + } else { + tmsglen = 0; } - plain.data[0] = (*seqnum >> 24) & 0xff; - plain.data[1] = (*seqnum >> 16) & 0xff; - plain.data[2] = (*seqnum >> 8) & 0xff; - plain.data[3] = *seqnum & 0xff; + tlen = g_token_size((gss_OID) oid, 14+cksum_size+tmsglen); - plain.data[4] = direction?0:0xff; + if ((t = (unsigned char *) xmalloc(tlen)) == NULL) + return(ENOMEM); - plain.data[5] = (text->length >> 8) & 0xff; - plain.data[6] = text->length & 0xff; + /*** fill in the token */ - memcpy(plain.data+7, text->value, text->length); + ptr = t; - if (code = krb5_c_make_checksum(context, ctype, subkey, - (toktype == KG2_TOK_WRAP_INTEG)? - KRB5_KEYUSAGE_GSS_TOK_WRAP_INTEG: - KRB5_KEYUSAGE_GSS_TOK_MIC, - &plain, &cksum)) - goto cleanup; + g_make_token_header((gss_OID) oid, 14+cksum_size+tmsglen, &ptr, toktype); - /* assemble the token itself */ + /* 0..1 SIGN_ALG */ - if (toktype == KG2_TOK_WRAP_INTEG) - tmp = 4+(7+text->length)+2+cksum.length; - else - tmp = 4+(5)+2+cksum.length; + ptr[0] = signalg & 0xff; + ptr[1] = (signalg >> 8) & 0xff; - tlen = g_token_size((gss_OID) oid, tmp); + /* 2..3 SEAL_ALG or Filler */ - if ((t = (unsigned char *) xmalloc(tlen)) == NULL) - return(ENOMEM); + if ((toktype == KG_TOK_SEAL_MSG) && encrypt) { + ptr[2] = sealalg & 0xff; + ptr[3] = (sealalg >> 8) & 0xff; + } else { + /* No seal */ + ptr[2] = 0xff; + ptr[3] = 0xff; + } - ptr = t; + /* 4..5 Filler */ + + ptr[4] = 0xff; + ptr[5] = 0xff; + + /* pad the plaintext, encrypt if needed, and stick it in the token */ + + /* initialize the the cksum */ + switch (signalg) { + case SGN_ALG_DES_MAC_MD5: + case SGN_ALG_MD2_5: + case SGN_ALG_HMAC_MD5: + md5cksum.checksum_type = CKSUMTYPE_RSA_MD5; + break; + case SGN_ALG_HMAC_SHA1_DES3_KD: + md5cksum.checksum_type = CKSUMTYPE_HMAC_SHA1_DES3; + break; + default: + case SGN_ALG_DES_MAC: + abort (); + } - g_make_token_header((gss_OID) oid, tmp, &ptr, toktype); + if (code = krb5_c_checksum_length(context, md5cksum.checksum_type, &sumlen)) + return(code); + md5cksum.length = sumlen; + + if (toktype == KG_TOK_SEAL_MSG) { + unsigned char *plain; + unsigned char pad; + + if (!bigend || encrypt) { + if ((plain = (unsigned char *) xmalloc(tmsglen)) == NULL) { + xfree(t); + return(ENOMEM); + } + + if ((code = kg_make_confounder(context, enc, plain))) { + xfree(plain); + xfree(t); + return(code); + } + + memcpy(plain+conflen, text->value, text->length); + + /* XXX 8 is DES cblock size */ + pad = 8-(text->length%8); + + memset(plain+conflen+text->length, pad, pad); + } else { + /* plain is never used in the bigend && !encrypt case */ + plain = NULL; + } + + if (encrypt) { + if ((code = kg_encrypt(context, enc, KG_USAGE_SEAL, NULL, + (krb5_pointer) plain, + (krb5_pointer) (ptr+cksum_size+14), + tmsglen))) { + if (plain) + xfree(plain); + xfree(t); + return(code); + } + } else { + if (bigend) + memcpy(ptr+14+cksum_size, text->value, text->length); + else + memcpy(ptr+14+cksum_size, plain, tmsglen); + } + + /* compute the checksum */ + + /* 8 = head of token body as specified by mech spec */ + if (! (data_ptr = + (char *) xmalloc(8 + (bigend ? text->length : tmsglen)))) { + if (plain) + xfree(plain); + xfree(t); + return(ENOMEM); + } + (void) memcpy(data_ptr, ptr-2, 8); + if (bigend) + (void) memcpy(data_ptr+8, text->value, text->length); + else + (void) memcpy(data_ptr+8, plain, tmsglen); + plaind.length = 8 + (bigend ? text->length : tmsglen); + plaind.data = data_ptr; + code = krb5_c_make_checksum(context, md5cksum.checksum_type, seq, + KG_USAGE_SIGN, &plaind, &md5cksum); + xfree(data_ptr); + + if (code) { + if (plain) + xfree(plain); + xfree(t); + return(code); + } - ptr[0] = (ctype >> 24) & 0xff; - ptr[1] = (ctype >> 16) & 0xff; - ptr[2] = (ctype >> 8) & 0xff; - ptr[3] = ctype & 0xff; + if (plain) + xfree(plain); + } else { + /* Sign only. */ + /* compute the checksum */ - ptr += 4; + if (! (data_ptr = (char *) xmalloc(8 + text->length))) { + xfree(t); + return(ENOMEM); + } + (void) memcpy(data_ptr, ptr-2, 8); + (void) memcpy(data_ptr+8, text->value, text->length); + plaind.length = 8 + text->length; + plaind.data = data_ptr; + code = krb5_c_make_checksum(context, md5cksum.checksum_type, seq, + KG_USAGE_SIGN, &plaind, &md5cksum); + xfree(data_ptr); + if (code) { + xfree(t); + return(code); + } + } - if (toktype == KG2_TOK_WRAP_INTEG) { - memcpy(ptr, plain.data, 7+text->length); - ptr += 7+text->length; - } else { - memcpy(ptr, plain.data, 5); - ptr += 5; + switch(signalg) { + case SGN_ALG_DES_MAC_MD5: + case 3: + + if ((code = kg_encrypt(context, seq, KG_USAGE_SEAL, + (g_OID_equal(oid, gss_mech_krb5_old) ? + seq->contents : NULL), + md5cksum.contents, md5cksum.contents, 16))) { + xfree(md5cksum.contents); + xfree(t); + return code; + } + + cksum.length = cksum_size; + cksum.contents = md5cksum.contents + 16 - cksum.length; + + memcpy(ptr+14, cksum.contents, cksum.length); + break; + + case SGN_ALG_HMAC_SHA1_DES3_KD: + /* + * Using key derivation, the call to krb5_c_make_checksum + * already dealt with encrypting. + */ + if (md5cksum.length != cksum_size) + abort (); + memcpy (ptr+14, md5cksum.contents, md5cksum.length); + break; } - ptr[0] = (cksum.length >> 8) & 0xff; - ptr[1] = cksum.length & 0xff; - ptr += 2; + xfree(md5cksum.contents); + + /* create the seq_num */ - memcpy(ptr, cksum.contents, cksum.length); + if ((code = kg_make_seq_num(context, seq, direction?0:0xff, *seqnum, + ptr+14, ptr+6))) { + xfree(t); + return(code); + } /* that's it. return the token */ @@ -247,372 +331,110 @@ make_integ_token_v2(context, subkey, ctype, seqnum, direction, text, token, token->length = tlen; token->value = (void *) t; - code = 0; - -cleanup: - if (plain.data) - free(plain.data); - if (cksum.contents) - krb5_free_checksum_contents(context, &cksum); - if (code) { - if (t) - free(t); - } - - return(code); + return(0); } -static krb5_error_code -make_seal_token_v1 PROTOTYPE((krb5_context context, - krb5_keyblock *enc, - krb5_keyblock *seq, - krb5_int32 *seqnum, - int direction, - gss_buffer_t text, - gss_buffer_t token, - int signalg, - int cksum_size, - int sealalg, - int encrypt, - int toktype, - int bigend, - gss_OID oid)); +/* if signonly is true, ignore conf_req, conf_state, + and do not encode the ENC_TYPE, MSG_LENGTH, or MSG_TEXT fields */ -static krb5_error_code -make_seal_token_v1(context, enc, seq, seqnum, direction, text, token, - signalg, cksum_size, sealalg, encrypt, toktype, - bigend, oid) - krb5_context context; - krb5_keyblock *enc; - krb5_keyblock *seq; - krb5_int32 *seqnum; - int direction; - gss_buffer_t text; - gss_buffer_t token; - int signalg; - int cksum_size; - int sealalg; - int encrypt; - int toktype; - int bigend; - gss_OID oid; +OM_uint32 +kg_seal(context, minor_status, context_handle, conf_req_flag, qop_req, + input_message_buffer, conf_state, output_message_buffer, toktype) + krb5_context context; + OM_uint32 *minor_status; + gss_ctx_id_t context_handle; + int conf_req_flag; + int qop_req; + gss_buffer_t input_message_buffer; + int *conf_state; + gss_buffer_t output_message_buffer; + int toktype; { - krb5_error_code code; - size_t sumlen; - char *data_ptr; - krb5_data plaind; - krb5_checksum md5cksum; - krb5_checksum cksum; - int conflen=0, tmsglen, tlen; - unsigned char *t, *ptr; - - /* create the token buffer */ - - if (toktype == KG_TOK_SEAL_MSG) { - if (bigend && !encrypt) { - tmsglen = text->length; - } else { - conflen = kg_confounder_size(context, enc); - /* XXX knows that des block size is 8 */ - tmsglen = (conflen+text->length+8)&(~7); - } - } else { - tmsglen = 0; - } - - tlen = g_token_size((gss_OID) oid, 14+cksum_size+tmsglen); - - if ((t = (unsigned char *) xmalloc(tlen)) == NULL) - return(ENOMEM); - - /*** fill in the token */ - - ptr = t; - - g_make_token_header((gss_OID) oid, 14+cksum_size+tmsglen, &ptr, toktype); - - /* 0..1 SIGN_ALG */ - - ptr[0] = signalg; - ptr[1] = 0; - - /* 2..3 SEAL_ALG or Filler */ - - if ((toktype == KG_TOK_SEAL_MSG) && encrypt) { - ptr[2] = sealalg; - ptr[3] = 0; - } else { - /* No seal */ - ptr[2] = 0xff; - ptr[3] = 0xff; - } - - /* 4..5 Filler */ - - ptr[4] = 0xff; - ptr[5] = 0xff; - - /* pad the plaintext, encrypt if needed, and stick it in the token */ - - /* initialize the the cksum */ - if (code = krb5_c_checksum_length(context, CKSUMTYPE_RSA_MD5, &sumlen)) - return(code); - - md5cksum.checksum_type = CKSUMTYPE_RSA_MD5; - md5cksum.length = sumlen; - if (toktype == KG_TOK_SEAL_MSG) { - unsigned char *plain; - unsigned char pad; - - if (!bigend || encrypt) { - if ((plain = (unsigned char *) xmalloc(tmsglen)) == NULL) { - xfree(t); - return(ENOMEM); - } - - if ((code = kg_make_confounder(context, enc, plain))) { - xfree(plain); - xfree(t); - return(code); - } - - memcpy(plain+conflen, text->value, text->length); - - /* XXX 8 is DES cblock size */ - pad = 8-(text->length%8); - - memset(plain+conflen+text->length, pad, pad); - } else { - /* plain is never used in the bigend && !encrypt case */ - plain = NULL; - } + krb5_gss_ctx_id_rec *ctx; + krb5_error_code code; + krb5_timestamp now; - if (encrypt) { - if ((code = kg_encrypt(context, enc, NULL, (krb5_pointer) plain, - (krb5_pointer) (ptr+cksum_size+14), - tmsglen))) { - if (plain) - xfree(plain); - xfree(t); - return(code); - } - } else { - if (bigend) - memcpy(ptr+14+cksum_size, text->value, text->length); - else - memcpy(ptr+14+cksum_size, plain, tmsglen); - } - - /* compute the checksum */ - - /* 8 = head of token body as specified by mech spec */ - if (! (data_ptr = - (char *) xmalloc(8 + (bigend ? text->length : tmsglen)))) { - if (plain) - xfree(plain); - xfree(t); - return(ENOMEM); - } - (void) memcpy(data_ptr, ptr-2, 8); - if (bigend) - (void) memcpy(data_ptr+8, text->value, text->length); - else - (void) memcpy(data_ptr+8, plain, tmsglen); - plaind.length = 8 + (bigend ? text->length : tmsglen); - plaind.data = data_ptr; - code = krb5_c_make_checksum(context, md5cksum.checksum_type, - 0, 0, &plaind, &md5cksum); - xfree(data_ptr); - - if (code) { - if (plain) - xfree(plain); - xfree(t); - return(code); - memcpy(ptr+14+cksum_size, plain, tmsglen); - } - - if (plain) - xfree(plain); - } else { - /* compute the checksum */ - - if (! (data_ptr = (char *) xmalloc(8 + text->length))) { - xfree(t); - return(ENOMEM); - } - (void) memcpy(data_ptr, ptr-2, 8); - (void) memcpy(data_ptr+8, text->value, text->length); - plaind.length = 8 + text->length; - plaind.data = data_ptr; - code = krb5_c_make_checksum(context, md5cksum.checksum_type, 0, 0, - &plaind, &md5cksum); - xfree(data_ptr); - if (code) { - xfree(t); - return(code); - } - } - - switch(signalg) { - case 0: - case 3: + output_message_buffer->length = 0; + output_message_buffer->value = NULL; + /* only default qop or matching established cryptosystem is allowed */ + #if 0 - /* XXX this depends on the key being a single-des key */ - - /* DES CBC doesn't use a zero IV like it should in some - krb5 implementations (beta5+). So we just do the - DES encryption the long way, and keep the last block - as the MAC */ - - /* XXX not converted to new api since it's inside an #if 0 */ - - /* initialize the the cksum and allocate the contents buffer */ - cksum.checksum_type = CKSUMTYPE_DESCBC; - cksum.length = krb5_checksum_size(context, CKSUMTYPE_DESCBC); - if ((cksum.contents = (krb5_octet *) xmalloc(cksum.length)) == NULL) - return(ENOMEM); - - /* XXX not converted to new api since it's inside an #if 0 */ - if (code = krb5_calculate_checksum(context, cksum.checksum_type, - md5cksum.contents, 16, - seq->contents, - seq->length, - &cksum)) { - xfree(cksum.contents); - xfree(md5cksum.contents); - xfree(t); - return(code); - } - - memcpy(ptr+14, cksum.contents, 8); - - xfree(cksum.contents); + switch (qop_req & GSS_KRB5_CONF_C_QOP_MASK) { + case GSS_C_QOP_DEFAULT: + break; + default: + unknown_qop: + *minor_status = (OM_uint32) G_UNKNOWN_QOP; + return GSS_S_FAILURE; + case GSS_KRB5_CONF_C_QOP_DES: + if (ctx->sealalg != SEAL_ALG_DES) { + bad_qop: + *minor_status = (OM_uint32) G_BAD_QOP; + return GSS_S_FAILURE; + } + break; + case GSS_KRB5_CONF_C_QOP_DES3: + if (ctx->sealalg != SEAL_ALG_DES3) + goto bad_qop; + break; + } + switch (qop_req & GSS_KRB5_INTEG_C_QOP_MASK) { + case GSS_C_QOP_DEFAULT: + break; + default: + goto unknown_qop; + case GSS_KRB5_INTEG_C_QOP_MD5: + case GSS_KRB5_INTEG_C_QOP_DES_MD5: + case GSS_KRB5_INTEG_C_QOP_DES_MAC: + if (ctx->sealalg != SEAL_ALG_DES) + goto bad_qop; + break; + case GSS_KRB5_INTEG_C_QOP_HMAC_SHA1: + if (ctx->sealalg != SEAL_ALG_DES3KD) + goto bad_qop; + break; + } #else - if ((code = kg_encrypt(context, seq, - (g_OID_equal(oid, gss_mech_krb5_old) ? - seq->contents : NULL), - md5cksum.contents, md5cksum.contents, 16))) { - xfree(md5cksum.contents); - xfree(t); - return code; - } - - cksum.length = cksum_size; - cksum.contents = md5cksum.contents + 16 - cksum.length; - - memcpy(ptr+14, cksum.contents, cksum.length); + if (qop_req != 0) { + *minor_status = (OM_uint32) G_UNKNOWN_QOP; + return GSS_S_FAILURE; + } #endif - break; - } - - xfree(md5cksum.contents); - - /* create the seq_num */ + /* validate the context handle */ + if (! kg_validate_ctx_id(context_handle)) { + *minor_status = (OM_uint32) G_VALIDATE_FAILED; + return(GSS_S_NO_CONTEXT); + } - if ((code = kg_make_seq_num(context, seq, direction?0:0xff, *seqnum, - ptr+14, ptr+6))) { - xfree(t); - return(code); - } + ctx = (krb5_gss_ctx_id_rec *) context_handle; - /* that's it. return the token */ + if (! ctx->established) { + *minor_status = KG_CTX_INCOMPLETE; + return(GSS_S_NO_CONTEXT); + } - (*seqnum)++; + if ((code = krb5_timeofday(context, &now))) { + *minor_status = code; + return(GSS_S_FAILURE); + } - token->length = tlen; - token->value = (void *) t; + code = make_seal_token_v1(context, ctx->enc, ctx->seq, + &ctx->seq_send, ctx->initiate, + input_message_buffer, output_message_buffer, + ctx->signalg, ctx->cksum_size, ctx->sealalg, + conf_req_flag, toktype, ctx->big_endian, + ctx->mech_used); - return(0); -} + if (code) { + *minor_status = code; + return(GSS_S_FAILURE); + } -/* if signonly is true, ignore conf_req, conf_state, - and do not encode the ENC_TYPE, MSG_LENGTH, or MSG_TEXT fields */ + if (conf_state) + *conf_state = conf_req_flag; -OM_uint32 -kg_seal(context, minor_status, context_handle, conf_req_flag, qop_req, - input_message_buffer, conf_state, output_message_buffer, toktype) - krb5_context context; - OM_uint32 *minor_status; - gss_ctx_id_t context_handle; - int conf_req_flag; - int qop_req; - gss_buffer_t input_message_buffer; - int *conf_state; - gss_buffer_t output_message_buffer; - int toktype; -{ - krb5_gss_ctx_id_rec *ctx; - krb5_error_code code; - krb5_timestamp now; - - output_message_buffer->length = 0; - output_message_buffer->value = NULL; - - /* only default qop is allowed */ - if (qop_req != GSS_C_QOP_DEFAULT) { - *minor_status = (OM_uint32) G_UNKNOWN_QOP; - return(GSS_S_FAILURE); - } - - /* validate the context handle */ - if (! kg_validate_ctx_id(context_handle)) { - *minor_status = (OM_uint32) G_VALIDATE_FAILED; - return(GSS_S_NO_CONTEXT); - } - - ctx = (krb5_gss_ctx_id_rec *) context_handle; - - if (! ctx->established) { - *minor_status = KG_CTX_INCOMPLETE; - return(GSS_S_NO_CONTEXT); - } - - if ((code = krb5_timeofday(context, &now))) { - *minor_status = code; - return(GSS_S_FAILURE); - } - - if (ctx->gsskrb5_version == 2000) { - if (toktype == KG_TOK_WRAP_MSG) { - if (conf_req_flag) - toktype = KG2_TOK_WRAP_PRIV; - else - toktype = KG2_TOK_WRAP_INTEG; - } else { - toktype = KG2_TOK_MIC; - } - - if (conf_req_flag) { - code = make_priv_token_v2(context, ctx->subkey, &ctx->seq_send, - ctx->initiate, input_message_buffer, - output_message_buffer, ctx->mech_used); - } else { - code = make_integ_token_v2(context, ctx->subkey, ctx->ctypes[0], - &ctx->seq_send, ctx->initiate, - input_message_buffer, - output_message_buffer, toktype, - ctx->mech_used); - } - } else { - code = make_seal_token_v1(context, ctx->enc, ctx->seq, - &ctx->seq_send, ctx->initiate, - input_message_buffer, output_message_buffer, - ctx->signalg, ctx->cksum_size, ctx->sealalg, - conf_req_flag, toktype, ctx->big_endian, - ctx->mech_used); - } - - if (code) { - *minor_status = code; - return(GSS_S_FAILURE); - } - - if (conf_state) - *conf_state = conf_req_flag; - - *minor_status = 0; - return((ctx->endtime < now)?GSS_S_CONTEXT_EXPIRED:GSS_S_COMPLETE); + *minor_status = 0; + return((ctx->endtime < now)?GSS_S_CONTEXT_EXPIRED:GSS_S_COMPLETE); } diff --git a/src/lib/gssapi/krb5/k5unseal.c b/src/lib/gssapi/krb5/k5unseal.c index 64a9539..9e4d353 100644 --- a/src/lib/gssapi/krb5/k5unseal.c +++ b/src/lib/gssapi/krb5/k5unseal.c @@ -1,6 +1,6 @@ /* * Copyright 1993 by OpenVision Technologies, Inc. - * + * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appears in all copies and @@ -10,7 +10,7 @@ * without specific, written prior permission. OpenVision makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. - * + * * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR @@ -22,14 +22,14 @@ /* * Copyright (C) 1998 by the FundsXpress, INC. - * + * * All rights reserved. - * + * * Export of this software from the United States of America may 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 @@ -40,7 +40,7 @@ * permission. FundsXpress makes no representations about the suitability of * this software for any purpose. It is provided "as is" without express * or implied warranty. - * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. @@ -53,834 +53,438 @@ * $Id$ */ -static OM_uint32 -kg2_verify_mic(context, minor_status, ctx, ptr, bodysize, - text, qop_state) - krb5_context context; - OM_uint32 *minor_status; - krb5_gss_ctx_id_rec *ctx; - unsigned char *ptr; - int bodysize; - gss_buffer_t text; - gss_qop_t *qop_state; +/* message_buffer is an input if SIGN, output if SEAL, and ignored if DEL_CTX + conf_state is only valid if SEAL. */ + +OM_uint32 +kg_unseal_v1(context, minor_status, ctx, ptr, bodysize, message_buffer, + conf_state, qop_state, toktype) + krb5_context context; + OM_uint32 *minor_status; + krb5_gss_ctx_id_rec *ctx; + unsigned char *ptr; + int bodysize; + gss_buffer_t message_buffer; + int *conf_state; + int *qop_state; + int toktype; { - size_t cksumlen; krb5_error_code code; - krb5_data plain; - krb5_cksumtype tctype; - krb5_ui_4 tseqnum; - int tdirection; + int tmsglen; + int conflen = 0; + int signalg; + int sealalg; + gss_buffer_desc token; krb5_checksum cksum; - krb5_boolean ckvalid; + krb5_checksum md5cksum; + krb5_data plaind; + char *data_ptr; krb5_timestamp now; + unsigned char *plain; + int cksum_len = 0; + int plainlen; + int direction; + krb5_int32 seqnum; OM_uint32 retval; + size_t sumlen; - plain.data = 0; - cksum.contents = 0; - - /* verify the header */ - - if (bodysize < 11) { - free(plain.data); - *minor_status = G_TOK_TRUNC; - return(GSS_S_DEFECTIVE_TOKEN); + if (toktype == KG_TOK_SEAL_MSG) { + message_buffer->length = 0; + message_buffer->value = NULL; } - /* allocate the checksum buffer */ - - plain.length = 7+text->length; - - if ((plain.data = (char *) malloc(plain.length)) == NULL) { - *minor_status = ENOMEM; - return(GSS_S_FAILURE); - } + /* get the sign and seal algorithms */ - /* suck out the body parts from the token */ + signalg = ptr[0] + (ptr[1]<<8); + sealalg = ptr[2] + (ptr[3]<<8); - tctype = (krb5_cksumtype) ((ptr[0]<<24) | (ptr[1]<<16) | - (ptr[2]<<8) | ptr[3]); - ptr += 4; + /* Sanity checks */ - memcpy(plain.data, ptr, 5); - tseqnum = ((ptr[0]<<24) | (ptr[1]<<16) | (ptr[2]<<8) | ptr[3]); - ptr += 4; - tdirection = ptr[0]; - ptr += 1; - - cksum.length = (ptr[0]<<8) | ptr[1]; - ptr += 2; - bodysize -= 11; - - if (cksum.length != bodysize) { - free(plain.data); - *minor_status = G_TOK_TRUNC; - return(GSS_S_DEFECTIVE_TOKEN); + if ((ptr[4] != 0xff) || (ptr[5] != 0xff)) { + *minor_status = 0; + return GSS_S_DEFECTIVE_TOKEN; } - cksum.contents = ptr; - cksum.checksum_type = tctype; + if ((toktype != KG_TOK_SEAL_MSG) && + (sealalg != 0xffff)) { + *minor_status = 0; + return GSS_S_DEFECTIVE_TOKEN; + } - /* finish assembling the checksum buffer and compute the checksum */ + /* in the current spec, there is only one valid seal algorithm per + key type, so a simple comparison is ok */ - plain.data[5] = (text->length >> 8) & 0xff; - plain.data[6] = text->length & 0xff; + if ((toktype == KG_TOK_SEAL_MSG) && + !((sealalg == 0xffff) || + (sealalg == ctx->sealalg))) { + *minor_status = 0; + return GSS_S_DEFECTIVE_TOKEN; + } - memcpy(plain.data+7, text->value, text->length); + /* there are several mappings of seal algorithms to sign algorithms, + but few enough that we can try them all. */ - if (code = krb5_c_verify_checksum(context, ctx->subkey, - KRB5_KEYUSAGE_GSS_TOK_MIC, - &plain, &cksum, &ckvalid)) { - free(plain.data); - *minor_status = code; - return(GSS_S_FAILURE); + if ((ctx->sealalg == SEAL_ALG_NONE && signalg > 1) || + (ctx->sealalg == SEAL_ALG_1 && signalg != SGN_ALG_3) || + (ctx->sealalg == SEAL_ALG_DES3KD && + signalg != SGN_ALG_HMAC_SHA1_DES3_KD)) { + *minor_status = 0; + return GSS_S_DEFECTIVE_TOKEN; } - if (!ckvalid) { - free(plain.data); + switch (signalg) { + case SGN_ALG_DES_MAC_MD5: + case SGN_ALG_MD2_5: + cksum_len = 8; + break; + case SGN_ALG_3: + cksum_len = 16; + break; + case SGN_ALG_HMAC_SHA1_DES3_KD: + cksum_len = 20; + break; + default: *minor_status = 0; - return(GSS_S_BAD_SIG); + return GSS_S_DEFECTIVE_TOKEN; } - /* check context expiry */ + if (toktype == KG_TOK_SEAL_MSG) + tmsglen = bodysize-(14+cksum_len); - if ((code = krb5_timeofday(context, &now))) { - free(plain.data); - *minor_status = code; - return(GSS_S_FAILURE); - } + /* get the token parameters */ - if (now > ctx->endtime) { - free(plain.data); - *minor_status = 0; - return(GSS_S_CONTEXT_EXPIRED); - } + /* decode the message, if SEAL */ - /* do sequencing checks */ + if (toktype == KG_TOK_SEAL_MSG) { + if (sealalg != 0xffff) { + if ((plain = (unsigned char *) xmalloc(tmsglen)) == NULL) { + *minor_status = ENOMEM; + return(GSS_S_FAILURE); + } - if ((ctx->initiate && tdirection != 0xff) || - (!ctx->initiate && tdirection != 0)) { - free(plain.data); - *minor_status = G_BAD_DIRECTION; - return(GSS_S_BAD_SIG); - } + if ((code = kg_decrypt(context, ctx->enc, KG_USAGE_SEAL, NULL, + ptr+14+cksum_len, plain, tmsglen))) { + xfree(plain); + *minor_status = code; + return(GSS_S_FAILURE); + } + } else { + plain = ptr+14+cksum_len; + } - retval = g_order_check(&(ctx->seqstate), tseqnum); + plainlen = tmsglen; - free(plain.data); + if ((sealalg == 0xffff) && ctx->big_endian) { + token.length = tmsglen; + } else { + conflen = kg_confounder_size(context, ctx->enc); + token.length = tmsglen - conflen - plain[tmsglen-1]; + } - if (retval) { - *minor_status = 0; - return(retval); - } + if (token.length) { + if ((token.value = (void *) xmalloc(token.length)) == NULL) { + if (sealalg != 0xffff) + xfree(plain); + *minor_status = ENOMEM; + return(GSS_S_FAILURE); + } + memcpy(token.value, plain+conflen, token.length); + } + } else if (toktype == KG_TOK_SIGN_MSG) { + token = *message_buffer; + plain = token.value; + plainlen = token.length; + } else { + token.length = 0; + token.value = NULL; + plain = token.value; + plainlen = token.length; + } - if (qop_state) - *qop_state = GSS_C_QOP_DEFAULT; + /* compute the checksum of the message */ + + /* initialize the the cksum */ + switch (signalg) { + case SGN_ALG_DES_MAC_MD5: + case SGN_ALG_MD2_5: + case SGN_ALG_HMAC_MD5: + case SGN_ALG_DES_MAC: + case SGN_ALG_3: + md5cksum.checksum_type = CKSUMTYPE_RSA_MD5; + break; + case SGN_ALG_HMAC_SHA1_DES3_KD: + md5cksum.checksum_type = CKSUMTYPE_HMAC_SHA1_DES3; + break; + default: + abort (); + } - *minor_status = 0; - return(GSS_S_COMPLETE); -} + if (code = krb5_c_checksum_length(context, md5cksum.checksum_type, &sumlen)) + return(code); + md5cksum.length = sumlen; -static OM_uint32 -kg2_unwrap_integ(context, minor_status, ctx, ptr, bodysize, output, qop_state) - krb5_context context; - OM_uint32 *minor_status; - krb5_gss_ctx_id_rec *ctx; - unsigned char *ptr; - int bodysize; - gss_buffer_t output; - gss_qop_t *qop_state; -{ - krb5_error_code code; - OM_uint32 retval; - krb5_ui_4 tseqnum; - int tdirection; - int tmsglen; - unsigned char *tmsg; - krb5_data plain; - krb5_checksum tcksum; - krb5_boolean ckvalid; - krb5_timestamp now; + switch (signalg) { + case SGN_ALG_DES_MAC_MD5: + case SGN_ALG_3: + /* compute the checksum of the message */ - output->length = 0; - output->value = NULL; + /* 8 = bytes of token body to be checksummed according to spec */ - /* read the body parts out of the message */ + if (! (data_ptr = (void *) + xmalloc(8 + (ctx->big_endian ? token.length : plainlen)))) { + if (sealalg != 0xffff) + xfree(plain); + if (toktype == KG_TOK_SEAL_MSG) + xfree(token.value); + *minor_status = ENOMEM; + return(GSS_S_FAILURE); + } - if (bodysize < 11) { - *minor_status = G_TOK_TRUNC; - return(GSS_S_DEFECTIVE_TOKEN); - } + (void) memcpy(data_ptr, ptr-2, 8); - tcksum.checksum_type = (krb5_cksumtype) ((ptr[0]<<24) | (ptr[1]<<16) | - (ptr[2]<<8) | ptr[3]); - ptr += 4; + if (ctx->big_endian) + (void) memcpy(data_ptr+8, token.value, token.length); + else + (void) memcpy(data_ptr+8, plain, plainlen); - plain.data = ptr; + plaind.length = 8 + (ctx->big_endian ? token.length : plainlen); + plaind.data = data_ptr; + code = krb5_c_make_checksum(context, md5cksum.checksum_type, + ctx->seq, KG_USAGE_SIGN, + &plaind, &md5cksum); + xfree(data_ptr); + + if (code) { + if (toktype == KG_TOK_SEAL_MSG) + xfree(token.value); + *minor_status = code; + return(GSS_S_FAILURE); + } - tseqnum = ((ptr[0]<<24) | (ptr[1]<<16) | (ptr[2]<<8) | ptr[3]); - ptr += 4; - tdirection = ptr[0]; - ptr += 1; + if ((code = kg_encrypt(context, ctx->seq, KG_USAGE_SEAL, + (g_OID_equal(ctx->mech_used, gss_mech_krb5_old) ? + ctx->seq->contents : NULL), + md5cksum.contents, md5cksum.contents, 16))) { + xfree(md5cksum.contents); + if (toktype == KG_TOK_SEAL_MSG) + xfree(token.value); + *minor_status = code; + return GSS_S_FAILURE; + } - tmsglen = (ptr[0]<<8) | ptr[1]; - ptr += 2; - bodysize -= 11; + if (signalg == 0) + cksum.length = 8; + else + cksum.length = 16; + cksum.contents = md5cksum.contents + 16 - cksum.length; - if (bodysize < tmsglen) { - *minor_status = G_TOK_TRUNC; - return(GSS_S_DEFECTIVE_TOKEN); - } + code = memcmp(cksum.contents, ptr+14, cksum.length); + break; - tmsg = ptr; - ptr += tmsglen; - bodysize -= tmsglen; + case SGN_ALG_MD2_5: + if (!ctx->seed_init && + (code = kg_make_seed(context, ctx->subkey, ctx->seed))) { + xfree(md5cksum.contents); + if (sealalg != 0xffff) + xfree(plain); + if (toktype == KG_TOK_SEAL_MSG) + xfree(token.value); + *minor_status = code; + return GSS_S_FAILURE; + } - plain.length = ((char*)ptr) - ((char *)plain.data); + if (! (data_ptr = (void *) + xmalloc(sizeof(ctx->seed) + 8 + + (ctx->big_endian ? token.length : plainlen)))) { + xfree(md5cksum.contents); + if (sealalg == 0) + xfree(plain); + if (toktype == KG_TOK_SEAL_MSG) + xfree(token.value); + *minor_status = ENOMEM; + return(GSS_S_FAILURE); + } + (void) memcpy(data_ptr, ptr-2, 8); + (void) memcpy(data_ptr+8, ctx->seed, sizeof(ctx->seed)); + if (ctx->big_endian) + (void) memcpy(data_ptr+8+sizeof(ctx->seed), + token.value, token.length); + else + (void) memcpy(data_ptr+8+sizeof(ctx->seed), + plain, plainlen); + plaind.length = 8 + sizeof(ctx->seed) + + (ctx->big_endian ? token.length : plainlen); + plaind.data = data_ptr; + xfree(md5cksum.contents); + code = krb5_c_make_checksum(context, md5cksum.checksum_type, + ctx->seq, KG_USAGE_SIGN, + &plaind, &md5cksum); + xfree(data_ptr); + + if (code) { + if (sealalg == 0) + xfree(plain); + if (toktype == KG_TOK_SEAL_MSG) + xfree(token.value); + *minor_status = code; + return(GSS_S_FAILURE); + } - tcksum.length = (ptr[0]<<8) | ptr[1]; - ptr += 2; - bodysize -= 2; + code = memcmp(md5cksum.contents, ptr+14, 8); + /* Falls through to defective-token?? */ - if (bodysize != tcksum.length) { - *minor_status = G_TOK_TRUNC; + default: + *minor_status = 0; return(GSS_S_DEFECTIVE_TOKEN); - } - - tcksum.contents = ptr; - /* verify the MIC */ + case SGN_ALG_HMAC_SHA1_DES3_KD: + /* compute the checksum of the message */ - if (code = krb5_c_verify_checksum(context, ctx->subkey, - KRB5_KEYUSAGE_GSS_TOK_WRAP_INTEG, - &plain, &tcksum, &ckvalid)) { - *minor_status = code; - return(GSS_S_FAILURE); - } + /* 8 = bytes of token body to be checksummed according to spec */ - if (!ckvalid) { - *minor_status = 0; - return(GSS_S_BAD_SIG); - } + if (! (data_ptr = (void *) + xmalloc(8 + (ctx->big_endian ? token.length : plainlen)))) { + if (sealalg != 0xffff) + xfree(plain); + if (toktype == KG_TOK_SEAL_MSG) + xfree(token.value); + *minor_status = ENOMEM; + return(GSS_S_FAILURE); + } - /* check context expiry */ - - if ((code = krb5_timeofday(context, &now))) { - *minor_status = code; - return(GSS_S_FAILURE); - } - - if (now > ctx->endtime) { - *minor_status = 0; - return(GSS_S_CONTEXT_EXPIRED); - } - - /* do sequencing checks */ - - if ((ctx->initiate && tdirection != 0xff) || - (!ctx->initiate && tdirection != 0)) { - *minor_status = G_BAD_DIRECTION; - return(GSS_S_BAD_SIG); - } - - if (retval = g_order_check(&(ctx->seqstate), tseqnum)) { - *minor_status = 0; - return(retval); - } - - if (tmsglen) { - if ((output->value = (void *) malloc(tmsglen)) == NULL) { - *minor_status = ENOMEM; - return(GSS_S_FAILURE); - } - memcpy(output->value, tmsg, tmsglen); - output->length = tmsglen; - } - - if (qop_state) - *qop_state = GSS_C_QOP_DEFAULT; - - *minor_status = 0; - return(GSS_S_COMPLETE); -} + (void) memcpy(data_ptr, ptr-2, 8); -static OM_uint32 -kg2_unwrap_priv(context, minor_status, ctx, ptr, bodysize, output, qop_state) - krb5_context context; - OM_uint32 *minor_status; - krb5_gss_ctx_id_rec *ctx; - unsigned char *ptr; - int bodysize; - gss_buffer_t output; - gss_qop_t *qop_state; -{ - krb5_error_code code; - OM_uint32 retval; - krb5_enc_data cipher; - krb5_data plain; - krb5_ui_4 tseqnum; - int tdirection; - int tmsglen; - unsigned char *tmsg; - krb5_timestamp now; + if (ctx->big_endian) + (void) memcpy(data_ptr+8, token.value, token.length); + else + (void) memcpy(data_ptr+8, plain, plainlen); - output->length = 0; - output->value = NULL; + plaind.length = 8 + (ctx->big_endian ? token.length : plainlen); + plaind.data = data_ptr; + code = krb5_c_make_checksum(context, md5cksum.checksum_type, + ctx->seq, KG_USAGE_SIGN, + &plaind, &md5cksum); + xfree(data_ptr); - /* read the body parts out of the message */ + if (code) { + if (toktype == KG_TOK_SEAL_MSG) + xfree(token.value); + *minor_status = code; + return(GSS_S_FAILURE); + } - if (bodysize < 2) { - *minor_status = G_TOK_TRUNC; - return(GSS_S_DEFECTIVE_TOKEN); + code = memcmp(md5cksum.contents, ptr+14, md5cksum.length); + break; } - cipher.ciphertext.length = (ptr[0]<<8) | ptr[1]; - ptr += 2; - bodysize -= 2; + xfree(md5cksum.contents); + if (sealalg != 0xffff) + xfree(plain); - if (bodysize != cipher.ciphertext.length) { - *minor_status = G_TOK_TRUNC; - return(GSS_S_DEFECTIVE_TOKEN); - } + /* compare the computed checksum against the transmitted checksum */ - cipher.ciphertext.data = ptr; - cipher.enctype = ENCTYPE_UNKNOWN; - - plain.length = cipher.ciphertext.length; - if ((plain.data = (char *) malloc(plain.length)) == NULL) { + if (code) { + if (toktype == KG_TOK_SEAL_MSG) + xfree(token.value); *minor_status = 0; - return(GSS_S_FAILURE); - } - - /* decrypt (and implicitly verify) the encrypted data */ - - if (code = krb5_c_decrypt(context, ctx->subkey, - KRB5_KEYUSAGE_GSS_TOK_WRAP_PRIV, - 0, &cipher, &plain)) { - free(plain.data); - *minor_status = code; - return(GSS_S_FAILURE); + return(GSS_S_BAD_SIG); } - /* parse out the encrypted fields */ - ptr = plain.data; - bodysize = plain.length; + /* it got through unscathed. Make sure the context is unexpired */ - if (bodysize < 7) { - free(plain.data); - *minor_status = G_TOK_TRUNC; - return(GSS_S_DEFECTIVE_TOKEN); - } + if (toktype == KG_TOK_SEAL_MSG) + *message_buffer = token; - tseqnum = ((ptr[0]<<24) | (ptr[1]<<16) | (ptr[2]<<8) | ptr[3]); - ptr += 4; - tdirection = ptr[0]; - ptr += 1; + if (conf_state) + *conf_state = (sealalg != 0xffff); - tmsglen = (ptr[0]<<8) | ptr[1]; - ptr += 2; - bodysize -= 7; - - /* check context expiry */ + if (qop_state) + *qop_state = GSS_C_QOP_DEFAULT; if ((code = krb5_timeofday(context, &now))) { - free(plain.data); *minor_status = code; return(GSS_S_FAILURE); } if (now > ctx->endtime) { - free(plain.data); *minor_status = 0; return(GSS_S_CONTEXT_EXPIRED); } /* do sequencing checks */ - if ((ctx->initiate && tdirection != 0xff) || - (!ctx->initiate && tdirection != 0)) { - free(plain.data); - *minor_status = G_BAD_DIRECTION; + if ((code = kg_get_seq_num(context, ctx->seq, ptr+14, ptr+6, &direction, + &seqnum))) { + if (toktype == KG_TOK_SEAL_MSG) + xfree(token.value); + *minor_status = code; return(GSS_S_BAD_SIG); } - if (retval = g_order_check(&(ctx->seqstate), tseqnum)) { - free(plain.data); - *minor_status = 0; - return(retval); - } - - /* now copy out the data. can't do a strict equality check here, - since the output could be padded. */ - - if (bodysize < tmsglen) { - free(plain.data); - *minor_status = G_TOK_TRUNC; - return(GSS_S_DEFECTIVE_TOKEN); - } - - tmsg = ptr; - - if (tmsglen) { - if ((output->value = (void *) malloc(tmsglen)) == NULL) { - free(plain.data); - *minor_status = ENOMEM; - return(GSS_S_FAILURE); - } - memcpy(output->value, tmsg, tmsglen); - output->length = tmsglen; + if ((ctx->initiate && direction != 0xff) || + (!ctx->initiate && direction != 0)) { + if (toktype == KG_TOK_SEAL_MSG) + xfree(token.value); + *minor_status = G_BAD_DIRECTION; + return(GSS_S_BAD_SIG); } - if (qop_state) - *qop_state = GSS_C_QOP_DEFAULT; + retval = g_order_check(&(ctx->seqstate), seqnum); - free(plain.data); + /* success or ordering violation */ *minor_status = 0; - return(GSS_S_COMPLETE); + return(retval); } /* message_buffer is an input if SIGN, output if SEAL, and ignored if DEL_CTX conf_state is only valid if SEAL. */ OM_uint32 -kg_unseal_v1(context, minor_status, ctx, ptr, bodysize, message_buffer, - conf_state, qop_state, toktype) - krb5_context context; - OM_uint32 *minor_status; - krb5_gss_ctx_id_rec *ctx; - unsigned char *ptr; - int bodysize; - gss_buffer_t message_buffer; - int *conf_state; - int *qop_state; - int toktype; +kg_unseal(context, minor_status, context_handle, input_token_buffer, + message_buffer, conf_state, qop_state, toktype) + krb5_context context; + OM_uint32 *minor_status; + gss_ctx_id_t context_handle; + gss_buffer_t input_token_buffer; + gss_buffer_t message_buffer; + int *conf_state; + int *qop_state; + int toktype; { - krb5_error_code code; - int tmsglen; - int conflen = 0; - int signalg; - int sealalg; - gss_buffer_desc token; - krb5_checksum cksum; - krb5_checksum desmac; - krb5_checksum md5cksum; - krb5_data plaind; - char *data_ptr; - krb5_timestamp now; - unsigned char *plain; - int cksum_len = 0; - int plainlen; - int err; - int direction; - krb5_int32 seqnum; - OM_uint32 retval; - size_t sumlen; - - if (toktype == KG_TOK_SEAL_MSG) { - message_buffer->length = 0; - message_buffer->value = NULL; - } - - /* get the sign and seal algorithms */ - - signalg = ptr[0] + (ptr[1]<<8); - sealalg = ptr[2] + (ptr[3]<<8); - - /* Sanity checks */ - - if ((ptr[4] != 0xff) || (ptr[5] != 0xff)) { - *minor_status = 0; - return GSS_S_DEFECTIVE_TOKEN; - } - - if ((toktype != KG_TOK_SEAL_MSG) && - (sealalg != 0xffff)) { - *minor_status = 0; - return GSS_S_DEFECTIVE_TOKEN; - } - - /* in the current spec, there is only one valid seal algorithm per - key type, so a simple comparison is ok */ - - if ((toktype == KG_TOK_SEAL_MSG) && - !((sealalg == 0xffff) || - (sealalg == ctx->sealalg))) { - *minor_status = 0; - return GSS_S_DEFECTIVE_TOKEN; - } - - /* there are several mappings of seal algorithms to sign algorithms, - but few enough that we can try them all. */ - - if (((ctx->sealalg == 0) && - (signalg > 1)) || - ((ctx->sealalg == 1) && - (signalg != 3))) { - *minor_status = 0; - return GSS_S_DEFECTIVE_TOKEN; - } - - switch (signalg) { - case 0: - case 1: - cksum_len = 8; - break; - case 3: - cksum_len = 16; - break; - } - - if (toktype == KG_TOK_SEAL_MSG) - tmsglen = bodysize-(14+cksum_len); - - /* get the token parameters */ - - /* decode the message, if SEAL */ - - if (toktype == KG_TOK_SEAL_MSG) { - if (sealalg != 0xffff) { - if ((plain = (unsigned char *) xmalloc(tmsglen)) == NULL) { - *minor_status = ENOMEM; - return(GSS_S_FAILURE); - } + krb5_gss_ctx_id_rec *ctx; + unsigned char *ptr; + int bodysize; + int err; + + /* validate the context handle */ + if (! kg_validate_ctx_id(context_handle)) { + *minor_status = (OM_uint32) G_VALIDATE_FAILED; + return(GSS_S_NO_CONTEXT); + } - if ((code = kg_decrypt(context, ctx->enc, NULL, - ptr+14+cksum_len, plain, tmsglen))) { - xfree(plain); - *minor_status = code; - return(GSS_S_FAILURE); - } - } else { - plain = ptr+14+cksum_len; - } - - plainlen = tmsglen; - - if ((sealalg == 0xffff) && ctx->big_endian) { - token.length = tmsglen; - } else { - conflen = kg_confounder_size(context, ctx->enc); - token.length = tmsglen - conflen - plain[tmsglen-1]; - } - - if (token.length) { - if ((token.value = (void *) xmalloc(token.length)) == NULL) { - if (sealalg != 0xffff) - xfree(plain); - *minor_status = ENOMEM; - return(GSS_S_FAILURE); - } - memcpy(token.value, plain+conflen, token.length); - } - } else if (toktype == KG_TOK_SIGN_MSG) { - token = *message_buffer; - plain = token.value; - plainlen = token.length; - } else { - token.length = 0; - token.value = NULL; - plain = token.value; - plainlen = token.length; - } - - /* compute the checksum of the message */ - - /* initialize the the cksum */ - if (code = krb5_c_checksum_length(context, CKSUMTYPE_RSA_MD5, &sumlen)) - return(code); - - md5cksum.checksum_type = CKSUMTYPE_RSA_MD5; - md5cksum.length = sumlen; - - switch (signalg) { - case 0: - case 3: - /* compute the checksum of the message */ - - /* 8 = bytes of token body to be checksummed according to spec */ - - if (! (data_ptr = (void *) - xmalloc(8 + (ctx->big_endian ? token.length : plainlen)))) { - if (sealalg != 0xffff) - xfree(plain); - if (toktype == KG_TOK_SEAL_MSG) - xfree(token.value); - *minor_status = ENOMEM; - return(GSS_S_FAILURE); - } - - (void) memcpy(data_ptr, ptr-2, 8); - - if (ctx->big_endian) - (void) memcpy(data_ptr+8, token.value, token.length); - else - (void) memcpy(data_ptr+8, plain, plainlen); - - plaind.length = 8 + (ctx->big_endian ? token.length : plainlen); - plaind.data = data_ptr; - code = krb5_c_make_checksum(context, md5cksum.checksum_type, 0, 0, - &plaind, &md5cksum); - xfree(data_ptr); - - if (code) { - if (toktype == KG_TOK_SEAL_MSG) - xfree(token.value); - *minor_status = code; - return(GSS_S_FAILURE); - } - -#if 0 - /* XXX this depends on the key being a single-des key, but that's - all that kerberos supports right now */ - - /* initialize the the cksum and allocate the contents buffer */ - cksum.checksum_type = CKSUMTYPE_DESCBC; - cksum.length = krb5_checksum_size(context, CKSUMTYPE_DESCBC); - if ((cksum.contents = (krb5_octet *) xmalloc(cksum.length)) == NULL) { - xfree(md5cksum.contents); - if (toktype == KG_TOK_SEAL_MSG) - xfree(token.value); - *minor_status = ENOMEM; - return(GSS_S_FAILURE); - } - - /* XXX not converted to new api since it's inside an #if 0 */ - if (code = krb5_calculate_checksum(context, cksum.checksum_type, - md5cksum.contents, 16, - ctx->seq.key->contents, - ctx->seq.key->length, - &cksum)) { - xfree(cksum.contents); - xfree(md5cksum.contents); - if (toktype == KG_TOK_SEAL_MSG) - xfree(token.value); - *minor_status = code; - return(GSS_S_FAILURE); - } - - code = memcmp(cksum.contents, ptr+14, cksum.length); - - xfree(cksum.contents); -#else - if ((code = kg_encrypt(context, ctx->seq, - (g_OID_equal(ctx->mech_used, gss_mech_krb5_old) ? - ctx->seq->contents : NULL), - md5cksum.contents, md5cksum.contents, 16))) { - xfree(md5cksum.contents); - if (toktype == KG_TOK_SEAL_MSG) - xfree(token.value); - *minor_status = code; - return GSS_S_FAILURE; - } - - if (signalg == 0) - cksum.length = 8; - else - cksum.length = 16; - cksum.contents = md5cksum.contents + 16 - cksum.length; - - code = memcmp(cksum.contents, ptr+14, cksum.length); -#endif - break; - - case 1: - if (!ctx->seed_init && - (code = kg_make_seed(context, ctx->subkey, ctx->seed))) { - xfree(md5cksum.contents); - if (sealalg != 0xffff) - xfree(plain); - if (toktype == KG_TOK_SEAL_MSG) - xfree(token.value); - *minor_status = code; - return GSS_S_FAILURE; - } - - if (! (data_ptr = (void *) - xmalloc(sizeof(ctx->seed) + 8 + - (ctx->big_endian ? token.length : plainlen)))) { - xfree(md5cksum.contents); - if (sealalg == 0) - xfree(plain); - if (toktype == KG_TOK_SEAL_MSG) - xfree(token.value); - *minor_status = ENOMEM; - return(GSS_S_FAILURE); - } - (void) memcpy(data_ptr, ptr-2, 8); - (void) memcpy(data_ptr+8, ctx->seed, sizeof(ctx->seed)); - if (ctx->big_endian) - (void) memcpy(data_ptr+8+sizeof(ctx->seed), - token.value, token.length); - else - (void) memcpy(data_ptr+8+sizeof(ctx->seed), - plain, plainlen); - plaind.length = 8 + sizeof(ctx->seed) + - (ctx->big_endian ? token.length : plainlen); - plaind.data = data_ptr; - xfree(md5cksum.contents); - code = krb5_c_make_checksum(context, md5cksum.checksum_type, 0, 0, - &plaind, &md5cksum); - xfree(data_ptr); - - if (code) { - if (sealalg == 0) - xfree(plain); - if (toktype == KG_TOK_SEAL_MSG) - xfree(token.value); - *minor_status = code; - return(GSS_S_FAILURE); - } - - code = memcmp(md5cksum.contents, ptr+14, 8); - - default: - *minor_status = 0; - return(GSS_S_DEFECTIVE_TOKEN); - } - - xfree(md5cksum.contents); - if (sealalg != 0xffff) - xfree(plain); - - /* compare the computed checksum against the transmitted checksum */ - - if (code) { - if (toktype == KG_TOK_SEAL_MSG) - xfree(token.value); - *minor_status = 0; - return(GSS_S_BAD_SIG); - } - - - /* it got through unscathed. Make sure the context is unexpired */ - - if (toktype == KG_TOK_SEAL_MSG) - *message_buffer = token; - - if (conf_state) - *conf_state = (sealalg != 0xffff); - - if (qop_state) - *qop_state = GSS_C_QOP_DEFAULT; - - if ((code = krb5_timeofday(context, &now))) { - *minor_status = code; - return(GSS_S_FAILURE); - } - - if (now > ctx->endtime) { - *minor_status = 0; - return(GSS_S_CONTEXT_EXPIRED); - } - - /* do sequencing checks */ - - if ((code = kg_get_seq_num(context, ctx->seq, ptr+14, ptr+6, &direction, - &seqnum))) { - if (toktype == KG_TOK_SEAL_MSG) - xfree(token.value); - *minor_status = code; - return(GSS_S_BAD_SIG); - } - - if ((ctx->initiate && direction != 0xff) || - (!ctx->initiate && direction != 0)) { - if (toktype == KG_TOK_SEAL_MSG) - xfree(token.value); - *minor_status = G_BAD_DIRECTION; - return(GSS_S_BAD_SIG); - } - - retval = g_order_check(&(ctx->seqstate), seqnum); - - /* success or ordering violation */ - - *minor_status = 0; - return(retval); -} + ctx = (krb5_gss_ctx_id_rec *) context_handle; -/* message_buffer is an input if SIGN, output if SEAL, and ignored if DEL_CTX - conf_state is only valid if SEAL. */ + if (! ctx->established) { + *minor_status = KG_CTX_INCOMPLETE; + return(GSS_S_NO_CONTEXT); + } -OM_uint32 -kg_unseal(context, minor_status, context_handle, input_token_buffer, - message_buffer, conf_state, qop_state, toktype) - krb5_context context; - OM_uint32 *minor_status; - gss_ctx_id_t context_handle; - gss_buffer_t input_token_buffer; - gss_buffer_t message_buffer; - int *conf_state; - int *qop_state; - int toktype; -{ - krb5_gss_ctx_id_rec *ctx; - unsigned char *ptr; - int bodysize; - int err; - OM_uint32 retval; - - /* validate the context handle */ - if (! kg_validate_ctx_id(context_handle)) { - *minor_status = (OM_uint32) G_VALIDATE_FAILED; - return(GSS_S_NO_CONTEXT); - } - - ctx = (krb5_gss_ctx_id_rec *) context_handle; - - if (! ctx->established) { - *minor_status = KG_CTX_INCOMPLETE; - return(GSS_S_NO_CONTEXT); - } - - /* parse the token, leave the data in message_buffer, setting conf_state */ - - /* verify the header */ - - ptr = (unsigned char *) input_token_buffer->value; - - if (ctx->gsskrb5_version == 2000) { - if (!(err = g_verify_token_header((gss_OID) ctx->mech_used, - &bodysize, &ptr, KG2_TOK_MIC, - input_token_buffer->length))) { - return(kg2_verify_mic(context, minor_status, ctx, ptr, bodysize, - message_buffer, qop_state)); - } else if (!(err = g_verify_token_header((gss_OID) ctx->mech_used, - &bodysize, &ptr, - KG2_TOK_WRAP_INTEG, - input_token_buffer->length))) { - if (GSS_ERROR(retval = kg2_unwrap_integ(context, minor_status, - ctx, ptr, bodysize, - message_buffer, qop_state))) - return(retval); - - if (conf_state) - *conf_state = 0; - return(GSS_S_COMPLETE); - } else if (!(err = g_verify_token_header((gss_OID) ctx->mech_used, - &bodysize, &ptr, - KG2_TOK_WRAP_PRIV, - input_token_buffer->length))) { - if (GSS_ERROR(retval = kg2_unwrap_priv(context, minor_status, - ctx, ptr, bodysize, - message_buffer, qop_state))) - return(retval); - - if (conf_state) - *conf_state = 1; - return(GSS_S_COMPLETE); - } - } else { - if (!(err = g_verify_token_header((gss_OID) ctx->mech_used, - &bodysize, &ptr, toktype, - input_token_buffer->length))) { - return(kg_unseal_v1(context, minor_status, ctx, ptr, bodysize, - message_buffer, conf_state, qop_state, - toktype)); - } - } - - *minor_status = err; - return(GSS_S_DEFECTIVE_TOKEN); + /* parse the token, leave the data in message_buffer, setting conf_state */ + + /* verify the header */ + + ptr = (unsigned char *) input_token_buffer->value; + + if (!(err = g_verify_token_header((gss_OID) ctx->mech_used, + &bodysize, &ptr, toktype, + input_token_buffer->length))) { + return(kg_unseal_v1(context, minor_status, ctx, ptr, bodysize, + message_buffer, conf_state, qop_state, + toktype)); + } + + *minor_status = err; + return(GSS_S_DEFECTIVE_TOKEN); } diff --git a/src/lib/gssapi/krb5/ser_sctx.c b/src/lib/gssapi/krb5/ser_sctx.c index 2a6231e..781e8ee 100644 --- a/src/lib/gssapi/krb5/ser_sctx.c +++ b/src/lib/gssapi/krb5/ser_sctx.c @@ -155,7 +155,6 @@ kg_queue_internalize(kcontext, argp, buffer, lenremain) size_t *lenremain; { krb5_error_code kret; - gss_OID oid; krb5_int32 ibuf; krb5_octet *bp; size_t remain; @@ -233,7 +232,6 @@ kg_ctx_size(kcontext, arg, sizep) * krb5_int32 for seq_recv. * krb5_int32 for established. * krb5_int32 for big_endian. - * krb5_int32 for gsskrb5_version. * krb5_int32 for nctypes. * krb5_int32 for trailer. */ @@ -349,8 +347,6 @@ kg_ctx_externalize(kcontext, arg, buffer, lenremain) &bp, &remain); (void) krb5_ser_pack_int32((krb5_int32) ctx->big_endian, &bp, &remain); - (void) krb5_ser_pack_int32((krb5_int32) ctx->gsskrb5_version, - &bp, &remain); (void) krb5_ser_pack_int32((krb5_int32) ctx->nctypes, &bp, &remain); @@ -477,8 +473,6 @@ kg_ctx_internalize(kcontext, argp, buffer, lenremain) (void) krb5_ser_unpack_int32(&ibuf, &bp, &remain); ctx->big_endian = (int) ibuf; (void) krb5_ser_unpack_int32(&ibuf, &bp, &remain); - ctx->gsskrb5_version = (int) ibuf; - (void) krb5_ser_unpack_int32(&ibuf, &bp, &remain); ctx->nctypes = (int) ibuf; if ((kret = kg_oid_internalize(kcontext, &ctx->mech_used, &bp, diff --git a/src/lib/gssapi/krb5/util_cksum.c b/src/lib/gssapi/krb5/util_cksum.c index 10e6b65..47ffc5b 100644 --- a/src/lib/gssapi/krb5/util_cksum.c +++ b/src/lib/gssapi/krb5/util_cksum.c @@ -27,6 +27,7 @@ #include "gssapiP_krb5.h" #include +/* Checksumming the channel bindings always uses plain MD5. */ krb5_error_code kg_checksum_channel_bindings(context, cb, cksum, bigend) krb5_context context; diff --git a/src/lib/gssapi/krb5/util_crypt.c b/src/lib/gssapi/krb5/util_crypt.c index 93d4694..33562bc 100644 --- a/src/lib/gssapi/krb5/util_crypt.c +++ b/src/lib/gssapi/krb5/util_crypt.c @@ -54,8 +54,6 @@ * $Id$ */ -static unsigned char zeros[8] = {0,0,0,0,0,0,0,0}; - int kg_confounder_size(context, key) krb5_context context; @@ -105,9 +103,10 @@ kg_encrypt_size(context, key, n) } krb5_error_code -kg_encrypt(context, key, iv, in, out, length) +kg_encrypt(context, key, usage, iv, in, out, length) krb5_context context; krb5_keyblock *key; + int usage; krb5_pointer iv; krb5_pointer in; krb5_pointer out; @@ -123,7 +122,10 @@ kg_encrypt(context, key, iv, in, out, length) return(code); ivd.length = blocksize; - ivd.data = iv; + ivd.data = malloc(ivd.length); + if (ivd.data == NULL) + return ENOMEM; + memcpy(ivd.data, iv, ivd.length); pivd = &ivd; } else { pivd = NULL; @@ -135,25 +137,26 @@ kg_encrypt(context, key, iv, in, out, length) outputd.ciphertext.length = length; outputd.ciphertext.data = out; - return(krb5_c_encrypt(context, key, - /* XXX this routine is only used for the old - bare-des stuff which doesn't use the - key usage */ 0, pivd, &inputd, &outputd)); + code = krb5_c_encrypt(context, key, usage, pivd, &inputd, &outputd); + if (pivd != NULL) + krb5_free_data_contents(context, pivd); + return code; } /* length is the length of the cleartext. */ krb5_error_code -kg_decrypt(context, key, iv, in, out, length) +kg_decrypt(context, key, usage, iv, in, out, length) krb5_context context; krb5_keyblock *key; + int usage; krb5_pointer iv; krb5_pointer in; krb5_pointer out; int length; { krb5_error_code code; - size_t blocksize, enclen; + size_t blocksize; krb5_data ivd, *pivd, outputd; krb5_enc_data inputd; @@ -162,7 +165,10 @@ kg_decrypt(context, key, iv, in, out, length) return(code); ivd.length = blocksize; - ivd.data = iv; + ivd.data = malloc(ivd.length); + if (ivd.data == NULL) + return ENOMEM; + memcpy(ivd.data, iv, ivd.length); pivd = &ivd; } else { pivd = NULL; @@ -175,8 +181,8 @@ kg_decrypt(context, key, iv, in, out, length) outputd.length = length; outputd.data = out; - return(krb5_c_decrypt(context, key, - /* XXX this routine is only used for the old - bare-des stuff which doesn't use the - key usage */ 0, pivd, &inputd, &outputd)); + code = krb5_c_decrypt(context, key, usage, pivd, &inputd, &outputd); + if (pivd != NULL) + krb5_free_data_contents(context, pivd); + return code; } diff --git a/src/lib/gssapi/krb5/util_seed.c b/src/lib/gssapi/krb5/util_seed.c index 206ee68..b4a9044 100644 --- a/src/lib/gssapi/krb5/util_seed.c +++ b/src/lib/gssapi/krb5/util_seed.c @@ -47,7 +47,7 @@ kg_make_seed(context, key, seed) for (i=0; ilength; i++) tmpkey->contents[i] = key->contents[key->length - 1 - i]; - code = kg_encrypt(context, tmpkey, NULL, zeros, seed, 16); + code = kg_encrypt(context, tmpkey, KG_USAGE_SEAL, NULL, zeros, seed, 16); krb5_free_keyblock(context, tmpkey); diff --git a/src/lib/gssapi/krb5/util_seqnum.c b/src/lib/gssapi/krb5/util_seqnum.c index e14b2f3..b8f2b38 100644 --- a/src/lib/gssapi/krb5/util_seqnum.c +++ b/src/lib/gssapi/krb5/util_seqnum.c @@ -47,7 +47,7 @@ kg_make_seq_num(context, key, direction, seqnum, cksum, buf) plain[6] = direction; plain[7] = direction; - return(kg_encrypt(context, key, cksum, plain, buf, 8)); + return(kg_encrypt(context, key, KG_USAGE_SEQ, cksum, plain, buf, 8)); } krb5_error_code kg_get_seq_num(context, key, cksum, buf, direction, seqnum) @@ -61,7 +61,7 @@ krb5_error_code kg_get_seq_num(context, key, cksum, buf, direction, seqnum) krb5_error_code code; unsigned char plain[8]; - if (code = kg_decrypt(context, key, cksum, buf, plain, 8)) + if (code = kg_decrypt(context, key, KG_USAGE_SEQ, cksum, buf, plain, 8)) return(code); if ((plain[4] != plain[5]) || diff --git a/src/lib/gssapi/krb5/wrap_size_limit.c b/src/lib/gssapi/krb5/wrap_size_limit.c index f7fee73..1f2db4a 100644 --- a/src/lib/gssapi/krb5/wrap_size_limit.c +++ b/src/lib/gssapi/krb5/wrap_size_limit.c @@ -1,4 +1,28 @@ /* + * Copyright 2000 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. + * + */ +/* * Copyright 1993 by OpenVision Technologies, Inc. * * Permission to use, copy, modify, distribute, and sell this software @@ -65,7 +89,9 @@ krb5_gss_wrap_size_limit(minor_status, context_handle, conf_req_flag, { krb5_context context; krb5_gss_ctx_id_rec *ctx; - krb5_error_code code; + OM_uint32 data_size, conflen; + OM_uint32 ohlen; + int overhead; if (GSS_ERROR(kg_get_context(minor_status, &context))) return(GSS_S_FAILURE); @@ -88,92 +114,23 @@ krb5_gss_wrap_size_limit(minor_status, context_handle, conf_req_flag, return(GSS_S_NO_CONTEXT); } - if (ctx->gsskrb5_version == 2000) { - if (conf_req_flag) { - /* this is pretty gross. take the max output, and call - krb5_c_encrypt_length to see how much overhead is added - on. subtract that much, and see if it fits in the - requested space. If not, start subtracting 1 until it - does. This doesn't necessarily give us the optimal - packing, but I think that's ok (I could start adding 1 - until I went over, but that seems like it's not worth - the effort). This is probably O(blocksize), but that's - never going to be large. */ - - OM_uint32 headerlen, plainlen; - size_t enclen; - - headerlen = g_token_size((gss_OID) ctx->mech_used, 2); - plainlen = req_output_size - headerlen; - - if (code = krb5_c_encrypt_length(context, ctx->enc->enctype, - plainlen, &enclen)) { - *minor_status = code; - return(GSS_S_FAILURE); - } - - plainlen -= plainlen - (enclen - plainlen); - - if (code = krb5_c_encrypt_length(context, ctx->enc->enctype, - plainlen, &enclen)) { - *minor_status = code; - return(GSS_S_FAILURE); - } - - while (headerlen + enclen > req_output_size) { - plainlen--; - - if (code = krb5_c_encrypt_length(context, ctx->enc->enctype, - plainlen, &enclen)) { - *minor_status = code; - return(GSS_S_FAILURE); - } - } - - /* subtract off the fixed size inside the encrypted part */ - - plainlen -= 7; - - *max_input_size = plainlen; - } else { - size_t cksumlen; - OM_uint32 headerlen; - - if (code = krb5_c_checksum_length(context, ctx->ctypes[0], - &cksumlen)) { - *minor_status = code; - return(GSS_S_FAILURE); - } - - headerlen = g_token_size((gss_OID) ctx->mech_used, 13 + cksumlen); - - *max_input_size = req_output_size - headerlen; - } - } else { - OM_uint32 data_size, conflen; - OM_uint32 ohlen; - int overhead; - - /* Calculate the token size and subtract that from the output size */ - overhead = 7 + ctx->mech_used->length; - data_size = req_output_size; - if (conf_req_flag) { - conflen = kg_confounder_size(context, ctx->enc); - data_size = (conflen + data_size + 8) & (~7); - } - ohlen = g_token_size((gss_OID) ctx->mech_used, - (unsigned int) (data_size + ctx->cksum_size + 14)) - - req_output_size; - - if (ohlen+overhead < req_output_size) - /* - * Cannot have trailer length that will cause us to pad over - * our length - */ - *max_input_size = (req_output_size - ohlen - overhead) & (~7); - else - *max_input_size = 0; - } + /* Calculate the token size and subtract that from the output size */ + overhead = 7 + ctx->mech_used->length; + data_size = req_output_size; + conflen = kg_confounder_size(context, ctx->enc); + data_size = (conflen + data_size + 8) & (~(OM_uint32)7); + ohlen = g_token_size((gss_OID) ctx->mech_used, + (unsigned int) (data_size + ctx->cksum_size + 14)) + - req_output_size; + + if (ohlen+overhead < req_output_size) + /* + * Cannot have trailer length that will cause us to pad over our + * length. + */ + *max_input_size = (req_output_size - ohlen - overhead) & (~(OM_uint32)7); + else + *max_input_size = 0; *minor_status = 0; return(GSS_S_COMPLETE); diff --git a/src/lib/gssapi32.def b/src/lib/gssapi32.def index 5132ea4..3a43be2 100644 --- a/src/lib/gssapi32.def +++ b/src/lib/gssapi32.def @@ -72,7 +72,7 @@ EXPORTS ; ; GSS-API variables ; - gss_nt_user_name - gss_nt_machine_uid_name - gss_nt_string_uid_name - gss_nt_service_name + gss_nt_user_name DATA + gss_nt_machine_uid_name DATA + gss_nt_string_uid_name DATA + gss_nt_service_name DATA diff --git a/src/lib/kadm5/ChangeLog b/src/lib/kadm5/ChangeLog index 8706ec0..54e1bc5 100644 --- a/src/lib/kadm5/ChangeLog +++ b/src/lib/kadm5/ChangeLog @@ -1,3 +1,56 @@ +2002-02-05 Ken Raeburn + + * kadm_rpc_xdr.c (xdr_krb5_kvno): Disable previous change. + +2002-01-25 Ken Raeburn + + * kadm_rpc_xdr.c (xdr_krb5_kvno): Return an error if the key + version number won't fit in the one-byte encoding we currently + use. + +2001-10-31 Ezra Peisach + + * str_conv.c (krb5_string_to_keysalts): When parsing string, allow + for extra separator characters (like spaces) between keysalts. + [pullup 1.7->1.8 from trunk] + +2001-09-25 Ken Raeburn + + * admin.h (krb5_realm_params): Add fields realm_reject_bad_transit + and realm_reject_bad_transit_valid; delete field realm_filler. + * alt_prof.c (string_to_boolean, krb5_aprof_get_boolean): New + functions. + (krb5_read_realm_params): Parse "reject_bad_transit" value as + boolean and save it. + +2001-09-07 Tom Yu + + * adb.h: Add btinfo. [pullup from trunk] + +2000-05-31 Ken Raeburn + + * alt_prof.c (kadm5_get_config_params): Include des3 in supported + enctypes by default. + +2000-05-19 Ken Raeburn + + * ovsec_glue.c (ovsec_kadm_chpass_principal_util): Use 1024 for + hard-coded length, to match existing callers. + +2000-05-11 Nalin Dahyabhai + + * admin.h: Add a length parameter to kadm5_chpass_principal_util(). + * admin_internal.h: Add a length parameter to + _kadm5_chpass_principal_util(). + * chpass_util.c (_kadm5_chpass_principal_util): Add a length parameter, + and use it to avoid overflowing "msg_ret". + * ovsec_glue.c (ovsec_kadm_chpass_principal_util): Adjust for new + parameter in kadm5_chpass_principal_util(). + +2000-05-01 Nalin Dahyabhai + + * logger.c (klog_com_err_proc): Don't overflow buffer "outbuf". + 2000-02-26 Tom Yu * kadm_rpc_xdr.c (xdr_cprinc3_arg): Don't XDR the nonexistent diff --git a/src/lib/kadm5/adb.h b/src/lib/kadm5/adb.h index ce0d600..81ff96c 100644 --- a/src/lib/kadm5/adb.h +++ b/src/lib/kadm5/adb.h @@ -44,6 +44,7 @@ typedef struct _osa_adb_db_ent_t { int magic; DB *db; HASHINFO info; + BTREEINFO btinfo; char *filename; osa_adb_lock_t lock; } osa_adb_db_ent, *osa_adb_db_t, *osa_adb_princ_t, *osa_adb_policy_t; diff --git a/src/lib/kadm5/admin.h b/src/lib/kadm5/admin.h index 159c7fb..6e06636 100644 --- a/src/lib/kadm5/admin.h +++ b/src/lib/kadm5/admin.h @@ -1,4 +1,30 @@ /* + * lib/kadm5/admin.h + * + * Copyright 2001 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. + * + */ +/* * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved * * $Header$ @@ -234,13 +260,14 @@ typedef struct __krb5_realm_params { krb5_timestamp realm_expiration; krb5_flags realm_flags; krb5_key_salt_tuple *realm_keysalts; + unsigned int realm_reject_bad_transit:1; unsigned int realm_kadmind_port_valid:1; unsigned int realm_enctype_valid:1; unsigned int realm_max_life_valid:1; unsigned int realm_max_rlife_valid:1; unsigned int realm_expiration_valid:1; unsigned int realm_flags_valid:1; - unsigned int realm_filler:7; + unsigned int realm_reject_bad_transit_valid:1; krb5_int32 realm_num_keysalts; } krb5_realm_params; @@ -411,7 +438,8 @@ kadm5_ret_t kadm5_chpass_principal_util(void *server_handle, krb5_principal princ, char *new_pw, char **ret_pw, - char *msg_ret); + char *msg_ret, + int msg_len); kadm5_ret_t kadm5_free_principal_ent(void *server_handle, kadm5_principal_ent_t diff --git a/src/lib/kadm5/admin_internal.h b/src/lib/kadm5/admin_internal.h index d2d1533..97cb5e5 100644 --- a/src/lib/kadm5/admin_internal.h +++ b/src/lib/kadm5/admin_internal.h @@ -62,7 +62,8 @@ kadm5_ret_t _kadm5_chpass_principal_util(void *server_handle, krb5_principal princ, char *new_pw, char **ret_pw, - char *msg_ret); + char *msg_ret, + int msg_len); /* this is needed by the alt_prof code I stole. The functions maybe shouldn't be named krb5_*, but they are. */ diff --git a/src/lib/kadm5/alt_prof.c b/src/lib/kadm5/alt_prof.c index 5582df0..50f0b6a 100644 --- a/src/lib/kadm5/alt_prof.c +++ b/src/lib/kadm5/alt_prof.c @@ -1,7 +1,7 @@ /* * lib/kadm/alt_prof.c * - * Copyright 1995 by the Massachusetts Institute of Technology. + * Copyright 1995,2001 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -117,6 +117,64 @@ krb5_aprof_getvals(acontext, hierarchy, retdata) } /* + * krb5_aprof_get_boolean() + * + * Parameters: + * acontext - opaque context for alternate profile + * hierarchy - hierarchy of value to retrieve + * retdata - Returned data value + * Returns: + * error codes + */ + +static krb5_error_code +string_to_boolean (const char *string, krb5_boolean *out) +{ + static const char *const yes[] = { "y", "yes", "true", "t", "1", "on" }; + static const char *const no[] = { "n", "no", "false", "f", "nil", "0", "off" }; + int i; + + for (i = 0; i < sizeof(yes)/sizeof(yes[0]); i++) + if (!strcasecmp(string, yes[i])) { + *out = 1; + return 0; + } + for (i = 0; i < sizeof(no)/sizeof(no[0]); i++) + if (!strcasecmp(string, no[i])) { + *out = 0; + return 0; + } + return PROF_BAD_BOOLEAN; +} + +krb5_error_code +krb5_aprof_get_boolean(krb5_pointer acontext, const char **hierarchy, + int uselast, int *retdata) +{ + krb5_error_code kret; + char **values; + char *valp; + int idx; + krb5_boolean val; + + kret = krb5_aprof_getvals (acontext, hierarchy, &values); + if (kret) + return kret; + idx = 0; + if (uselast) { + while (values[idx]) + idx++; + idx--; + } + valp = values[idx]; + kret = string_to_boolean (valp, &val); + if (kret) + return kret; + *retdata = val; + return 0; +} + +/* * krb5_aprof_get_deltat() - Get a delta time value from the alternate * profile. * @@ -644,8 +702,8 @@ krb5_error_code kadm5_get_config_params(context, kdcprofile, kdcenv, if (aprofile) krb5_aprof_get_string(aprofile, hierarchy, TRUE, &svalue); if (svalue == NULL) - svalue = strdup("des-cbc-crc:normal"); - + svalue = strdup("des3-hmac-sha1:normal des-cbc-crc:normal"); + params.keysalts = NULL; params.num_keysalts = 0; krb5_string_to_keysalts(svalue, @@ -736,6 +794,7 @@ krb5_read_realm_params(kcontext, realm, kdcprofile, kdcenv, rparamp) const char *hierarchy[4]; char *svalue; krb5_int32 ivalue; + krb5_boolean bvalue; krb5_deltat dtvalue; krb5_error_code kret; @@ -832,7 +891,13 @@ krb5_read_realm_params(kcontext, realm, kdcprofile, kdcenv, rparamp) rparams->realm_expiration_valid = 1; krb5_xfree(svalue); } - + + hierarchy[2] = "reject_bad_transit"; + if (!krb5_aprof_get_boolean(aprofile, hierarchy, TRUE, &bvalue)) { + rparams->realm_reject_bad_transit = bvalue; + rparams->realm_reject_bad_transit_valid = 1; + } + /* Get the value for the default principal flags */ hierarchy[2] = "default_principal_flags"; if (!krb5_aprof_get_string(aprofile, hierarchy, TRUE, &svalue)) { diff --git a/src/lib/kadm5/chpass_util.c b/src/lib/kadm5/chpass_util.c index dbf610c..ec97a0e 100644 --- a/src/lib/kadm5/chpass_util.c +++ b/src/lib/kadm5/chpass_util.c @@ -61,7 +61,8 @@ kadm5_ret_t _kadm5_chpass_principal_util(void *server_handle, krb5_principal princ, char *new_pw, char **ret_pw, - char *msg_ret) + char *msg_ret, + int msg_len) { int code, code2, pwsize; static char buffer[255]; @@ -94,12 +95,18 @@ kadm5_ret_t _kadm5_chpass_principal_util(void *server_handle, memset(buffer, 0, sizeof(buffer)); #endif if (code == KRB5_LIBOS_BADPWDMATCH) { - strcpy(msg_ret, string_text(CHPASS_UTIL_NEW_PASSWORD_MISMATCH)); + strncpy(msg_ret, string_text(CHPASS_UTIL_NEW_PASSWORD_MISMATCH), + msg_len - 1); + msg_ret[msg_len - 1] = '\0'; return(code); } else { - sprintf(msg_ret, "%s %s\n%s\n", error_message(code), - string_text(CHPASS_UTIL_WHILE_READING_PASSWORD), - string_text(CHPASS_UTIL_PASSWORD_NOT_CHANGED)); + strncpy(msg_ret, error_message(code), msg_len - 1); + strncat(msg_ret, " ", msg_len - 1); + strncat(msg_ret, string_text(CHPASS_UTIL_WHILE_READING_PASSWORD), + msg_len - 1); + strncat(msg_ret, string_text(CHPASS_UTIL_PASSWORD_NOT_CHANGED), + msg_len - 1); + msg_ret[msg_len - 1] = '\0'; return(code); } } @@ -107,7 +114,8 @@ kadm5_ret_t _kadm5_chpass_principal_util(void *server_handle, #ifdef ZEROPASSWD memset(buffer, 0, sizeof(buffer)); #endif - strcpy(msg_ret, string_text(CHPASS_UTIL_NO_PASSWORD_READ)); + strncpy(msg_ret, string_text(CHPASS_UTIL_NO_PASSWORD_READ), msg_len - 1); + msg_ret[msg_len - 1] = '\0'; return(KRB5_LIBOS_CANTREADPWD); /* could do better */ } } @@ -123,7 +131,8 @@ kadm5_ret_t _kadm5_chpass_principal_util(void *server_handle, #endif if (code == KADM5_OK) { - strcpy(msg_ret, string_text(CHPASS_UTIL_PASSWORD_CHANGED)); + strncpy(msg_ret, string_text(CHPASS_UTIL_PASSWORD_CHANGED), msg_len - 1); + msg_ret[msg_len - 1] = '\0'; return(0); } @@ -141,12 +150,15 @@ kadm5_ret_t _kadm5_chpass_principal_util(void *server_handle, /* Ok, we have a password quality error. Return a good message */ if (code == KADM5_PASS_REUSE) { - strcpy(msg_ret, string_text(CHPASS_UTIL_PASSWORD_REUSE)); + strncpy(msg_ret, string_text(CHPASS_UTIL_PASSWORD_REUSE), msg_len - 1); + msg_ret[msg_len - 1] = '\0'; return(code); } if (code == KADM5_PASS_Q_DICT) { - strcpy(msg_ret, string_text(CHPASS_UTIL_PASSWORD_IN_DICTIONARY)); + strncpy(msg_ret, string_text(CHPASS_UTIL_PASSWORD_IN_DICTIONARY), + msg_len - 1); + msg_ret[msg_len - 1] = '\0'; return(code); } @@ -155,18 +167,32 @@ kadm5_ret_t _kadm5_chpass_principal_util(void *server_handle, code2 = kadm5_get_principal (lhandle, princ, &princ_ent, KADM5_PRINCIPAL_NORMAL_MASK); if (code2 != 0) { - sprintf(msg_ret, "%s %s\n%s %s\n\n%s\n ", error_message(code2), - string_text(CHPASS_UTIL_GET_PRINC_INFO), - error_message(code), - string_text(CHPASS_UTIL_WHILE_TRYING_TO_CHANGE), - string_text(CHPASS_UTIL_PASSWORD_NOT_CHANGED)); + strncpy(msg_ret, error_message(code2), msg_len - 1); + strncat(msg_ret, " ", msg_len - 1 - strlen(msg_ret)); + strncat(msg_ret, string_text(CHPASS_UTIL_GET_PRINC_INFO), msg_len - 1 - strlen(msg_ret)); + strncat(msg_ret, "\n", msg_len - 1 - strlen(msg_ret)); + strncat(msg_ret, error_message(code), msg_len - 1 - strlen(msg_ret)); + strncat(msg_ret, " ", msg_len - 1 - strlen(msg_ret)); + strncat(msg_ret, string_text(CHPASS_UTIL_WHILE_TRYING_TO_CHANGE), + msg_len - 1 - strlen(msg_ret)); + strncat(msg_ret, "\n\n", msg_len - 1 - strlen(msg_ret)); + strncat(msg_ret, string_text(CHPASS_UTIL_PASSWORD_NOT_CHANGED), + msg_len - 1 - strlen(msg_ret)); + strncat(msg_ret, "\n", msg_len - 1 - strlen(msg_ret)); + msg_ret[msg_len - 1] = '\0'; return(code); } if ((princ_ent.aux_attributes & KADM5_POLICY) == 0) { - sprintf(msg_ret, "%s %s\n\n%s", error_message(code), - string_text(CHPASS_UTIL_NO_POLICY_YET_Q_ERROR), - string_text(CHPASS_UTIL_PASSWORD_NOT_CHANGED)); + strncpy(msg_ret, error_message(code), msg_len - 1 - strlen(msg_ret)); + strncat(msg_ret, " ", msg_len - 1 - strlen(msg_ret)); + strncpy(msg_ret, string_text(CHPASS_UTIL_NO_POLICY_YET_Q_ERROR), + msg_len - 1 - strlen(msg_ret)); + strncat(msg_ret, "\n\n", msg_len - 1 - strlen(msg_ret)); + strncpy(msg_ret, string_text(CHPASS_UTIL_PASSWORD_NOT_CHANGED), + msg_len - 1 - strlen(msg_ret)); + msg_ret[msg_len - 1] = '\0'; + (void) kadm5_free_principal_ent(lhandle, &princ_ent); return(code); } diff --git a/src/lib/kadm5/clnt/ChangeLog b/src/lib/kadm5/clnt/ChangeLog index 79dc124..ac8850a 100644 --- a/src/lib/kadm5/clnt/ChangeLog +++ b/src/lib/kadm5/clnt/ChangeLog @@ -1,3 +1,23 @@ +2001-11-05 Tom Yu + + * Makefile.in (LIBMAJOR): Bump to avoid Heimdal conflict. + +2000-05-11 Nalin Dahyabhai + + * clnt_chpass_util.c (kadm5_chpass_principal_util): Adjust for new + length parameter in both kadm5_chpass_principal_util() and in + _kadm5_chpass_principal_util(). + +2000-05-09 Ken Raeburn + + * client_init.c (enctypes): Add des3 and des-md5 to the list of + permitted enctypes. + +2000-05-01 Nalin Dahyabhai + + * client_init.c (_kadm5_init_any): Fix determination of client + name length for overflow checking. + 2000-02-26 Tom Yu * client_principal.c (kadm5_create_principal_3): Remove keepold diff --git a/src/lib/kadm5/clnt/Makefile.in b/src/lib/kadm5/clnt/Makefile.in index 2d69cdc..e434236 100644 --- a/src/lib/kadm5/clnt/Makefile.in +++ b/src/lib/kadm5/clnt/Makefile.in @@ -5,7 +5,7 @@ BUILDTOP=$(REL)$(U)$(S)$(U)$(S)$(U) LOCALINCLUDES = -I$(BUILDTOP)/include/kadm5 LIB=kadm5clnt -LIBMAJOR=4 +LIBMAJOR=5 LIBMINOR=0 STOBJLISTS=../OBJS.ST OBJS.ST SHLIB_EXPDEPS=\ diff --git a/src/lib/kadm5/clnt/client_init.c b/src/lib/kadm5/clnt/client_init.c index a3d2613..b3832bb 100644 --- a/src/lib/kadm5/clnt/client_init.c +++ b/src/lib/kadm5/clnt/client_init.c @@ -134,6 +134,8 @@ static int preauth_search_list[] = { }; static krb5_enctype enctypes[] = { + ENCTYPE_DES3_CBC_SHA1, + ENCTYPE_DES_CBC_MD5, ENCTYPE_DES_CBC_CRC, 0, }; @@ -282,9 +284,15 @@ static kadm5_ret_t _kadm5_init_any(char *client_name, goto error; if (realm) { + if(strlen(service_name) + strlen(realm) + 1 >= sizeof(full_service_name)) { + goto error; + } sprintf(full_service_name, "%s@%s", service_name, realm); } else { /* krb5_princ_realm(creds.client) is not null terminated */ + if(strlen(service_name) + krb5_princ_realm(handle->context, creds.client)->length + 1 >= sizeof(full_service_name)) { + goto error; + } strcpy(full_service_name, service_name); strcat(full_service_name, "@"); strncat(full_service_name, krb5_princ_realm(handle->context, diff --git a/src/lib/kadm5/clnt/clnt_chpass_util.c b/src/lib/kadm5/clnt/clnt_chpass_util.c index d6c7f0b..ae9ced0 100644 --- a/src/lib/kadm5/clnt/clnt_chpass_util.c +++ b/src/lib/kadm5/clnt/clnt_chpass_util.c @@ -5,11 +5,12 @@ kadm5_ret_t kadm5_chpass_principal_util(void *server_handle, krb5_principal princ, char *new_pw, char **ret_pw, - char *msg_ret) + char *msg_ret, + int msg_len) { kadm5_server_handle_t handle = server_handle; CHECK_HANDLE(server_handle); return _kadm5_chpass_principal_util(handle, handle->lhandle, princ, - new_pw, ret_pw, msg_ret); + new_pw, ret_pw, msg_ret, msg_len); } diff --git a/src/lib/kadm5/kadm_rpc_xdr.c b/src/lib/kadm5/kadm_rpc_xdr.c index bf40048..c92dc60 100644 --- a/src/lib/kadm5/kadm_rpc_xdr.c +++ b/src/lib/kadm5/kadm_rpc_xdr.c @@ -135,8 +135,16 @@ xdr_krb5_kvno(XDR *xdrs, krb5_kvno *objp) tmp = '\0'; /* for purify, else xdr_u_char performs a umr */ - if (xdrs->x_op == XDR_ENCODE) + if (xdrs->x_op == XDR_ENCODE) { tmp = (unsigned char) *objp; +#if 0 + /* We can't change the protocol right now, so let's + just reject (legitimate!) values that won't fit in + our broken one-byte encoding. */ + if (tmp != *objp) + return FALSE; +#endif + } if (!xdr_u_char(xdrs, &tmp)) return (FALSE); diff --git a/src/lib/kadm5/logger.c b/src/lib/kadm5/logger.c index 4f2ad20..bf6bbfd 100644 --- a/src/lib/kadm5/logger.c +++ b/src/lib/kadm5/logger.c @@ -199,8 +199,9 @@ klog_com_err_proc(whoami, code, format, ap) /* If reporting an error message, separate it. */ if (code) { - strcat(outbuf, error_message(code)); - strcat(outbuf, " - "); + outbuf[sizeof(outbuf) - 1] = '\0'; + strncat(outbuf, error_message(code), sizeof(outbuf) - 1 - strlen(outbuf)); + strncat(outbuf, " - ", sizeof(outbuf) - 1 - strlen(outbuf)); } cp = &outbuf[strlen(outbuf)]; diff --git a/src/lib/kadm5/ovsec_glue.c b/src/lib/kadm5/ovsec_glue.c index 6118282..ce81893 100644 --- a/src/lib/kadm5/ovsec_glue.c +++ b/src/lib/kadm5/ovsec_glue.c @@ -102,8 +102,10 @@ ovsec_kadm_ret_t ovsec_kadm_chpass_principal_util(void *server_handle, char **ret_pw, char *msg_ret) { - return kadm5_chpass_principal_util(server_handle, princ, new_pw, - ret_pw, msg_ret); + /* Oh crap. Can't change the API without bumping the API version... */ + memset(msg_ret, '\0', 1024); + return kadm5_chpass_principal_util(server_handle, princ, new_pw, + ret_pw, msg_ret, 1024); } ovsec_kadm_ret_t ovsec_kadm_randkey_principal(void *server_handle, diff --git a/src/lib/kadm5/srv/ChangeLog b/src/lib/kadm5/srv/ChangeLog index 792936d..34d3ff0 100644 --- a/src/lib/kadm5/srv/ChangeLog +++ b/src/lib/kadm5/srv/ChangeLog @@ -1,3 +1,39 @@ +2001-11-05 Tom Yu + + * Makefile.in (LIBMAJOR): Bump to avoid Heimdal conflict. + +2001-10-22 Tom Yu + + * svr_principal.c (kadm5_decrypt_key): For now, coerce enctype of + output keyblock in case we got a match on a similar enctype. + +2001-10-16 Mitchell Berger + Matt Crawford + + * svr_principal.c (add_to_history): If the policy a principal uses has + been changed to hold a lesser number of history entries than it did + before, extract the correct number and value of old keys from the + history array into a newly allocated array of the proper size. Failing + to do this made kadmind vulnerable to a crash upon changing such a + principal's password. Original patch written by Matt Crawford, with + a few changes. + [pullup from trunk] + +2001-09-07 Tom Yu + + * adb_openclose.c (osa_adb_create_db): Default to btree. + (osa_adb_init_db): Set up btinfo as well. + (osa_adb_open_and_lock): Try btree, then hash. + [pullup from trunk] + +2000-05-11 Nalin Dahyabhai + + * adb_openclose.c (osa_adb_create_db): Open lock files using O_EXCL + and fdopen() the descriptor instead of using fopen(). + * svr_chpass_util.c (kadm5_chpass_principal_util): Adjust for new + length parameter in both kadm5_chpass_principal_util() and in + _kadm5_chpass_principal_util(). + 2000-03-16 Ken Raeburn Matt Crawford diff --git a/src/lib/kadm5/srv/Makefile.in b/src/lib/kadm5/srv/Makefile.in index a0d18e4..3459760 100644 --- a/src/lib/kadm5/srv/Makefile.in +++ b/src/lib/kadm5/srv/Makefile.in @@ -9,7 +9,7 @@ DEFINES = @HESIOD_DEFS@ ##DOSLIBNAME = libkadm5srv.lib LIB=kadm5srv -LIBMAJOR=4 +LIBMAJOR=5 LIBMINOR=0 STOBJLISTS=../OBJS.ST OBJS.ST SHLIB_EXPDEPS=\ diff --git a/src/lib/kadm5/srv/adb_openclose.c b/src/lib/kadm5/srv/adb_openclose.c index e776192..dbbc3b6 100644 --- a/src/lib/kadm5/srv/adb_openclose.c +++ b/src/lib/kadm5/srv/adb_openclose.c @@ -24,27 +24,29 @@ struct _locklist { osa_adb_ret_t osa_adb_create_db(char *filename, char *lockfilename, int magic) { - FILE *lf; + int lf; DB *db; - HASHINFO info; + BTREEINFO btinfo; - memset(&info, 0, sizeof(info)); - info.hash = NULL; - info.bsize = 256; - info.ffactor = 8; - info.nelem = 25000; - info.lorder = 0; - db = dbopen(filename, O_RDWR | O_CREAT | O_EXCL, 0600, DB_HASH, &info); + memset(&btinfo, 0, sizeof(btinfo)); + btinfo.flags = 0; + btinfo.cachesize = 0; + btinfo.psize = 4096; + btinfo.lorder = 0; + btinfo.minkeypage = 0; + btinfo.compare = NULL; + btinfo.prefix = NULL; + db = dbopen(filename, O_RDWR | O_CREAT | O_EXCL, 0600, DB_BTREE, &btinfo); if (db == NULL) return errno; if (db->close(db) < 0) return errno; /* only create the lock file if we successfully created the db */ - lf = fopen(lockfilename, "w+"); - if (lf == NULL) + lf = THREEPARAMOPEN(lockfilename, O_RDWR | O_CREAT | O_EXCL, 0600); + if (lf == -1) return errno; - (void) fclose(lf); + (void) close(lf); return OSA_ADB_OK; } @@ -128,6 +130,13 @@ osa_adb_ret_t osa_adb_init_db(osa_adb_db_t *dbp, char *filename, db->info.nelem = 25000; db->info.lorder = 0; + db->btinfo.flags = 0; + db->btinfo.cachesize = 0; + db->btinfo.psize = 4096; + db->btinfo.lorder = 0; + db->btinfo.minkeypage = 0; + db->btinfo.compare = NULL; + db->btinfo.prefix = NULL; /* * A process is allowed to open the same database multiple times * and access it via different handles. If the handles use @@ -333,7 +342,7 @@ osa_adb_ret_t osa_adb_get_lock(osa_adb_db_t db, int mode) osa_adb_ret_t osa_adb_release_lock(osa_adb_db_t db) { - int ret; + int ret, fd; if (!db->lock->lockcnt) /* lock already unlocked */ return OSA_ADB_NOTLOCKED; @@ -341,8 +350,9 @@ osa_adb_ret_t osa_adb_release_lock(osa_adb_db_t db) if (--db->lock->lockcnt == 0) { if (db->lock->lockmode == OSA_ADB_PERMANENT) { /* now we need to create the file since it does not exist */ - if ((db->lock->lockfile = fopen(db->lock->filename, - "w+")) == NULL) + fd = THREEPARAMOPEN(db->lock->filename,O_RDWR | O_CREAT | O_EXCL, + 0600); + if ((db->lock->lockfile = fdopen(fd, "w+")) == NULL) return OSA_ADB_NOLOCKFILE; } else if (ret = krb5_lock_file(db->lock->context, fileno(db->lock->lockfile), @@ -362,14 +372,23 @@ osa_adb_ret_t osa_adb_open_and_lock(osa_adb_princ_t db, int locktype) if (ret != OSA_ADB_OK) return ret; - db->db = dbopen(db->filename, O_RDWR, 0600, DB_HASH, &db->info); - if (db->db == NULL) { + db->db = dbopen(db->filename, O_RDWR, 0600, DB_BTREE, &db->btinfo); + if (db->db != NULL) + return OSA_ADB_OK; + switch (errno) { +#ifdef EFTYPE + case EFTYPE: +#endif + case EINVAL: + db->db = dbopen(db->filename, O_RDWR, 0600, DB_HASH, &db->info); + if (db->db != NULL) + return OSA_ADB_OK; + default: (void) osa_adb_release_lock(db); - if(errno == EINVAL) + if (errno == EINVAL) return OSA_ADB_BAD_DB; return errno; } - return OSA_ADB_OK; } osa_adb_ret_t osa_adb_close_and_unlock(osa_adb_princ_t db) diff --git a/src/lib/kadm5/srv/svr_chpass_util.c b/src/lib/kadm5/srv/svr_chpass_util.c index df2bf4c..4c4c6bb 100644 --- a/src/lib/kadm5/srv/svr_chpass_util.c +++ b/src/lib/kadm5/srv/svr_chpass_util.c @@ -5,11 +5,12 @@ kadm5_ret_t kadm5_chpass_principal_util(void *server_handle, krb5_principal princ, char *new_pw, char **ret_pw, - char *msg_ret) + char *msg_ret, + int msg_len) { kadm5_server_handle_t handle = server_handle; CHECK_HANDLE(server_handle); return _kadm5_chpass_principal_util(handle, handle->lhandle, princ, - new_pw, ret_pw, msg_ret); + new_pw, ret_pw, msg_ret, msg_len); } diff --git a/src/lib/kadm5/srv/svr_principal.c b/src/lib/kadm5/srv/svr_principal.c index 4981703..040a8e6 100644 --- a/src/lib/kadm5/srv/svr_principal.c +++ b/src/lib/kadm5/srv/svr_principal.c @@ -974,6 +974,7 @@ int free_history_entry(krb5_context context, osa_pw_hist_ent *hist) * array where the next element should be written, and must be [0, * adb->old_key_len). */ +#define KADM_MOD(x) (x + adb->old_key_next) % adb->old_key_len static kadm5_ret_t add_to_history(krb5_context context, osa_princ_ent_t adb, kadm5_policy_ent_t pol, @@ -1001,6 +1002,39 @@ static kadm5_ret_t add_to_history(krb5_context context, memset(&adb->old_keys[adb->old_key_len],0,sizeof(osa_pw_hist_ent)); adb->old_key_len++; + } else if (adb->old_key_len > pol->pw_history_num-1) { + /* + * The policy must have changed! Shrink the array. + * Can't simply realloc() down, since it might be wrapped. + * To understand the arithmetic below, note that we are + * copying into new positions 0 .. N-1 from old positions + * old_key_next-N .. old_key_next-1, modulo old_key_len, + * where N = pw_history_num - 1 is the length of the + * shortened list. Matt Crawford, FNAL + */ + int j; + histp = (osa_pw_hist_ent *) + malloc((pol->pw_history_num - 1) * sizeof (osa_pw_hist_ent)); + if (histp) { + for (i = 0; i < pol->pw_history_num - 1; i++) { + /* We need the number we use the modulus operator on to be + positive, so after subtracting pol->pw_history_num-1, we + add back adb->old_key_len. */ + j = KADM_MOD(i - (pol->pw_history_num - 1) + adb->old_key_len); + histp[i] = adb->old_keys[j]; + } + /* Now free the ones we don't keep (the oldest ones) */ + for (i = 0; i < adb->old_key_len - (pol->pw_history_num - 1); i++) + for (j = 0; j < adb->old_keys[KADM_MOD(i)].n_key_data; j++) + krb5_free_key_data_contents(context, + &adb->old_keys[KADM_MOD(i)].key_data[j]); + free((void *)adb->old_keys); + adb->old_keys = histp; + adb->old_key_len = pol->pw_history_num - 1; + adb->old_key_next = 0; + } else { + return(ENOMEM); + } } /* free the old pw history entry if it contains data */ @@ -1017,6 +1051,7 @@ static kadm5_ret_t add_to_history(krb5_context context, return(0); } +#undef KADM_MOD kadm5_ret_t kadm5_chpass_principal(void *server_handle, @@ -1703,6 +1738,13 @@ kadm5_ret_t kadm5_decrypt_key(void *server_handle, keyblock, keysalt)) return ret; + /* + * Coerce the enctype of the output keyblock in case we got an + * inexact match on the enctype; this behavior will go away when + * the key storage architecture gets redesigned for 1.3. + */ + keyblock->enctype = ktype; + if (kvnop) *kvnop = key_data->key_data_kvno; diff --git a/src/lib/kadm5/str_conv.c b/src/lib/kadm5/str_conv.c index 16ad534..f4f572a 100644 --- a/src/lib/kadm5/str_conv.c +++ b/src/lib/kadm5/str_conv.c @@ -361,7 +361,22 @@ krb5_string_to_keysalts(string, tupleseps, ksaltseps, dups, ksaltp, nksaltp) if (ep) ep[-1] = trailchar; kp = ep; - } + + /* Skip over extra separators - like spaces */ + if (kp && *tseplist) { + septmp = tseplist; + while(*septmp && *kp) { + if(*septmp == *kp) { + /* Increment string - reset separator list */ + kp++; + septmp = tseplist; + } else { + septmp++; + } + } + if (!*kp) kp = NULL; + } + } /* while kp */ return(kret); } diff --git a/src/lib/kadm5/unit-test/ChangeLog b/src/lib/kadm5/unit-test/ChangeLog index b8e4b71..2e9b74f 100644 --- a/src/lib/kadm5/unit-test/ChangeLog +++ b/src/lib/kadm5/unit-test/ChangeLog @@ -1,3 +1,16 @@ +2002-11-03 Tom Yu + + * config/unix.exp: Work around tcl 8.4's (incorrect?) output EOL + translation. + [pullup from trunk] + +2000-05-09 Ken Raeburn + + * api.2/chpass-principal-v2.exp (test200): Expect an additional + key to be reported, since des3 has been added to the list. + * api.2/get-principal-v2.exp (test101_102): Likewise. + * api.2/randkey-principal-v2.exp (test100): Likewise. + 2000-02-08 Tom Yu * api.1/lock.exp: Since a "wait" directive to the command list of diff --git a/src/lib/kadm5/unit-test/api.2/chpass-principal-v2.exp b/src/lib/kadm5/unit-test/api.2/chpass-principal-v2.exp index 40a78c9..ef45510 100644 --- a/src/lib/kadm5/unit-test/api.2/chpass-principal-v2.exp +++ b/src/lib/kadm5/unit-test/api.2/chpass-principal-v2.exp @@ -53,10 +53,10 @@ proc test200 {} { } # XXX Perhaps I should actually check the key type returned. - if {$num_keys == 2} { + if {$num_keys == 3} { pass "$test" } else { - fail "$test: $num_keys keys, should be 2" + fail "$test: $num_keys keys, should be 3" } if { ! [cmd {kadm5_destroy $server_handle}]} { error "$test: unexpected failure in destroy" diff --git a/src/lib/kadm5/unit-test/api.2/get-principal-v2.exp b/src/lib/kadm5/unit-test/api.2/get-principal-v2.exp index 0e3e1b5..d2eb85a 100644 --- a/src/lib/kadm5/unit-test/api.2/get-principal-v2.exp +++ b/src/lib/kadm5/unit-test/api.2/get-principal-v2.exp @@ -143,8 +143,8 @@ proc test101_102 {rpc} { } set failed 0 - if {$num_keys != 2} { - fail "$test: num_keys $num_keys should be 2" + if {$num_keys != 3} { + fail "$test: num_keys $num_keys should be 3" set failed 1 } for {set i 0} {$i < $num_keys} {incr i} { diff --git a/src/lib/kadm5/unit-test/api.2/randkey-principal-v2.exp b/src/lib/kadm5/unit-test/api.2/randkey-principal-v2.exp index 5c8fdc5..d9cc971 100644 --- a/src/lib/kadm5/unit-test/api.2/randkey-principal-v2.exp +++ b/src/lib/kadm5/unit-test/api.2/randkey-principal-v2.exp @@ -47,10 +47,10 @@ proc test100 {} { } # XXX Perhaps I should actually check the key type returned. - if {$num_keys == 1} { + if {$num_keys == 2} { pass "$test" } else { - fail "$test: $num_keys keys, should be 1" + fail "$test: $num_keys keys, should be 2" } if { ! [cmd {kadm5_destroy $server_handle}]} { error "$test: unexpected failure in destroy" diff --git a/src/lib/kadm5/unit-test/config/unix.exp b/src/lib/kadm5/unit-test/config/unix.exp index 2aab9e4..0472789 100644 --- a/src/lib/kadm5/unit-test/config/unix.exp +++ b/src/lib/kadm5/unit-test/config/unix.exp @@ -58,6 +58,14 @@ proc api_start {} { if {! [info exists env(TCLUTIL)]} { error "TCLUTIL environment variable isn't set" } + # tcl 8.4 for some reason screws up autodetection of output + # EOL translation. Work around it for now. + send "if { \[info commands fconfigure\] ne \"\" } { fconfigure stdout -translation lf }\n" + expect { + -re "$prompt$" {} + eof { error "EOF starting API" } + timeout { error "Timeout starting API" } + } send "source $env(TCLUTIL)\n" expect { -re "$prompt$" {} diff --git a/src/lib/kdb/ChangeLog b/src/lib/kdb/ChangeLog index a710eb7..ec95fe4 100644 --- a/src/lib/kdb/ChangeLog +++ b/src/lib/kdb/ChangeLog @@ -1,3 +1,68 @@ +2002-08-26 Tom Yu + + * kdb_db2.h: Add prototype and rename for + krb5_db2_db_iterate_ext(). + + * kdb_db2.c (krb5_db2_db_iterate_ext): New function; allow + optional backwards or recursive (if btree) traversal of the + database. + + * Makefile.in (LIBMINOR): Bump due to addition of + krb5_db_iterate_ext(). + + [pullups from trunk] + +2002-08-15 Tom Yu + + * keytab.c (krb5_ktkdb_get_entry): For consistency, check for + DISALLOW_ALL_TIX and DISALLOW_SVR when looking up keys. + [pullup from trunk] + +2002-08-12 Sam Hartman + + * kdb_xdr.c (krb5_dbe_search_enctype): Initialize ret to 0; thanks + to Lubos Kejzlar + [pullup from trunk] + +2001-11-05 Tom Yu + + * Makefile.in (LIBMINOR): Bump due to some behavior changes + regarding enctype similarity. + +2001-10-22 Tom Yu + + * kdb_xdr.c (krb5_dbe_search_enctype): Filter out enctypes that + aren't in permitted_enctypes. This prevents the KDC from issuing + a ticket whose enctype that it won't accept. + +2001-10-20 Tom Yu + + * keytab.c (krb5_ktkdb_get_entry): For now, coerce enctype of + output keyblock in case we got a match on a similar enctype. + +2000-05-11 Nalin Dahyabhai + + * t_kdb.c (gen_principal): Don't overflow "pnamebuf" if bad data was + passed in. + +2000-05-03 Nalin Dahyabhai + + * setup_mkey.c (krb5_db_setup_mkey_name): Use REALM_SEP_STRING + when computing size of buffer that is to include it. + + * fetch_mkey.c (krb5_db_fetch_mkey): Make sure "defkeyfile" is + null terminated after construction. + * store_mkey.c (krb5_db_store_mkey): Likewise. + +2000-04-27 Ken Raeburn + Ezra Peisach + + * t_kdb.c (gen_principal): Force argument to isalnum to be in + range 0..255. + (do_testing): Cast pid_t to long before passing to fprintf, and + use %ld format. Fix argument lists to find_principal and + delete_principal. + 2000-03-16 Ezra Peisach * kdb_xdr.c (krb5_dbe_lookup_mod_princ_data): Get rid of diff --git a/src/lib/kdb/Makefile.in b/src/lib/kdb/Makefile.in index 68c6361..10f7580 100644 --- a/src/lib/kdb/Makefile.in +++ b/src/lib/kdb/Makefile.in @@ -9,7 +9,7 @@ PROG_RPATH=$(KRB5_LIBDIR) LIB=kdb5 LIBMAJOR=3 -LIBMINOR=0 +LIBMINOR=2 RELDIR=kdb # Depends on libk5crypto and libkrb5 SHLIB_EXPDEPS = \ diff --git a/src/lib/kdb/fetch_mkey.c b/src/lib/kdb/fetch_mkey.c index 2ff5c29..7ae26bb 100644 --- a/src/lib/kdb/fetch_mkey.c +++ b/src/lib/kdb/fetch_mkey.c @@ -133,7 +133,7 @@ krb5_db_fetch_mkey(context, mname, etype, fromkeyboard, twice, keyfile, (void) strncat(defkeyfile, realm->data, min(sizeof(defkeyfile)-sizeof(DEFAULT_KEYFILE_STUB)-1, realm->length)); - (void) strcat(defkeyfile, ""); + defkeyfile[sizeof(defkeyfile) - 1] = '\0'; #ifdef ANSI_STDIO if (!(kf = fopen((keyfile) ? keyfile : defkeyfile, "rb"))) diff --git a/src/lib/kdb/kdb_db2.c b/src/lib/kdb/kdb_db2.c index 627aa75..6420acc 100644 --- a/src/lib/kdb/kdb_db2.c +++ b/src/lib/kdb/kdb_db2.c @@ -1115,10 +1115,11 @@ cleanup: } krb5_error_code -krb5_db2_db_iterate (context, func, func_arg) +krb5_db2_db_iterate_ext(context, func, func_arg, backwards, recursive) krb5_context context; krb5_error_code (*func) PROTOTYPE((krb5_pointer, krb5_db_entry *)); krb5_pointer func_arg; + int backwards, recursive; { krb5_db2_context *db_ctx; DB *db; @@ -1127,17 +1128,31 @@ krb5_db2_db_iterate (context, func, func_arg) krb5_db_entry entries; krb5_error_code retval; int dbret; - + void *cookie; + + cookie = NULL; if (!k5db2_inited(context)) return KRB5_KDB_DBNOTINITED; db_ctx = (krb5_db2_context *) context->db_context; retval = krb5_db2_db_lock(context, KRB5_LOCKMODE_SHARED); + if (retval) return retval; db = db_ctx->db; - dbret = (*db->seq)(db, &key, &contents, R_FIRST); + if (recursive && db->type != DB_BTREE) { + (void)krb5_db2_db_unlock(context); + return KRB5_KDB_UK_RERROR; /* Not optimal, but close enough. */ + } + + if (!recursive) { + dbret = (*db->seq)(db, &key, &contents, + backwards ? R_LAST : R_FIRST); + } else { + dbret = bt_rseq(db, &key, &contents, &cookie, + backwards ? R_LAST : R_FIRST); + } while (dbret == 0) { contdata.data = contents.data; contdata.length = contents.size; @@ -1148,7 +1163,13 @@ krb5_db2_db_iterate (context, func, func_arg) krb5_dbe_free_contents(context, &entries); if (retval) break; - dbret = (*db->seq)(db, &key, &contents, R_NEXT); + if (!recursive) { + dbret = (*db->seq)(db, &key, &contents, + backwards ? R_PREV : R_NEXT); + } else { + dbret = bt_rseq(db, &key, &contents, &cookie, + backwards ? R_PREV : R_NEXT); + } } switch (dbret) { case 1: @@ -1162,6 +1183,15 @@ krb5_db2_db_iterate (context, func, func_arg) return retval; } +krb5_error_code +krb5_db2_db_iterate(context, func, func_arg) + krb5_context context; + krb5_error_code (*func) (krb5_pointer, krb5_db_entry *); + krb5_pointer func_arg; +{ + return krb5_db2_db_iterate_ext(context, func, func_arg, 0, 0); +} + krb5_boolean krb5_db2_db_set_lockmode(context, mode) krb5_context context; diff --git a/src/lib/kdb/kdb_db2.h b/src/lib/kdb/kdb_db2.h index fd35c81..d8f7ba5 100644 --- a/src/lib/kdb/kdb_db2.h +++ b/src/lib/kdb/kdb_db2.h @@ -41,6 +41,7 @@ #define krb5_db2_db_free_principal krb5_db_free_principal #define krb5_db2_db_put_principal krb5_db_put_principal #define krb5_db2_db_delete_principal krb5_db_delete_principal +#define krb5_db2_db_iterate_ext krb5_db_iterate_ext #define krb5_db2_db_iterate krb5_db_iterate #define krb5_db2_db_lock krb5_db_lock #define krb5_db2_db_unlock krb5_db_unlock @@ -104,6 +105,11 @@ krb5_error_code krb5_db2_db_put_principal KRB5_PROTOTYPE((krb5_context, krb5_db_entry *, int * )); +krb5_error_code krb5_db2_db_iterate_ext + KRB5_PROTOTYPE((krb5_context, + krb5_error_code (*) (krb5_pointer, + krb5_db_entry *), + krb5_pointer, int, int )); krb5_error_code krb5_db2_db_iterate KRB5_PROTOTYPE((krb5_context, krb5_error_code (*) KRB5_PROTOTYPE((krb5_pointer, diff --git a/src/lib/kdb/kdb_xdr.c b/src/lib/kdb/kdb_xdr.c index 5d1911e2..b7b8b4a 100644 --- a/src/lib/kdb/kdb_xdr.c +++ b/src/lib/kdb/kdb_xdr.c @@ -724,7 +724,9 @@ krb5_dbe_search_enctype(kcontext, dbentp, start, ktype, stype, kvno, kdatap) int i, index; int maxkvno; krb5_key_data *datap; + krb5_error_code ret; + ret = 0; if (kvno == -1 && stype == -1 && ktype == -1) kvno = 0; @@ -741,15 +743,25 @@ krb5_dbe_search_enctype(kcontext, dbentp, start, ktype, stype, kvno, kdatap) datap = (krb5_key_data *) NULL; for (i = *start; i < dbentp->n_key_data; i++) { krb5_boolean similar; - krb5_error_code ret; krb5_int32 db_stype; + ret = 0; if (dbentp->key_data[i].key_data_ver > 1) { db_stype = dbentp->key_data[i].key_data_type[1]; } else { db_stype = KRB5_KDB_SALTTYPE_NORMAL; } + + /* + * Filter out non-permitted enctypes. + */ + if (!krb5_is_permitted_enctype(kcontext, + dbentp->key_data[i].key_data_type[0])) { + ret = KRB5_KDB_NO_PERMITTED_KEY; + continue; + } + if (ktype >= 0) { if ((ret = krb5_c_enctype_compare(kcontext, (krb5_enctype) ktype, dbentp->key_data[i].key_data_type[0], @@ -776,7 +788,7 @@ krb5_dbe_search_enctype(kcontext, dbentp, start, ktype, stype, kvno, kdatap) } } if (maxkvno < 0) - return ENOENT; + return ret ? ret : KRB5_KDB_NO_MATCHING_KEY; *kdatap = datap; *start = index+1; return 0; diff --git a/src/lib/kdb/keytab.c b/src/lib/kdb/keytab.c index 1e5025c..586f0e8 100644 --- a/src/lib/kdb/keytab.c +++ b/src/lib/kdb/keytab.c @@ -116,6 +116,12 @@ krb5_ktkdb_get_entry(context, id, principal, kvno, enctype, entry) return KRB5_KT_NOTFOUND; } + if (db_entry.attributes & KRB5_KDB_DISALLOW_SVR + || db_entry.attributes & KRB5_KDB_DISALLOW_ALL_TIX) { + kerror = KRB5_KT_NOTFOUND; + goto error; + } + /* match key */ kerror = krb5_db_get_mkey(context, &master_key); if (kerror) @@ -131,6 +137,13 @@ krb5_ktkdb_get_entry(context, id, principal, kvno, enctype, entry) if (kerror) goto error; + /* + * Coerce the enctype of the output keyblock in case we got an + * inexact match on the enctype; this behavior will go away when + * the key storage architecture gets redesigned for 1.3. + */ + entry->key.enctype = enctype; + kerror = krb5_copy_principal(context, principal, &entry->principal); if (kerror) goto error; diff --git a/src/lib/kdb/setup_mkey.c b/src/lib/kdb/setup_mkey.c index 0898a63..1788ecd 100644 --- a/src/lib/kdb/setup_mkey.c +++ b/src/lib/kdb/setup_mkey.c @@ -56,7 +56,7 @@ krb5_db_setup_mkey_name(context, keyname, realm, fullname, principal) keylen = strlen(keyname); - fname = malloc(keylen+rlen+2); + fname = malloc(keylen+rlen+strlen(REALM_SEP_STRING)+1); if (!fname) return ENOMEM; diff --git a/src/lib/kdb/store_mkey.c b/src/lib/kdb/store_mkey.c index d18630a..47e0bc9 100644 --- a/src/lib/kdb/store_mkey.c +++ b/src/lib/kdb/store_mkey.c @@ -68,7 +68,7 @@ krb5_db_store_mkey(context, keyfile, mname, key) (void) strncat(defkeyfile, realm->data, min(sizeof(defkeyfile)-sizeof(DEFAULT_KEYFILE_STUB)-1, realm->length)); - (void) strcat(defkeyfile, ""); + defkeyfile[sizeof(defkeyfile) - 1] = '\0'; keyfile = defkeyfile; } diff --git a/src/lib/kdb/t_kdb.c b/src/lib/kdb/t_kdb.c index 8358088..10e6163 100644 --- a/src/lib/kdb/t_kdb.c +++ b/src/lib/kdb/t_kdb.c @@ -363,15 +363,23 @@ gen_principal(kcontext, realm, do_rand, n, princp, namep) complen = RANDOM(1,MAX_COMP_SIZE); for (j=0; j= pnamebuf + sizeof(pnamebuf)) + break; } + if(cp + strlen(realm) >= pnamebuf + sizeof(pnamebuf)) + break; *cp = '/'; cp++; } - cp[-1] = '@'; - strcpy(cp, realm); + if(cp + strlen(realm) < pnamebuf + sizeof(pnamebuf)) { + cp[-1] = '@'; + strcpy(cp, realm); + } else { + strcpy(cp , ""); + } } else { instname = instnames[n % (sizeof(instnames)/sizeof(instnames[0]))]; @@ -894,45 +902,40 @@ do_testing(db, passes, verbose, timing, rcases, check, save_db, dontclean, &stat_kb, rseed))) { fprintf(stderr, - "%d: (%d,%d) Failed add of %s with %s\n", - getpid(), i, j, playback_name(base+j), + "%ld: (%d,%d) Failed add of %s with %s\n", + (long) getpid(), i, j, playback_name(base+j), error_message(kret)); break; } if (verbose > 4) - fprintf(stderr, "*A[%d](%s)\n", getpid(), + fprintf(stderr, "*A[%ld](%s)\n", (long) getpid(), playback_name(base+j)); } for (j=0; (j 4) - fprintf(stderr, "-S[%d](%s)\n", getpid(), + fprintf(stderr, "-S[%ld](%s)\n", (long) getpid(), playback_name(base+j)); } for (j=0; (j 4) - fprintf(stderr, "XD[%d](%s)\n", getpid(), + fprintf(stderr, "XD[%ld](%s)\n", (long) getpid(), playback_name(base+j)); } krb5_db_fini(ccontext); @@ -949,13 +952,13 @@ do_testing(db, passes, verbose, timing, rcases, check, save_db, dontclean, for (i=0; i + + * rd_svc_key.c (krb54_get_service_keyblock): If the keytab + encryption type is a non-raw des3 key, bash its enctype. This + matches kdc/kerberos_v4.c. + [pullup from trunk] + +2001-01-26 Tom Yu + + * dest_tkt.c: Clean up uid handling. Fix stat checks. + + * in_tkt.c: Clean up uid handling. Fix stat checks. + + * tf_util.c: Clean up uid handling. Fix stat checks. + +2000-06-09 Tom Yu + + * configure.in: Check for strdup(). + + * kparse.c: Remove strsave() and replace with an inlined static + version of strdup() if HAVE_STRDUP is not defined. + + * g_ad_tkt.c (get_ad_tkt): ptr may be signed; cast while + assigning to larger types. [from Charles Hannum by way of + ghudson] + +2000-05-23 Ken Raeburn + + * decomp_tkt.c (dcmp_tkt_int): Add a couple more length checks. + Reject names that are exactly ANAME_SZ (etc) bytes long without + the trailing nul, because krb.h says the *_SZ macros are "maximum + sizes ... +1". + * mk_auth.c (krb_mk_auth): Force nul termination of inst. + * sendauth.c (krb_sendauth): Force nul termination of srv_inst. + +2000-05-11 Nalin Dahyabhai + + * Password.c (GetUserInfo): Truncate user name if it's too long + to fit. + * cr_auth_repl.c (cr_auth_reply): Bail if the reply packet won't + fit into its buffer. + * cr_ciph.c (create_ciph): Ditto. + * cr_death_pkt.c (krb_create_death_packet): Truncate "aname" to + make it fit into the packet's data buffer. + * cr_err_repl.c (cr_err_reply): Bail if the reply packet won't + fit into its buffer. + * cr_tkt.c (krb_create_ticket): Ditto. + * g_ad_tkt.c (get_ad_tkt): Stop if data being added to buffer + would overflow it. Add more sanity checks when decomposing the + credential received. + * g_in_tkt.c (krb_mk_in_tkt_preauth): Bail if the request packet + won't fit into its buffer. + * g_krbhst.c (get_krbhst_default): Truncate the guessed KDC's + hostname if it is too long. + * g_pw_in_tkt.c: Remove useless strcpy() prototype. + * kntoln.c (krb_kntoln): Don't overflow buffer "lname". + * mk_err.c (krb_mk_err): Return the needed buffer length if the + pointer passed in is NULL. + * mk_req.c (krb_mk_req): Bail if the reply packet won't + fit into its buffer. + * rd_req.c (krb_rd_req): Sanity check the realm name being read, + and truncate the service name, nstance, and realm from credential + read from keytab. + * realmofhost.c (krb_realmofhost): Truncate realm names read + from file if they are too long. + * send_to_kdc.c (send_to_kdc): Truncate passed-in realm name. + +2000-05-08 Ken Raeburn + + * rd_req.c (krb_rd_req): Mask length byte with 0xff in case the + length is over 127 and char is signed. + + * recvauth.c (krb_recvauth): If the number of bytes to be read + from the net is not positive, just return an error. + +2000-05-03 Tom Yu + + * cr_tkt.c: Delete prototype for krb_cr_tkt_int(), since the + definition is K&R style and contains narrow types. Thank you + HP/UX for having a compiler that actually makes this a fatal + error. + +2000-04-28 Ken Raeburn + Nalin Dahyabhai + + * dest_tkt.c (dest_tkt): Don't overflow buffer "shmidname". + * in_tkt.c (in_tkt): Don't overflow buffer "shmidname". + * kuserok.c (kuserok): Don't overflow buffer "pbuf". + * tf_util.c (tf_init): Don't overflow buffer "shmidname". + * win_store.c (krb__get_cnffile): Don't overflow buffers "defname" + and "cnfname". + (krb__get_realmsfile): Don't overflow buffers "defname" and + "realmsname". + +2000-04-28 Tom Yu + + * rd_req.c (krb_rd_req): Fix some uses of strcpy(). + +2000-03-12 Ezra Peisach + + * cr_tkt.c (krb_cr_tkt_int): Add static prototype. + * decomp_tkt.c: (dcmp_tkt_int): Add static prototype + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/lib/krb4/Password.c b/src/lib/krb4/Password.c index b296630..5862e0e 100644 --- a/src/lib/krb4/Password.c +++ b/src/lib/krb4/Password.c @@ -177,7 +177,8 @@ OSErr GetUserInfo( char *password ) // already got a password, just get the initial ticket ////////////////////////////////////////////////////// if (*gPassword) { - strcpy (UserName, krb_get_default_user( )); + strncpy (UserName, krb_get_default_user( ), sizeof(UserName)-1); + UserName[sizeof(UserName) - 1] = '\0'; /* FIXME jcm - if we have a password then no dialog comes up for setting the uinstance. */ rc = kname_parse(uname, uinst, realm, UserName); @@ -201,7 +202,8 @@ OSErr GetUserInfo( char *password ) } // Insert user's name in dialog - strcpy (UserName, krb_get_default_user( )); + strncpy (UserName, krb_get_default_user( ), sizeof(UserName) - 1); + UserName[sizeof(UserName) - 1] = '\0'; if (*UserName) { tempStr[0] = strlen(UserName); memcpy( &(tempStr[1]), UserName, tempStr[0]); @@ -417,7 +419,8 @@ CacheInitialTicket( serviceName ) if (!serviceName || (serviceName[0] == '\0')) return err; - strcpy (UserName, krb_get_default_user()); + strncpy (UserName, krb_get_default_user(), sizeof(UserName) - 1); + UserName[sizeof(UserName) - 1] = '\0'; err = kname_parse(uname, uinst, urealm, UserName); if (err) return err; diff --git a/src/lib/krb4/configure.in b/src/lib/krb4/configure.in index 0434c7d..59937e1 100644 --- a/src/lib/krb4/configure.in +++ b/src/lib/krb4/configure.in @@ -38,7 +38,7 @@ else AC_DEFINE(BITS32) fi AC_DEFINE(KRB4_USE_KEYTAB) -AC_HAVE_FUNCS(strsave seteuid setreuid setresuid) +AC_HAVE_FUNCS(strdup seteuid setreuid setresuid) AC_PROG_AWK KRB5_BUILD_LIBOBJS KRB5_BUILD_LIBRARY_WITH_DEPS diff --git a/src/lib/krb4/cr_auth_repl.c b/src/lib/krb4/cr_auth_repl.c index 5203506..a0562d9 100644 --- a/src/lib/krb4/cr_auth_repl.c +++ b/src/lib/krb4/cr_auth_repl.c @@ -83,6 +83,16 @@ create_auth_reply(pname,pinst,prealm,time_ws,n,x_date,kvno,cipher) if (n != 0) *v = 3; + /* Make sure the response will actually fit into its buffer. */ + if(sizeof(pkt->dat) < 3 + strlen(pname) + + 1 + strlen(pinst) + + 1 + strlen(prealm) + + 4 + 1 + 4 + + 1 + 2 + cipher->length) { + pkt->length = 0; + return NULL; + } + /* Add the basic info */ (void) strcpy((char *) (pkt->dat+2), pname); pkt->length = 3 + strlen(pname); diff --git a/src/lib/krb4/cr_ciph.c b/src/lib/krb4/cr_ciph.c index d15a4e0..d9c7512 100644 --- a/src/lib/krb4/cr_ciph.c +++ b/src/lib/krb4/cr_ciph.c @@ -71,6 +71,17 @@ create_ciph(c, session, service, instance, realm, life, kvno, tkt, ptr = (char *) c->dat; + if(sizeof(c->dat) / 8 < (8 + + strlen(service) + 1 + + strlen(instance) + 1 + + strlen(realm) + 1 + + 1 + 1 + 1 + + tkt->length + 4 + + 7) / 8) { + c->length = 0; + return(KFAILURE); + } + memcpy(ptr, (char *) session, 8); ptr += 8; diff --git a/src/lib/krb4/cr_death_pkt.c b/src/lib/krb4/cr_death_pkt.c index 8daa2d6..c356267 100644 --- a/src/lib/krb4/cr_death_pkt.c +++ b/src/lib/krb4/cr_death_pkt.c @@ -52,8 +52,9 @@ krb_create_death_packet(a_name) *v = (unsigned char) KRB_PROT_VERSION; *t = (unsigned char) AUTH_MSG_DIE; *t |= HOST_BYTE_ORDER; - (void) strcpy((char *) (pkt->dat+2),a_name); - pkt->length = 3 + strlen(a_name); + (void) strncpy((char *) (pkt->dat+2),a_name,sizeof(pkt->dat) - 3); + pkt->dat[sizeof(pkt->dat) - 1] = '\0'; + pkt->length = 3 + strlen(pkt->dat+2); return pkt; } #endif /* DEBUG */ diff --git a/src/lib/krb4/cr_err_repl.c b/src/lib/krb4/cr_err_repl.c index 7f68bda..54e87d8 100644 --- a/src/lib/krb4/cr_err_repl.c +++ b/src/lib/krb4/cr_err_repl.c @@ -78,6 +78,15 @@ cr_err_reply(pkt,pname,pinst,prealm,time_ws,e,e_string) *t = (unsigned char) AUTH_MSG_ERR_REPLY; *t |= HOST_BYTE_ORDER; + /* Make sure the reply will fit into the buffer. */ + if(sizeof(pkt->dat) < 3 + strlen(pname) + + 1 + strlen(pinst) + + 1 + strlen(prealm) + + 4 + 4 + + 1 + strlen(e_string)) { + pkt->length = 0; + return; + } /* Add the basic info */ (void) strcpy((char *) (pkt->dat+2),pname); pkt->length = 3 + strlen(pname); diff --git a/src/lib/krb4/cr_tkt.c b/src/lib/krb4/cr_tkt.c index a8224f8..34bec48 100644 --- a/src/lib/krb4/cr_tkt.c +++ b/src/lib/krb4/cr_tkt.c @@ -14,6 +14,7 @@ #include "prot.h" #include #include + /* * Create ticket takes as arguments information that should be in a * ticket, and the KTEXT object in which the ticket should be @@ -134,6 +135,23 @@ krb_cr_tkt_int(tkt, flags, pname, pinstance, prealm, paddress, register char *data; /* running index into ticket */ tkt->length = 0; /* Clear previous data */ + + /* Check length of ticket */ + if (sizeof(tkt->dat) < (sizeof(flags) + + 1 + strlen(pname) + + 1 + strlen(pinstance) + + 1 + strlen(prealm) + + 4 + /* address */ + 8 + /* session */ + 1 + /* life */ + 4 + /* issue time */ + 1 + strlen(sname) + + 1 + strlen(sinstance) + + 7) / 8) { /* roundoff */ + memset(tkt->dat, 0, sizeof(tkt->dat)); + return KFAILURE /* XXX */; + } + flags |= HOST_BYTE_ORDER; /* ticket byte order */ memcpy((char *) (tkt->dat), (char *) &flags, sizeof(flags)); data = ((char *)tkt->dat) + sizeof(flags); diff --git a/src/lib/krb4/decomp_tkt.c b/src/lib/krb4/decomp_tkt.c index 03398ac..06e9e31 100644 --- a/src/lib/krb4/decomp_tkt.c +++ b/src/lib/krb4/decomp_tkt.c @@ -19,6 +19,12 @@ extern int krb_debug; #endif +static int dcmp_tkt_int PROTOTYPE((KTEXT tkt, unsigned char *flags, + char *pname, char *pinstance, char *prealm, + unsigned KRB4_32 *paddress, C_Block session, + int *life, unsigned KRB4_32 *time_sec, + char *sname, char *sinstance, C_Block key, + Key_schedule key_s, krb5_keyblock *k5key)); /* * This routine takes a ticket and pointers to the variables that * should be filled in based on the information in the ticket. It @@ -186,17 +192,17 @@ dcmp_tkt_int(tkt, flags, pname, pinstance, prealm, paddress, session, if (HOST_BYTE_ORDER != ((*flags >> K_FLAG_ORDER)& 1)) tkt_swap_bytes++; - if (strlen(ptr) > ANAME_SZ) + if (strlen(ptr) >= ANAME_SZ) return(KFAILURE); (void) strcpy(pname,ptr); /* pname */ ptr += strlen(pname) + 1; - if (strlen(ptr) > INST_SZ) + if (strlen(ptr) >= INST_SZ) return(KFAILURE); (void) strcpy(pinstance,ptr); /* instance */ ptr += strlen(pinstance) + 1; - if (strlen(ptr) > REALM_SZ) + if (strlen(ptr) >= REALM_SZ) return(KFAILURE); (void) strcpy(prealm,ptr); /* realm */ ptr += strlen(prealm) + 1; @@ -223,9 +229,13 @@ dcmp_tkt_int(tkt, flags, pname, pinstance, prealm, paddress, session, if (tkt_swap_bytes) *time_sec = krb4_swab32(*time_sec); + if (strlen(ptr) >= ANAME_SZ) + return KFAILURE; (void) strcpy(sname,ptr); /* service name */ ptr += 1 + strlen(sname); + if (strlen (ptr) >= INST_SZ) + return KFAILURE; (void) strcpy(sinstance,ptr); /* instance */ ptr += 1 + strlen(sinstance); diff --git a/src/lib/krb4/dest_tkt.c b/src/lib/krb4/dest_tkt.c index 7057818..7887822 100644 --- a/src/lib/krb4/dest_tkt.c +++ b/src/lib/krb4/dest_tkt.c @@ -1,14 +1,29 @@ /* - * dest_tkt.c + * lib/krb4/dest_tkt.c * - * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute - * of Technology. + * Copyright 1985, 1986, 1987, 1988, 2000, 2001 by the Massachusetts + * Institute of Technology. All Rights Reserved. * - * For copying and distribution information, please see the file - * . + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. */ -#include "mit-copyright.h" #include "krb.h" #include #include @@ -17,12 +32,29 @@ #ifdef TKT_SHMEM #include #endif +#ifdef HAVE_UNISTD_H +#include +#endif #include #ifndef O_SYNC #define O_SYNC 0 #endif +#ifdef HAVE_SETEUID +#define do_seteuid(e) seteuid((e)) +#else +#ifdef HAVE_SETRESUID +#define do_seteuid(e) setresuid(-1, (e), -1) +#else +#ifdef HAVE_SETREUID +#define do_seteuid(e) setreuid(geteuid(), (e)) +#else +#define do_seteuid(e) (errno = EPERM, -1) +#endif +#endif +#endif + /* * dest_tkt() is used to destroy the ticket store upon logout. * If the ticket file does not exist, dest_tkt() returns RET_TKFIL. @@ -38,10 +70,13 @@ dest_tkt() char *file = TKT_FILE; int i,fd; extern int errno; - struct stat statb; + int ret; + struct stat statpre, statpost; char buf[BUFSIZ]; + uid_t me, metoo; #ifdef TKT_SHMEM char shmidname[MAXPATHLEN]; + size_t shmidlen; #endif /* TKT_SHMEM */ /* If ticket cache selector is null, use default cache. */ @@ -49,22 +84,56 @@ dest_tkt() file = tkt_string(); errno = 0; - if (lstat(file,&statb) < 0) - goto out; + ret = KSUCCESS; + me = getuid(); + metoo = geteuid(); - if (!(statb.st_mode & S_IFREG) -#ifdef notdef - || statb.st_mode & 077 -#endif - ) + if (lstat(file, &statpre) < 0) + return (errno == ENOENT) ? RET_TKFIL : KFAILURE; + /* + * This does not guard against certain cases that are vulnerable + * to race conditions, such as world-writable or group-writable + * directories that are not stickybitted, or untrusted path + * components. In all other cases, the following checks should be + * sufficient. It is assumed that the aforementioned certain + * vulnerable cases are unlikely to arise on a well-administered + * system where the user is not deliberately being stupid. + */ + if (!(statpre.st_mode & S_IFREG) || me != statpre.st_uid + || statpre.st_nlink != 1) + return KFAILURE; + /* + * Yes, we do uid twiddling here. It's not optimal, but some + * applications may expect that the ruid is what should really own + * the ticket file, e.g. setuid applications. + */ + if (me != metoo && do_seteuid(me) < 0) + return KFAILURE; + if ((fd = open(file, O_RDWR|O_SYNC, 0)) < 0) { + ret = (errno == ENOENT) ? RET_TKFIL : KFAILURE; goto out; - - if ((fd = open(file, O_RDWR|O_SYNC, 0)) < 0) + } + /* + * Do some additional paranoid things. The worst-case situation + * is that a user may be fooled into opening a non-regular file + * briefly if the file is in a directory with improper + * permissions. + */ + if (fstat(fd, &statpost) < 0) { + (void)close(fd); + ret = KFAILURE; + goto out; + } + if (statpre.st_dev != statpost.st_dev + || statpre.st_ino != statpost.st_ino) { + (void)close(fd); + errno = 0; + ret = KFAILURE; goto out; + } memset(buf, 0, BUFSIZ); - - for (i = 0; i < statb.st_size; i += BUFSIZ) + for (i = 0; i < statpost.st_size; i += BUFSIZ) if (write(fd, buf, BUFSIZ) != BUFSIZ) { #ifndef NO_FSYNC (void) fsync(fd); @@ -81,16 +150,22 @@ dest_tkt() (void) unlink(file); out: - if (errno == ENOENT) return RET_TKFIL; - else if (errno != 0) return KFAILURE; + if (me != metoo && do_seteuid(metoo) < 0) + return KFAILURE; + if (ret != KSUCCESS) + return ret; + #ifdef TKT_SHMEM /* * handle the shared memory case */ - (void) strcpy(shmidname, file); - (void) strcat(shmidname, ".shm"); - if ((i = krb_shm_dest(shmidname)) != KSUCCESS) - return(i); -#endif /* TKT_SHMEM */ - return(KSUCCESS); + shmidlen = strlen(file) + sizeof(".shm"); + if (shmidlen > sizeof(shmidname)) + return RET_TKFIL; + (void)strcpy(shmidname, file); + (void)strcat(shmidname, ".shm"); + return krb_shm_dest(shmidname); +#else /* !TKT_SHMEM */ + return KSUCCESS; +#endif /* !TKT_SHMEM */ } diff --git a/src/lib/krb4/g_ad_tkt.c b/src/lib/krb4/g_ad_tkt.c index b3abb2d..afcd0c6 100644 --- a/src/lib/krb4/g_ad_tkt.c +++ b/src/lib/krb4/g_ad_tkt.c @@ -19,6 +19,19 @@ extern int krb_debug; extern int swap_bytes; +/* Return the length of the string if a NUL is found within the first + * max_len bytes, otherwise, -1. */ +static int krb_strnlen(const char *str, int max_len) +{ + int i; + for(i = 0; i < max_len; i++) { + if(str[i] == '\0') { + return i; + } + } + return -1; +} + /* * get_ad_tkt obtains a new service ticket from Kerberos, using * the ticket-granting ticket which must be in the ticket file. @@ -136,11 +149,22 @@ get_ad_tkt(service,sinstance,realm,lifetime) return(AD_NOTGT); /* timestamp */ /* FIXME -- always 0 now, should we fill it in??? */ + if(pkt->length + 4 > sizeof(pkt->dat)) + return(INTK_ERR); memcpy((char *) (pkt->dat+pkt->length), (char *) &time_ws, 4); pkt->length += 4; + + if(pkt->length + 1 > sizeof(pkt->dat)) + return(INTK_ERR); *(pkt->dat+(pkt->length)++) = (char) lifetime; + + if(pkt->length + 1 + strlen(service) > sizeof(pkt->dat)) + return(INTK_ERR); (void) strcpy((char *) (pkt->dat+pkt->length),service); pkt->length += 1 + strlen(service); + + if(pkt->length + 1 + strlen(sinstance) > sizeof(pkt->dat)) + return(INTK_ERR); (void) strcpy((char *)(pkt->dat+pkt->length),sinstance); pkt->length += 1 + strlen(sinstance); @@ -199,18 +223,27 @@ get_ad_tkt(service,sinstance,realm,lifetime) memcpy((char *)ses, ptr, 8); ptr += 8; - (void) strcpy(s_name,ptr); + if(krb_strnlen(ptr, sizeof(s_name)) < 0) + return RD_AP_MODIFIED; + (void) strncpy(s_name,ptr,sizeof(s_name) - 1); + s_name[sizeof(s_name) - 1] = '\0'; ptr += strlen(s_name) + 1; - (void) strcpy(s_instance,ptr); + if(krb_strnlen(ptr, sizeof(s_instance)) < 0) + return RD_AP_MODIFIED; + (void) strncpy(s_instance,ptr,sizeof(s_instance)-1); + s_instance[sizeof(s_instance)-1] = '\0'; ptr += strlen(s_instance) + 1; - (void) strcpy(rlm,ptr); + if(krb_strnlen(ptr, sizeof(rlm)) < 0) + return RD_AP_MODIFIED; + (void) strncpy(rlm,ptr,sizeof(rlm) - 1); + rlm[sizeof(rlm)-1]; ptr += strlen(rlm) + 1; - lifetime = (unsigned long) ptr[0]; - kvno = (unsigned long) ptr[1]; - tkt->length = (int) ptr[2]; + lifetime = (unsigned char) ptr[0]; + kvno = (unsigned char) ptr[1]; + tkt->length = (unsigned char) ptr[2]; ptr += 3; memcpy((char *)(tkt->dat), ptr, tkt->length); ptr += tkt->length; diff --git a/src/lib/krb4/g_in_tkt.c b/src/lib/krb4/g_in_tkt.c index c9d6183..361273c 100644 --- a/src/lib/krb4/g_in_tkt.c +++ b/src/lib/krb4/g_in_tkt.c @@ -152,6 +152,20 @@ krb_mk_in_tkt_preauth(user, instance, realm, service, sinstance, life, *t = (unsigned char) AUTH_MSG_KDC_REQUEST; *t |= HOST_BYTE_ORDER; + /* Make sure the ticket data will fit into the buffer. */ + if(sizeof(pkt->dat) < 2 + /* protocol version + flags */ + 3 + strlen(user) + + 1 + strlen(instance) + + 1 + strlen(realm) + + 4 + /* timestamp */ + 1 + /* lifetime */ + 1 + strlen(service) + + 1 + strlen(sinstance) + + preauth_len) { + pkt->length = 0; + return INTK_ERR; + } + /* Now for the variable info */ (void) strcpy((char *)(pkt->dat+2),user); /* aname */ pkt->length = 3 + strlen(user); diff --git a/src/lib/krb4/g_krbhst.c b/src/lib/krb4/g_krbhst.c index 529ac07..4e0fd6d 100644 --- a/src/lib/krb4/g_krbhst.c +++ b/src/lib/krb4/g_krbhst.c @@ -52,9 +52,11 @@ get_krbhst_default(h, r, n) int n; { if (n==1) { - (void) strcpy(h,KRB_HOST); - (void) strcat(h,"."); - (void) strcat(h,r); /* KRB_HOST.REALM (ie. kerberos.CYGNUS.COM) */ + (void) strncpy(h,KRB_HOST,MAXHOSTNAMELEN-1); + h[MAXHOSTNAMELEN-1] = '\0'; + (void) strncat(h,".",MAXHOSTNAMELEN-1-strlen(h)); + (void) strncat(h,r,MAXHOSTNAMELEN-1-strlen(h)); + /* KRB_HOST.REALM (ie. kerberos.CYGNUS.COM) */ return(KSUCCESS); } else diff --git a/src/lib/krb4/g_krbrlm.c b/src/lib/krb4/g_krbrlm.c index 983150c..c750231 100644 --- a/src/lib/krb4/g_krbrlm.c +++ b/src/lib/krb4/g_krbrlm.c @@ -44,7 +44,8 @@ krb_get_lrealm(r,n) cnffile = krb__get_cnffile(); if (!cnffile) { if (n == 1) { - (void) strcpy(r, KRB_REALM); + (void) strncpy(r, KRB_REALM, REALM_SZ); + r[REALM_SZ - 1] = '\0'; return(KSUCCESS); } else diff --git a/src/lib/krb4/g_pw_in_tkt.c b/src/lib/krb4/g_pw_in_tkt.c index 6723df8..13f762b 100644 --- a/src/lib/krb4/g_pw_in_tkt.c +++ b/src/lib/krb4/g_pw_in_tkt.c @@ -176,7 +176,6 @@ krb_get_pw_in_tkt_preauth(user,instance,realm,service,sinstance,life,password) #include #include #else -char *strcpy(); int strcmp(); #endif #if defined(__svr4__) || defined(__SVR4) diff --git a/src/lib/krb4/in_tkt.c b/src/lib/krb4/in_tkt.c index ea17be8..a34f318 100644 --- a/src/lib/krb4/in_tkt.c +++ b/src/lib/krb4/in_tkt.c @@ -1,14 +1,29 @@ /* - * in_tkt.c + * lib/krb4/in_tkt.c * - * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute - * of Technology. + * Copyright 1985, 1986, 1987, 1988, 2000, 2001 by the Massachusetts + * Institute of Technology. All Rights Reserved. * - * For copying and distribution information, please see the file - * . + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. */ -#include "mit-copyright.h" #include #include #include "krb.h" @@ -34,7 +49,7 @@ extern int krb_debug; #define do_seteuid(e) seteuid((e)) #else #ifdef HAVE_SETRESUID -#define do_seteuid(e) setresuid(getuid(), (e), geteuid()) +#define do_seteuid(e) setresuid(-1, (e), -1) #else #ifdef HAVE_SETREUID #define do_seteuid(e) setreuid(geteuid(), (e)) @@ -55,7 +70,7 @@ in_tkt(pname,pinst) { int tktfile; uid_t me, metoo, getuid(), geteuid(); - struct stat buf; + struct stat statpre, statpost; int count; char *file = TKT_FILE; int fd; @@ -72,20 +87,49 @@ in_tkt(pname,pinst) me = getuid (); metoo = geteuid(); - if (lstat(file,&buf) == 0) { - if (buf.st_uid != me || !(buf.st_mode & S_IFREG) || - buf.st_mode & 077) { + if (lstat(file, &statpre) == 0) { + if (statpre.st_uid != me || !(statpre.st_mode & S_IFREG) + || statpre.st_nlink != 1 || statpre.st_mode & 077) { if (krb_debug) fprintf(stderr,"Error initializing %s",file); return(KFAILURE); } + /* + * Yes, we do uid twiddling here. It's not optimal, but some + * applications may expect that the ruid is what should really + * own the ticket file, e.g. setuid applications. + */ + if (me != metoo && do_seteuid(me) < 0) + return KFAILURE; /* file already exists, and permissions appear ok, so nuke it */ - if ((fd = open(file, O_RDWR|O_SYNC, 0)) < 0) + fd = open(file, O_RDWR|O_SYNC, 0); + (void)unlink(file); + if (me != metoo && do_seteuid(metoo) < 0) + return KFAILURE; + if (fd < 0) { goto out; /* can't zero it, but we can still try truncating it */ + } + + /* + * Do some additional paranoid things. The worst-case + * situation is that a user may be fooled into opening a + * non-regular file briefly if the file is in a directory with + * improper permissions. + */ + if (fstat(fd, &statpost) < 0) { + (void)close(fd); + goto out; + } + if (statpre.st_dev != statpost.st_dev + || statpre.st_ino != statpost.st_ino) { + (void)close(fd); + errno = 0; + goto out; + } memset(charbuf, 0, sizeof(charbuf)); - for (i = 0; i < buf.st_size; i += sizeof(charbuf)) + for (i = 0; i < statpost.st_size; i += sizeof(charbuf)) if (write(fd, charbuf, sizeof(charbuf)) != sizeof(charbuf)) { #ifndef NO_FSYNC (void) fsync(fd); @@ -117,12 +161,7 @@ in_tkt(pname,pinst) /* Set umask to ensure that we have write access on the created ticket file. */ mask = umask(077); - if ((tktfile = creat(file,0600)) < 0) { - umask(mask); - if (krb_debug) - fprintf(stderr,"Error initializing %s",TKT_FILE); - return(KFAILURE); - } + tktfile = open(file, O_RDWR|O_SYNC|O_CREAT|O_EXCL, 0600); umask(mask); if (me != metoo) { if (do_seteuid(metoo) < 0) { @@ -134,19 +173,11 @@ in_tkt(pname,pinst) if (krb_debug) printf("swapped UID's %d and %d\n",me,metoo); } - if (lstat(file,&buf) < 0) { + if (tktfile < 0) { if (krb_debug) fprintf(stderr,"Error initializing %s",TKT_FILE); return(KFAILURE); } - - if (buf.st_uid != me || !(buf.st_mode & S_IFREG) || - buf.st_mode & 077) { - if (krb_debug) - fprintf(stderr,"Error initializing %s",TKT_FILE); - return(KFAILURE); - } - count = strlen(pname)+1; if (write(tktfile,pname,count) != count) { (void) close(tktfile); @@ -159,8 +190,9 @@ in_tkt(pname,pinst) } (void) close(tktfile); #ifdef TKT_SHMEM - (void) strcpy(shmidname, file); - (void) strcat(shmidname, ".shm"); + (void) strncpy(shmidname, file, sizeof(shmidname) - 1); + shmidname[sizeof(shmidname) - 1] = '\0'; + (void) strncat(shmidname, ".shm", sizeof(shmidname) - 1 - strlen(shmidname)); return(krb_shm_create(shmidname)); #else /* !TKT_SHMEM */ return(KSUCCESS); diff --git a/src/lib/krb4/kntoln.c b/src/lib/krb4/kntoln.c index 8b6cdfe..f86599c 100644 --- a/src/lib/krb4/kntoln.c +++ b/src/lib/krb4/kntoln.c @@ -38,6 +38,10 @@ * KSUCCESS if all goes well, otherwise KFAILURE. */ +/* The definition of MAX_USERNAME here MUST agree with kuserok.c, or bad + * things will happen. */ +#define MAX_USERNAME 10 + krb_kntoln(ad,lname) AUTH_DAT *ad; char *lname; @@ -51,6 +55,7 @@ krb_kntoln(ad,lname) return(KFAILURE); if (strcmp(ad->prealm,lrealm)) return(KFAILURE); - (void) strcpy(lname,ad->pname); + (void) strncpy(lname,ad->pname,MAX_USERNAME-1); + lname[MAX_USERNAME - 1] = '\0'; return(KSUCCESS); } diff --git a/src/lib/krb4/kparse.c b/src/lib/krb4/kparse.c index 98e48fb..e72295c 100644 --- a/src/lib/krb4/kparse.c +++ b/src/lib/krb4/kparse.c @@ -54,8 +54,8 @@ static char *strutol(); -#ifndef HAVE_STRSAVE -static char *strsave(); +#ifndef HAVE_STRDUP +static char *strdup(); #endif #ifndef HAVE_STDLIB_H extern char *malloc(); @@ -104,7 +104,7 @@ int fGetParameterSet( fp,parm,parmcount ) keyword); return(PS_BAD_KEYWORD); } - parm[i].value = strsave( value ); + parm[i].value = strdup(value); break; } } @@ -552,34 +552,6 @@ int fGetChar(fp) return(ch); } - -/* - * Routine Name: strsave - * - * Function: return a pointer to a saved copy of the - * input string. the copy will be allocated - * as large as necessary. - * - * Explicit Parameters: pointer to string to save - * - * Implicit Parameters: None - * - * External Procedures: malloc,strcpy,strlen - * - * Side Effects: None - * - * Return Value: pointer to copied string - * - */ -#ifndef HAVE_STRSAVE -static char * strsave(p) - char *p; -{ - return(strcpy(malloc(strlen(p)+1),p)); -} -#endif - - /* * strutol changes all characters in a string to lower case, in place. * the pointer to the beginning of the string is returned. @@ -770,3 +742,42 @@ main(argc,argv) exit(0); } #endif + +/* + * Copyright (c) 1988 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that: (1) source distributions retain this entire copyright + * notice and comment, and (2) distributions including binaries display + * the following acknowledgement: ``This product includes software + * developed by the University of California, Berkeley and its contributors'' + * in the documentation or other materials provided with the distribution + * and in all advertising materials mentioning features or use of this + * software. Neither the name of the University 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +/* based on @(#)strdup.c 5.3 (Berkeley) 6/1/90 */ + +#ifndef HAVE_STRDUP +static char * +strdup(str) + const char *str; +{ + int len; + char *copy; + + if (!str) + return((char *)0); + len = strlen(str) + 1; + if (!(copy = malloc((u_int)len))) + return((char *)0); + memcpy(copy, str, len); + return(copy); +} +#endif diff --git a/src/lib/krb4/kuserok.c b/src/lib/krb4/kuserok.c index 0aee893..20587cb 100644 --- a/src/lib/krb4/kuserok.c +++ b/src/lib/krb4/kuserok.c @@ -118,8 +118,11 @@ kuserok(kdata, luser) if ((pwd = getpwnam(luser)) == NULL) { return(NOTOK); } - (void) strcpy(pbuf, pwd->pw_dir); - (void) strcat(pbuf, "/.klogin"); + if (strlen (pwd->pw_dir) + sizeof ("/.klogin") >= sizeof (pbuf)) + return NOTOK; + (void) strncpy(pbuf, pwd->pw_dir, sizeof(pbuf) - 1); + pbuf[sizeof(pbuf) - 1] = '\0'; + (void) strncat(pbuf, "/.klogin", sizeof(pbuf) - 1 - strlen(pbuf)); if (access(pbuf, F_OK)) { /* not accessible */ /* diff --git a/src/lib/krb4/mk_auth.c b/src/lib/krb4/mk_auth.c index 39a2e2f..a94a25d 100644 --- a/src/lib/krb4/mk_auth.c +++ b/src/lib/krb4/mk_auth.c @@ -124,8 +124,10 @@ krb_mk_auth(options, ticket, service, inst, realm, checksum, version, buf) realm = krb_realm; } - if (!(options & KOPT_DONT_CANON)) - (void) strncpy(inst, krb_get_phost(inst), INST_SZ); + if (!(options & KOPT_DONT_CANON)) { + (void) strncpy(inst, krb_get_phost(inst), INST_SZ - 1); + inst[INST_SZ-1] = 0; + } /* get the ticket if desired */ if (!(options & KOPT_DONT_MK_REQ)) { diff --git a/src/lib/krb4/mk_err.c b/src/lib/krb4/mk_err.c index e30e299..029aa9f 100644 --- a/src/lib/krb4/mk_err.c +++ b/src/lib/krb4/mk_err.c @@ -41,6 +41,14 @@ krb_mk_err(p,e,e_string) { u_char *start; + /* Just return the buffer length if p is NULL, because writing to the + * buffer would be a bad idea. Note that this feature is a change from + * previous versions, and can therefore only be used safely in this + * source tree, where we know this function supports it. */ + if(p == NULL) { + return 2 + sizeof(e) + strlen(e_string); + } + start = p; /* Create fixed part of packet */ diff --git a/src/lib/krb4/mk_req.c b/src/lib/krb4/mk_req.c index 1936cb2..468dccd 100644 --- a/src/lib/krb4/mk_req.c +++ b/src/lib/krb4/mk_req.c @@ -130,6 +130,19 @@ krb_mk_req(authent,service,instance,realm,checksum) if (retval != KSUCCESS) return (retval); + if(sizeof(authent->dat) / 8 < (3 + + strlen(realm) + 1 + 2 + + 3 + ticket->length + + strlen(cr.pname) + 1 + + strlen(cr.pinst) + 1 + + strlen(myrealm) + 1 + + 4 + /* checksum */ + 4 + /* timestamp */ + 7) / 8) { /* round-up */ + authent->length = 0; + return KFAILURE; + } + if (krb_ap_req_debug) DEB (("%s %s %s %s %s\n", service, instance, realm, cr.pname, cr.pinst)); diff --git a/src/lib/krb4/rd_req.c b/src/lib/krb4/rd_req.c index c9b6ac7..09f914d 100644 --- a/src/lib/krb4/rd_req.c +++ b/src/lib/krb4/rd_req.c @@ -108,6 +108,19 @@ krb_clear_key_krb5(ctx) krb5_key = 0; } +/* A helper function to let us see if a buffer is properly terminated. */ +static int +krb_strnlen(const char *str, size_t max_len) +{ + int i = 0; + for(i = 0; i < max_len; i++) { + if(str[i] == '\0') { + return i; + } + } + return -1; +} + /* * krb_rd_req() takes an AUTH_MSG_APPL_REQUEST or * AUTH_MSG_APPL_REQUEST_MUTUAL message created by krb_mk_req(), @@ -184,6 +197,8 @@ krb_rd_req(authent,service,instance,from_addr,ad,fn) krb5_keyblock keyblock; int status; + tkt->mbz = req_id->mbz = 0; + if (authent->length <= 0) return(RD_AP_MODIFIED); @@ -219,8 +234,13 @@ krb_rd_req(authent,service,instance,from_addr,ad,fn) mutual = 0; #endif /* lint */ s_kvno = *ptr++; /* get server key version */ - (void) strcpy(realm,ptr); /* And the realm of the issuing KDC */ - ptr += strlen(ptr) + 1; /* skip the realm "hint" */ + if(krb_strnlen(ptr, sizeof(realm)) < 0) { + return RD_AP_MODIFIED; /* must have been modified, the client wouldn't + try to trick us with wacky data */ + } + (void) strncpy(realm,ptr,REALM_SZ); /* And the realm of the issuing KDC */ + realm[REALM_SZ-1] = '\0'; + ptr += strlen(realm) + 1; /* skip the realm "hint" */ /* * If "fn" is NULL, key info should already be set; don't @@ -249,13 +269,16 @@ krb_rd_req(authent,service,instance,from_addr,ad,fn) return(RD_AP_UNDEC); #endif /* !NOENCRYPTION */ - (void) strcpy(st_rlm,realm); - (void) strcpy(st_nam,service); - (void) strcpy(st_inst,instance); + (void) strncpy(st_rlm,realm, sizeof(st_rlm) - 1); + st_rlm[sizeof(st_rlm) - 1] = '\0'; + (void) strncpy(st_nam,service, sizeof(st_nam) - 1); + st_nam[sizeof(st_nam) - 1] = '\0'; + (void) strncpy(st_inst,instance, sizeof(st_inst) - 1); + st_inst[sizeof(st_inst) - 1] = '\0'; } /* Get ticket from authenticator */ - tkt->length = (int) *ptr++; + tkt->length = (int) *ptr++ & 0xff; if ((tkt->length + (ptr+1 - (char *) authent->dat)) > authent->length) return(RD_AP_MODIFIED); memcpy((char *)(tkt->dat), ptr+1, tkt->length); @@ -324,13 +347,16 @@ krb_rd_req(authent,service,instance,from_addr,ad,fn) #define check_ptr() if ((ptr - (char *) req_id->dat) > req_id->length) return(RD_AP_MODIFIED); ptr = (char *) req_id->dat; - (void) strcpy(r_aname,ptr); /* Authentication name */ + (void) strncpy(r_aname,ptr,ANAME_SZ); /* Authentication name */ + r_aname[ANAME_SZ-1] = '\0'; ptr += strlen(r_aname)+1; check_ptr(); - (void) strcpy(r_inst,ptr); /* Authentication instance */ + (void) strncpy(r_inst,ptr,INST_SZ); /* Authentication instance */ + r_inst[INST_SZ-1] = '\0'; ptr += strlen(r_inst)+1; check_ptr(); - (void) strcpy(r_realm,ptr); /* Authentication name */ + (void) strncpy(r_realm,ptr,REALM_SZ); /* Authentication name */ + r_realm[REALM_SZ-1] = '\0'; ptr += strlen(r_realm)+1; check_ptr(); memcpy((char *)&ad->checksum, ptr, 4); /* Checksum */ diff --git a/src/lib/krb4/rd_svc_key.c b/src/lib/krb4/rd_svc_key.c index 831becd..a9b6fd5 100644 --- a/src/lib/krb4/rd_svc_key.c +++ b/src/lib/krb4/rd_svc_key.c @@ -183,7 +183,7 @@ krb54_get_service_keyblock(service,instance,realm,kvno,file,keyblock) if ((retval = krb5_kt_resolve(krb5__krb4_context, keytabname, &kt_id))) goto errout; - + if ((retval = krb5_kt_get_entry(krb5__krb4_context, kt_id, princ, kvno, 0, &kt_entry))) { krb5_kt_close(krb5__krb4_context, kt_id); @@ -192,6 +192,12 @@ krb54_get_service_keyblock(service,instance,realm,kvno,file,keyblock) retval = krb5_copy_keyblock_contents(krb5__krb4_context, &kt_entry.key, keyblock); + /* Bash types */ + /* KLUDGE! If it's a non-raw des3 key, bash its enctype */ + /* See kdc/kerberos_v4.c */ + if (keyblock->enctype == ENCTYPE_DES3_CBC_SHA1 || + keyblock->enctype == ENCTYPE_LOCAL_DES3_HMAC_SHA1) + keyblock->enctype = ENCTYPE_DES3_CBC_RAW; krb5_kt_free_entry(krb5__krb4_context, &kt_entry); krb5_kt_close (krb5__krb4_context, kt_id); diff --git a/src/lib/krb4/realmofhost.c b/src/lib/krb4/realmofhost.c index 90e01bb..1e4b786 100644 --- a/src/lib/krb4/realmofhost.c +++ b/src/lib/krb4/realmofhost.c @@ -131,14 +131,18 @@ krb_realmofhost(host) if (domain && (strlen(trans_host) == strlen(domain)) && !strcasecmp (trans_host, domain)) { /* got domain match, save for later */ - (void) strcpy (ret_realm, trans_realm); + (void) strncpy (ret_realm, trans_realm, + sizeof(ret_realm) - 1); + ret_realm[sizeof(ret_realm) - 1] = '\0'; continue; } } else { /* want exact match of hostname */ if ((strlen(lhost) == strlen(trans_host)) && !strcasecmp (trans_host, lhost)) { - (void) strcpy (ret_realm, trans_realm); + (void) strncpy (ret_realm, trans_realm, + sizeof(ret_realm) - 1); + ret_realm[sizeof(ret_realm) - 1] = '\0'; break; } } diff --git a/src/lib/krb4/recvauth.c b/src/lib/krb4/recvauth.c index e62e3f9..2a66656 100644 --- a/src/lib/krb4/recvauth.c +++ b/src/lib/krb4/recvauth.c @@ -188,9 +188,12 @@ krb_recvauth(options, fd, ticket, service, instance, faddr, laddr, kdata, if (i < KRB_SENDAUTH_VLEN) { /* since we already got the space, and part of the ticket, we read fewer bytes to get the rest of the ticket */ + int len_to_read = tkt_len - KRB_SENDAUTH_VLEN + 1 + i; + if (len_to_read <= 0) + return KFAILURE; if (krb_net_read(fd, (char *)(tmp_buf+KRB_SENDAUTH_VLEN), - (int) (tkt_len - KRB_SENDAUTH_VLEN + 1 + i)) - != (int)(tkt_len - KRB_SENDAUTH_VLEN + 1 + i)) + len_to_read) + != len_to_read) return(errno); } else { if (krb_net_read(fd, (char *)(tmp_buf+i), (int)tkt_len) != diff --git a/src/lib/krb4/send_to_kdc.c b/src/lib/krb4/send_to_kdc.c index c7e0fb3..f93b9d0 100644 --- a/src/lib/krb4/send_to_kdc.c +++ b/src/lib/krb4/send_to_kdc.c @@ -94,12 +94,13 @@ send_to_kdc(pkt,rpkt,realm) * local realm. */ if (realm) - (void) strcpy(lrealm, realm); + (void) strncpy(lrealm, realm, sizeof(lrealm) - 1); else if (krb_get_lrealm(lrealm,1)) { DEB (("%s: can't get local realm\n", prog)); return(SKDC_CANT); } + lrealm[sizeof(lrealm) - 1] = '\0'; DEB (("lrealm is %s\n", lrealm)); if (SOCKET_INITIALIZE()) { diff --git a/src/lib/krb4/sendauth.c b/src/lib/krb4/sendauth.c index 9b8fb39..76c470c 100644 --- a/src/lib/krb4/sendauth.c +++ b/src/lib/krb4/sendauth.c @@ -208,7 +208,8 @@ krb_sendauth(options, fd, ticket, service, inst, realm, checksum, } /* copy instance into local storage, so mk_auth can canonicalize */ - (void) strncpy(srv_inst, inst, INST_SZ); + (void) strncpy(srv_inst, inst, INST_SZ-1); + srv_inst[INST_SZ-1] = 0; rem = krb_mk_auth (options, ticket, service, srv_inst, realm, checksum, version, packet); if (rem != KSUCCESS) diff --git a/src/lib/krb4/tf_util.c b/src/lib/krb4/tf_util.c index ebf500b..faf115e 100644 --- a/src/lib/krb4/tf_util.c +++ b/src/lib/krb4/tf_util.c @@ -1,20 +1,38 @@ /* - * tf_util.c + * lib/krb4/tf_util.c * - * Copyright 1987, 1988 by the Massachusetts Institute of Technology. + * Copyright 1985, 1986, 1987, 1988, 2000, 2001 by the Massachusetts + * Institute of Technology. All Rights Reserved. * - * For copying and distribution information, please see the file - * . + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. */ -#include "mit-copyright.h" - #include "krb.h" #include "k5-int.h" #include #include #include +#ifdef HAVE_UNISTD_H +#include +#endif #include #include @@ -44,7 +62,6 @@ char *shmat(); #ifdef NEED_UTIMES #include -#include #ifdef __SCO__ #include #endif @@ -62,6 +79,20 @@ int utimes(path, times) } #endif +#ifdef HAVE_SETEUID +#define do_seteuid(e) seteuid((e)) +#else +#ifdef HAVE_SETRESUID +#define do_seteuid(e) setresuid(-1, (e), -1) +#else +#ifdef HAVE_SETREUID +#define do_seteuid(e) setreuid(geteuid(), (e)) +#else +#define do_seteuid(e) (errno = EPERM, -1) +#endif +#endif +#endif + /* * fd must be initialized to something that won't ever occur as a real * file descriptor. Since open(2) returns only non-negative numbers as @@ -149,7 +180,7 @@ int tf_init(tf_name, rw) int rw; { int wflag; - uid_t me= getuid(); + uid_t me, metoo; struct stat stat_buf, stat_buffd; #ifdef TKT_SHMEM char shmidname[MAXPATHLEN]; @@ -163,6 +194,7 @@ int tf_init(tf_name, rw) } me = getuid(); + metoo = geteuid(); switch (rw) { case R_TKT_FIL: @@ -181,8 +213,9 @@ int tf_init(tf_name, rw) tf_name = tkt_string(); #ifdef TKT_SHMEM - (void) strcpy(shmidname, tf_name); - (void) strcat(shmidname, ".shm"); + (void) strncpy(shmidname, tf_name, sizeof(shmidname) - 1); + shmidname[sizeof(shmidname) - 1] = '\0'; + (void) strncat(shmidname, ".shm", sizeof(shmidname) - 1 - strlen(shmidname)); #endif /* TKT_SHMEM */ /* @@ -195,8 +228,30 @@ int tf_init(tf_name, rw) curpos = sizeof(tfbfr); #ifdef TKT_SHMEM + if (lstat(shmidname, &stat_buf) < 0) { + switch (errno) { + case ENOENT: + return NO_TKT_FIL; + default: + return TKT_FIL_ACC; + } + } + if (stat_buf.st_uid != me || !(stat_buf.st_mode & S_IFREG) + || stat_buf.st_nlink != 1 || stat_buf.st_mode & 077) { + return TKT_FIL_ACC; + } + + /* + * Yes, we do uid twiddling here. It's not optimal, but some + * applications may expect that the ruid is what should really own + * the ticket file, e.g. setuid applications. + */ + if (me != metoo && do_seteuid(me) < 0) + return KFAILURE; sfp = fopen(shmidname, "r"); /* only need read/write on the actual tickets */ + if (me != metoo && do_seteuid(metoo) < 0) + return KFAILURE; if (sfp == 0) { switch(errno) { case ENOENT: @@ -206,10 +261,11 @@ int tf_init(tf_name, rw) } } - /* lstat() and fstat() the file to check that the file we opened is the * - * one we think it is, and to check ownership. */ - if ((fstat(sfp->_file, &stat_buffd) < 0) || - (lstat(shmidname, &stat_buf) < 0)) { + /* + * fstat() the file to check that the file we opened is the one we + * think it is. + */ + if (fstat(fileno(sfp), &stat_buffd) < 0) { (void) close(fd); fd = -1; switch(errno) { @@ -270,8 +326,25 @@ int tf_init(tf_name, rw) tmp_shm_addr = krb_shm_addr; #endif /* TKT_SHMEM */ + if (lstat(tf_name, &stat_buf) < 0) { + switch (errno) { + case ENOENT: + return NO_TKT_FIL; + default: + return TKT_FIL_ACC; + } + } + if (stat_buf.st_uid != me || !(stat_buf.st_mode & S_IFREG) + || stat_buf.st_nlink != 1 || stat_buf.st_mode & 077) { + return TKT_FIL_ACC; + } + if (wflag) { + if (me != metoo && do_seteuid(me) < 0) + return KFAILURE; fd = open(tf_name, O_RDWR, 0600); + if (me != metoo && do_seteuid(metoo) < 0) + return KFAILURE; if (fd < 0) { switch(errno) { case ENOENT: @@ -280,10 +353,11 @@ int tf_init(tf_name, rw) return TKT_FIL_ACC; } } - /* lstat() and fstat() the file to check that the file we opened is the * - * one we think it is, and to check ownership. */ - if ((fstat(fd, &stat_buffd) < 0) || - (lstat(tf_name, &stat_buf) < 0)) { + /* + * fstat() the file to check that the file we opened is the + * one we think it is, and to check ownership. + */ + if (fstat(fd, &stat_buffd) < 0) { (void) close(fd); fd = -1; switch(errno) { @@ -326,7 +400,11 @@ int tf_init(tf_name, rw) * for read-only operations and locked for shared access. */ + if (me != metoo && do_seteuid(me) < 0) + return KFAILURE; fd = open(tf_name, O_RDONLY, 0600); + if (me != metoo && do_seteuid(metoo) < 0) + return KFAILURE; if (fd < 0) { switch(errno) { case ENOENT: @@ -335,10 +413,11 @@ int tf_init(tf_name, rw) return TKT_FIL_ACC; } } - /* lstat() and fstat() the file to check that the file we opened is the * - * one we think it is, and to check ownership. */ - if ((fstat(fd, &stat_buffd) < 0) || - (lstat(tf_name, &stat_buf) < 0)) { + /* + * fstat() the file to check that the file we opened is the one we + * think it is, and to check ownership. + */ + if (fstat(fd, &stat_buffd) < 0) { (void) close(fd); fd = -1; switch(errno) { diff --git a/src/lib/krb4/win_store.c b/src/lib/krb4/win_store.c index 50507aa..28d11bd 100644 --- a/src/lib/krb4/win_store.c +++ b/src/lib/krb4/win_store.c @@ -62,15 +62,17 @@ krb__get_cnffile() char defname[FILENAME_MAX]; UINT rc; - rc = GetWindowsDirectory(defname, sizeof(defname)); + defname[sizeof(defname) - 1] = '\0'; + rc = GetWindowsDirectory(defname, sizeof(defname) - 1); assert(rc > 0); - strcat(defname, "\\"); + strncat(defname, "\\", sizeof(defname) - 1 - strlen(defname)); - strcat(defname, DEF_KRB_CONF); + strncat(defname, DEF_KRB_CONF, sizeof(defname) - 1 - strlen(defname)); + cnfname[sizeof(cnfname) - 1] = '\0'; GetPrivateProfileString(INI_FILES, INI_KRB_CONF, defname, - cnfname, sizeof(cnfname), KERBEROS_INI); + cnfname, sizeof(cnfname) - 1, KERBEROS_INI); cnffile = fopen(cnfname, "r"); @@ -94,15 +96,17 @@ krb__get_realmsfile() char defname[FILENAME_MAX]; UINT rc; - rc = GetWindowsDirectory(defname, sizeof(defname)); + defname[sizeof(defname) - 1] = '\0'; + rc = GetWindowsDirectory(defname, sizeof(defname) - 1); assert(rc > 0); - strcat(defname, "\\"); + strncat(defname, "\\", sizeof(defname) - 1 - strlen(defname)); - strcat(defname, DEF_KRB_REALMS); + strncat(defname, DEF_KRB_REALMS, sizeof(defname) - 1 - strlen(defname)); + defname[sizeof(defname) - 1] = '\0'; GetPrivateProfileString(INI_FILES, INI_KRB_REALMS, defname, - realmsname, sizeof(realmsname), KERBEROS_INI); + realmsname, sizeof(realmsname) - 1, KERBEROS_INI); realmsfile = fopen(realmsname, "r"); diff --git a/src/lib/krb5/ChangeLog b/src/lib/krb5/ChangeLog index a2ab81a..13007dd 100644 --- a/src/lib/krb5/ChangeLog +++ b/src/lib/krb5/ChangeLog @@ -1,3 +1,41 @@ +2002-05-22 Alexandra Ellwood + * krb5_libinit.c: Conditionalized error table loading for + Mac OS X. Error tables should always be loaded on other + platforms. + +2002-02-28 Alexandra Ellwood + * krb5_libinit.c: Added an include for com_err.h since + it is not included by error table headers on Mac OS X. Also + fixed busted check for Mac OS + +2001-12-03 Miro Jurisic + + * krb5_libinit.c: punted the Mac OS 9 sleep notification code + +2001-11-05 Tom Yu + + * Makefile.in (LIBMINOR): Bump due to changes in error tables. + +2000-11-29 Miro Jurisic + + * krb5_libinit.c: Install a callback in the Mac OS sleep + queue to get notification of the machine coming out + of sleep, in order to refresh the cached uptime to + real time offset + +2000-10-02 Alexandra Ellwood + + * Makefile.in (LIBMAJOR, LIBMINOR): Bump version. + +2000-04-18 Ken Raeburn + + * Makefile.in (SHLIB_EXPLIBS): Add @RESOLV_LIB@. + 2000-03-14 Ken Raeburn * configure.in: Check for gethostbyname2. diff --git a/src/lib/krb5/Makefile.in b/src/lib/krb5/Makefile.in index 0dab1f3..3b42585 100644 --- a/src/lib/krb5/Makefile.in +++ b/src/lib/krb5/Makefile.in @@ -32,8 +32,8 @@ LIBDONE= error_tables/DONE asn.1/DONE ccache/DONE ccache/stdio/DONE \ STLIBOBJS=krb5_libinit.o LIB=krb5 -LIBMAJOR=2 -LIBMINOR=2 +LIBMAJOR=3 +LIBMINOR=1 STOBJLISTS= \ OBJS.ST \ @@ -58,7 +58,7 @@ RELDIR=krb5 SHLIB_EXPDEPS = \ $(TOPLIBD)/libk5crypto$(SHLIBEXT) \ $(TOPLIBD)/libcom_err$(SHLIBEXT) -SHLIB_EXPLIBS=-lk5crypto -lcom_err @GEN_LIB@ +SHLIB_EXPLIBS=-lk5crypto -lcom_err @GEN_LIB@ @RESOLV_LIB@ SHLIB_DIRS=-L$(TOPLIBD) SHLIB_RDIRS=$(KRB5_LIBDIR) diff --git a/src/lib/krb5/asn.1/ChangeLog b/src/lib/krb5/asn.1/ChangeLog index 96f7098..bc8b40a 100644 --- a/src/lib/krb5/asn.1/ChangeLog +++ b/src/lib/krb5/asn.1/ChangeLog @@ -1,3 +1,94 @@ +2002-04-08 Tom Yu + + * asn1_get.c (asn1_get_length): Check for negative length. + +2002-03-06 Alexandra Ellwood + * asn1_encode.c: Removed unused Mac OS 9 code + +2002-02-28 Alexandra Ellwood + * asn1_get.c: removed unused variable to reduce warnings + +2001-10-29 Miro Jurisic + * pullup from krb5-1-2 branch after krb5-1-2-2-bp + * asn1_encode.c: Updated Utilities.h #include + +2001-01-31 Tom Yu + + * asn1buf.c (asn1buf_sync): Add new arguments to include the full + complement of data about a prefetched tag, as well as to indicate + whether the prefetched tag or the surrounding sequence is of an + indefinite length. + (asn1buf_skiptail): Add new arguments to indicate whether the + prefetched tag is indefinite, as well as its length. This + facilitates proper skipping of trailing garbage. + (asn1buf_remains): Add new argument to indicate whether the + surrounding encoding is indefinite. Don't advance buf->next if an + EOC encoding is detected; the caller will do that. + [pullup from trunk] + + * asn1buf.h: Update prototypes. [pullup from trunk] + + * asn1_get.c (asn1_get_tag_indef): Don't treat EOC encoding as + special anymore, since previous behavior was overloading the + tag number in a bad way. Also, report a MISMATCH_INDEF error if + the tag encoding is for the forbidden primitive constructed + encoding. [pullup from trunk] + + * asn1_k_decode.c (next_tag): Call get_tag_indef() in order to get + information about whether the length is indefinite. Don't check + the tag class and construction explicitly. + (get_eoc): New macro to get a tag and check if it is an EOC + encoding. + (get_field, opt_field): Move the check for the tag class and + construction to here. + (get_field_body, get_lenfield_body): Call get_eoc() instead of + next_tag() if we are decoding a constructed indefinite encoding. + (begin_structure): Use a different variable to indicate whether + the sequence is indefinite as opposed to whether an individual + field is indefinite. + (end_structure): Update to new calling convention of + asn1buf_sync(). + (sequence_of): Rewrite significantly. + (sequence_of_common): Move the bulk of previous sequence_of() + macro to here. Does not declare some variables that sequence_of() + declares. + (sequence_of_no_tagvars): Similar to sequence_of() macro but + declares different variables for the purpose of prefetching the + final tag. + (end_sequence_of_no_tagvars): Similar to end_sequence_of() macro + but uses variables declared by the sequence_of_no_tagvars() macro + to prefetch the final tag. + (asn1_decode_principal_name): Update for new asn1buf_remains() + calling convention. Call sequence_of_no_tagvars(), etc. instead + of sequence_of(), etc. in order to not declare shadowing + block-local variables. + (decode_array_body): Update for new asn1buf_remains() calling + convention. + (asn1_decode_sequence_of_enctype): Update for new + asn1buf_remains() calling convention. + [pullup from trunk] + + * krb5_decode.c (next_tag): Call get_tag_indef() in order to get + information about whether the length is indefinite. Don't check + the tag class and construction explicitly. + (get_eoc): New macro to get a tag and check if it is an EOC + encoding. + (get_field, opt_field): Move the check for the tag class and + construction to here. + (get_field_body, get_lenfield_body): Call get_eoc() instead of + next_tag() if we are decoding a constructed indefinite encoding. + (begin_structure): Use a different variable to indicate whether + the sequence is indefinite as opposed to whether an individual + field is indefinite. + (end_structure): Update to new calling convention of + asn1buf_sync(). + [pullup from trunk] + +2000-09-28 Miro Jurisic + + * asn1_encode.c (asn1_encode_generaltime): Fixed the Mac code to + use the correct epoch. + 2000-02-06 Ken Raeburn Patches from Frank Cusack for helping in preauth replay diff --git a/src/lib/krb5/asn.1/asn1_encode.c b/src/lib/krb5/asn.1/asn1_encode.c index 7ef89c8..7cc8042 100644 --- a/src/lib/krb5/asn.1/asn1_encode.c +++ b/src/lib/krb5/asn.1/asn1_encode.c @@ -186,12 +186,6 @@ asn1_error_code asn1_encode_ia5string(buf, len, val, retlen) return 0; } -#ifdef macintosh -#define EPOCH ((70 * 365 * 24 * 60 * 60) + (17 * 24 * 60 * 60) + (getTimeZoneOffset() * 60 * 60)) -#else -#define EPOCH (0) -#endif - asn1_error_code asn1_encode_generaltime(buf, val, retlen) asn1buf * buf; const time_t val; @@ -201,9 +195,11 @@ asn1_error_code asn1_encode_generaltime(buf, val, retlen) struct tm *gtime; char s[16]; int length, sum=0; - time_t gmt_time; + time_t gmt_time = val; - gmt_time = val + EPOCH; +#ifdef macintosh + unix_time_to_msl_time (&gmt_time); +#endif gtime = gmtime(&gmt_time); /* diff --git a/src/lib/krb5/asn.1/asn1_get.c b/src/lib/krb5/asn.1/asn1_get.c index 20334a2..90f5dd9 100644 --- a/src/lib/krb5/asn.1/asn1_get.c +++ b/src/lib/krb5/asn.1/asn1_get.c @@ -42,12 +42,6 @@ asn1_get_tag_indef(buf, class, construction, tagnum, retlen, indef) *tagnum = ASN1_TAGNUM_CEILING; return 0; } - /* Allow for the indefinite encoding */ - if ( !*(buf->next) && !*(buf->next + 1)) { - buf->next += 2; - *tagnum = ASN1_TAGNUM_CEILING; - return 0; - } retval = asn1_get_id(buf,class,construction,tagnum); if(retval) return retval; retval = asn1_get_length(buf,retlen,indef); @@ -63,7 +57,6 @@ asn1_get_tag(buf, class, construction, tagnum, retlen) asn1_tagnum *tagnum; int *retlen; { - asn1_error_code retval; int indef; return asn1_get_tag_indef(buf, class, construction, tagnum, retlen, &indef); @@ -149,6 +142,8 @@ asn1_error_code asn1_get_length(buf, retlen, indef) if(retval) return retval; len = (len<<8) + (int)o; } + if (len < 0) + return ASN1_OVERRUN; if (indef != NULL && !len) *indef = 1; if(retlen != NULL) *retlen = len; diff --git a/src/lib/krb5/asn.1/asn1_k_decode.c b/src/lib/krb5/asn.1/asn1_k_decode.c index 6f72d8e..a855527 100644 --- a/src/lib/krb5/asn.1/asn1_k_decode.c +++ b/src/lib/krb5/asn.1/asn1_k_decode.c @@ -39,10 +39,16 @@ int length,taglen #define unused_var(x) if(0) x=0 #define next_tag()\ -retval = asn1_get_tag(&subbuf,&class,&construction,&tagnum,&taglen);\ -if(retval) return retval;\ -if(class != CONTEXT_SPECIFIC || construction != CONSTRUCTED)\ - return ASN1_BAD_ID +retval = asn1_get_tag_indef(&subbuf,&class,&construction,\ + &tagnum,&taglen,&indef);\ +if(retval) return retval; + +#define get_eoc() \ +retval = asn1_get_tag_indef(&subbuf,&class,&construction, \ + &tagnum,&taglen,&indef); \ +if(retval) return retval; \ +if(class != UNIVERSAL || tagnum || indef) \ + return ASN1_MISSING_EOC #define alloc_field(var,type)\ var = (type*)calloc(1,sizeof(type));\ @@ -59,15 +65,21 @@ if(class != APPLICATION || construction != CONSTRUCTED ||\ #define get_field_body(var,decoder)\ retval = decoder(&subbuf,&(var));\ if(retval) return retval;\ -if(!taglen) { next_tag(); }\ +if(!taglen && indef) { get_eoc(); }\ next_tag() #define get_field(var,tagexpect,decoder)\ if(tagnum > (tagexpect)) return ASN1_MISSING_FIELD;\ if(tagnum < (tagexpect)) return ASN1_MISPLACED_FIELD;\ +if((class != CONTEXT_SPECIFIC || construction != CONSTRUCTED) \ + && (tagnum || taglen || class != UNIVERSAL)) \ + return ASN1_BAD_ID;\ get_field_body(var,decoder) #define opt_field(var,tagexpect,decoder,optvalue)\ +if((class != CONTEXT_SPECIFIC || construction != CONSTRUCTED) \ + && (tagnum || taglen || class != UNIVERSAL)) \ + return ASN1_BAD_ID;\ if(tagnum == (tagexpect)){\ get_field_body(var,decoder); }\ else var = optvalue @@ -76,12 +88,15 @@ else var = optvalue #define get_lenfield_body(len,var,decoder)\ retval = decoder(&subbuf,&(len),&(var));\ if(retval) return retval;\ -if(!taglen) { next_tag(); }\ +if(!taglen && indef) { get_eoc(); }\ next_tag() #define get_lenfield(len,var,tagexpect,decoder)\ if(tagnum > (tagexpect)) return ASN1_MISSING_FIELD;\ if(tagnum < (tagexpect)) return ASN1_MISPLACED_FIELD;\ +if((class != CONTEXT_SPECIFIC || construction != CONSTRUCTED) \ + && (tagnum || taglen || class != UNIVERSAL)) \ + return ASN1_BAD_ID;\ get_lenfield_body(len,var,decoder) #define opt_lenfield(len,var,tagexpect,decoder)\ @@ -92,30 +107,58 @@ else { len = 0; var = 0; } #define begin_structure()\ asn1buf subbuf;\ +int seqindef;\ int indef;\ -retval = asn1_get_sequence(buf,&length,&indef);\ +retval = asn1_get_sequence(buf,&length,&seqindef);\ if(retval) return retval;\ -retval = asn1buf_imbed(&subbuf,buf,length,indef);\ +retval = asn1buf_imbed(&subbuf,buf,length,seqindef);\ if(retval) return retval;\ next_tag() #define end_structure()\ -retval = asn1buf_sync(buf,&subbuf,tagnum,length);\ +retval = asn1buf_sync(buf,&subbuf,class,tagnum,length,indef,seqindef);\ if(retval) return retval -#define sequence_of(buf)\ -int size=0;\ -asn1buf seqbuf;\ -int length;\ -int indef;\ -retval = asn1_get_sequence(buf,&length,&indef);\ -if(retval) return retval;\ -retval = asn1buf_imbed(&seqbuf,buf,length,indef);\ +#define sequence_of(buf) \ +unsigned int length, taglen; \ +asn1_class class; \ +asn1_construction construction; \ +asn1_tagnum tagnum; \ +int indef; \ +sequence_of_common(buf) + +#define sequence_of_common(buf) \ +int size=0; \ +asn1buf seqbuf; \ +int seqofindef; \ +retval = asn1_get_sequence(buf,&length,&seqofindef); \ +if(retval) return retval; \ +retval = asn1buf_imbed(&seqbuf,buf,length,seqofindef); \ if(retval) return retval -#define end_sequence_of(buf)\ -retval = asn1buf_sync(buf,&seqbuf,ASN1_TAGNUM_CEILING,length);\ -if(retval) return retval +#define sequence_of_no_tagvars(buf) \ +asn1_class eseqclass; \ +asn1_construction eseqconstr; \ +asn1_tagnum eseqnum; \ +unsigned int eseqlen; \ +int eseqindef; \ +sequence_of_common(buf) + +#define end_sequence_of_no_tagvars(buf) \ +retval = asn1_get_tag_indef(&seqbuf,&eseqclass,&eseqconstr, \ + &eseqnum,&eseqlen,&eseqindef); \ +if(retval) return retval; \ +retval = asn1buf_sync(buf,&seqbuf,eseqclass,eseqnum, \ + eseqlen,eseqindef,seqofindef); \ +if(retval) return retval; + +#define end_sequence_of(buf) \ +retval = asn1_get_tag_indef(&seqbuf,&class,&construction, \ + &tagnum,&taglen,&indef); \ +if(retval) return retval; \ +retval = asn1buf_sync(buf,&seqbuf,class,tagnum, \ + length,indef,seqofindef); \ +if(retval) return retval; #define cleanup()\ return 0 @@ -206,8 +249,8 @@ asn1_error_code asn1_decode_principal_name(buf, val) { begin_structure(); get_field((*val)->type,0,asn1_decode_int32); - { sequence_of(&subbuf); - while(asn1buf_remains(&seqbuf)){ + { sequence_of_no_tagvars(&subbuf); + while(asn1buf_remains(&seqbuf,seqofindef) > 0){ size++; if ((*val)->data == NULL) (*val)->data = (krb5_data*)malloc(size*sizeof(krb5_data)); @@ -221,8 +264,12 @@ asn1_error_code asn1_decode_principal_name(buf, val) if(retval) return retval; } (*val)->length = size; - end_sequence_of(&subbuf); + end_sequence_of_no_tagvars(&subbuf); + } + if (indef) { + get_eoc(); } + next_tag(); end_structure(); (*val)->magic = KV5M_PRINCIPAL; } @@ -528,7 +575,7 @@ if(*(array) == NULL) return ENOMEM;\ type *elt;\ \ { sequence_of(buf);\ - while(asn1buf_remains(&seqbuf) > 0){\ + while(asn1buf_remains(&seqbuf,seqofindef) > 0){\ alloc_field(elt,type);\ get_element(elt,decoder);\ array_append(val,size,elt,type);\ @@ -660,7 +707,7 @@ asn1_error_code asn1_decode_sequence_of_enctype(buf, num, val) { asn1_error_code retval; { sequence_of(buf); - while(asn1buf_remains(&seqbuf) > 0){ + while(asn1buf_remains(&seqbuf,seqofindef) > 0){ size++; if (*val == NULL) *val = (krb5_enctype*)malloc(size*sizeof(krb5_enctype)); diff --git a/src/lib/krb5/asn.1/asn1buf.c b/src/lib/krb5/asn.1/asn1buf.c index 9c63927..4be82fb 100644 --- a/src/lib/krb5/asn.1/asn1buf.c +++ b/src/lib/krb5/asn.1/asn1buf.c @@ -54,6 +54,9 @@ #include #include "asn1_get.h" +#define asn1_is_eoc(class, num, indef) \ +((class) == UNIVERSAL && !(num) && !(indef)) + asn1_error_code asn1buf_create(buf) asn1buf ** buf; { @@ -91,34 +94,35 @@ asn1_error_code asn1buf_imbed(subbuf, buf, length, indef) return 0; } -asn1_error_code asn1buf_sync(buf, subbuf, lasttag, length) +asn1_error_code asn1buf_sync(buf, subbuf, class, lasttag, length, indef, seqindef) asn1buf * buf; asn1buf * subbuf; + const asn1_class class; const asn1_tagnum lasttag; const int length; + const int indef; + const int seqindef; { asn1_error_code retval; - if (length) { + if (!seqindef) { + /* sequence was encoded as definite length */ buf->next = subbuf->bound + 1; + } else if (!asn1_is_eoc(class, lasttag, indef)) { + retval = asn1buf_skiptail(subbuf, length, indef); + if (retval) + return retval; } else { - /* - * indefinite length: - * - * Note that asn1_get_tag() returns ASN1_TAGNUM_CEILING - * for an EOC encoding. - */ - if (lasttag != ASN1_TAGNUM_CEILING) { - retval = asn1buf_skiptail(subbuf); - if (retval) return retval; - } + /* We have just read the EOC octets. */ buf->next = subbuf->next; } return 0; } -asn1_error_code asn1buf_skiptail(buf) +asn1_error_code asn1buf_skiptail(buf, length, indef) asn1buf *buf; + const int length; + const int indef; { asn1_error_code retval; asn1_class class; @@ -126,15 +130,29 @@ asn1_error_code asn1buf_skiptail(buf) asn1_tagnum tagnum; int taglen; int nestlevel; + int tagindef; - nestlevel = 1; + nestlevel = 1 + indef; + if (!indef) { + if (length <= buf->bound - buf->next + 1) + buf->next += length; + else + return ASN1_OVERRUN; + } while (nestlevel > 0) { - retval = asn1_get_tag(buf, &class, &construction, &tagnum, &taglen); + retval = asn1_get_tag_indef(buf, &class, &construction, &tagnum, + &taglen, &tagindef); if (retval) return retval; - if (construction == CONSTRUCTED && taglen == 0) + if (!tagindef) { + if (taglen <= buf->bound - buf->next + 1) + buf->next += taglen; + else + return ASN1_OVERRUN; + } + if (tagindef) nestlevel++; - if (tagnum == ASN1_TAGNUM_CEILING) - nestlevel--; + if (asn1_is_eoc(class, tagnum, tagindef)) + nestlevel--; /* got an EOC encoding */ } return 0; } @@ -247,8 +265,9 @@ asn1_error_code asn1buf_remove_charstring(buf, len, s) return 0; } -int asn1buf_remains(buf) +int asn1buf_remains(buf, indef) asn1buf *buf; + int indef; { int remain; if(buf == NULL || buf->base == NULL) return 0; @@ -256,15 +275,9 @@ int asn1buf_remains(buf) if (remain <= 0) return remain; /* * Two 0 octets means the end of an indefinite encoding. - * - * XXX Do we need to test to make sure we'er actually doing an - * indefinite encoding here? */ - if ( !*(buf->next) && !*(buf->next + 1)) { - /* buf->bound = buf->next + 1; */ - buf->next += 2; + if (indef && remain >= 2 && !*(buf->next) && !*(buf->next + 1)) return 0; - } else return remain; } @@ -379,9 +392,9 @@ asn1_error_code asn1buf_ensure_space(buf, amount) asn1buf * buf; const int amount; { - int free = asn1buf_free(buf); - if(free < amount){ - asn1_error_code retval = asn1buf_expand(buf, amount-free); + int avail = asn1buf_free(buf); + if(avail < amount){ + asn1_error_code retval = asn1buf_expand(buf, amount-avail); if(retval) return retval; } return 0; diff --git a/src/lib/krb5/asn.1/asn1buf.h b/src/lib/krb5/asn.1/asn1buf.h index 52fc0d6..3f4a6ac 100644 --- a/src/lib/krb5/asn.1/asn1buf.h +++ b/src/lib/krb5/asn.1/asn1buf.h @@ -121,14 +121,17 @@ asn1_error_code asn1buf_imbed position starts at the beginning of *subbuf. */ asn1_error_code asn1buf_sync - PROTOTYPE((asn1buf *buf, asn1buf *subbuf, const asn1_tagnum lasttag, - const int length)); + PROTOTYPE((asn1buf *buf, asn1buf *subbuf, const asn1_class class, + const asn1_tagnum lasttag, + const int length, const int indef, + const int seqindef)); /* requires *subbuf is a sub-buffer of *buf, as created by asn1buf_imbed. - lasttag is a pointer to the last tagnumber read. + lasttag is the last tagnumber read. effects Synchronizes *buf's current position to match that of *subbuf. */ asn1_error_code asn1buf_skiptail - PROTOTYPE((asn1buf *buf)); + PROTOTYPE((asn1buf *buf, const int length, + const int indef)); /* requires *buf is a subbuffer used in a decoding of a constructed indefinite sequence. effects skips trailing fields. */ @@ -143,7 +146,7 @@ asn1_error_code asn1buf_insert_octet effects Inserts o into the buffer *buf, expanding the buffer if necessary. Returns ENOMEM memory is exhausted. */ #if ((__GNUC__ >= 2) && !defined(ASN1BUF_OMIT_INLINE_FUNCS)) -extern inline asn1_error_code asn1buf_insert_octet(buf, o) +extern __inline__ asn1_error_code asn1buf_insert_octet(buf, o) asn1buf * buf; const int o; { @@ -221,7 +224,7 @@ asn1_error_code asn12krb5_buf int asn1buf_remains - PROTOTYPE((asn1buf *buf)); + PROTOTYPE((asn1buf *buf, int indef)); /* requires *buf is a buffer containing an asn.1 structure or array modifies *buf effects Returns the number of unprocessed octets remaining in *buf. */ diff --git a/src/lib/krb5/asn.1/krb5_decode.c b/src/lib/krb5/asn.1/krb5_decode.c index 69028b9..ff935c6 100644 --- a/src/lib/krb5/asn.1/krb5_decode.c +++ b/src/lib/krb5/asn.1/krb5_decode.c @@ -77,23 +77,29 @@ if(tagnum != (tagexpect)) clean_return(KRB5_BADMSGTYPE) /* decode an explicit tag and place the number in tagnum */ #define next_tag()\ -retval = asn1_get_tag(&subbuf,&class,&construction,&tagnum,NULL);\ -if(retval) clean_return(retval);\ -if(class != CONTEXT_SPECIFIC || construction != CONSTRUCTED)\ - clean_return(ASN1_BAD_ID) +retval = asn1_get_tag_indef(&subbuf,&class,&construction,&tagnum,NULL,&indef);\ +if(retval) clean_return(retval) + +#define get_eoc() \ +retval = asn1_get_tag_indef(&subbuf,&class,&construction, \ + &tagnum,NULL,&indef); \ +if(retval) return retval; \ +if(class != UNIVERSAL || tagnum || indef) \ + return ASN1_MISSING_EOC /* decode sequence header and initialize tagnum with the first field */ #define begin_structure()\ asn1buf subbuf;\ +int seqindef;\ int indef;\ -retval = asn1_get_sequence(&buf,&length,&indef);\ +retval = asn1_get_sequence(&buf,&length,&seqindef);\ if(retval) clean_return(retval);\ -retval = asn1buf_imbed(&subbuf,&buf,length,indef);\ +retval = asn1buf_imbed(&subbuf,&buf,length,seqindef);\ if(retval) clean_return(retval);\ next_tag() #define end_structure()\ -retval = asn1buf_sync(&buf,&subbuf,tagnum,length);\ +retval = asn1buf_sync(&buf,&subbuf,class,tagnum,length,indef,seqindef);\ if (retval) clean_return(retval) /* process fields *******************************************/ @@ -101,6 +107,7 @@ if (retval) clean_return(retval) #define get_field_body(var,decoder)\ retval = decoder(&subbuf,&(var));\ if(retval) clean_return(retval);\ +if (indef) { get_eoc(); }\ next_tag() /* decode a field (<[UNIVERSAL id]> ) @@ -110,26 +117,35 @@ next_tag() #define get_field(var,tagexpect,decoder)\ if(tagnum > (tagexpect)) clean_return(ASN1_MISSING_FIELD);\ if(tagnum < (tagexpect)) clean_return(ASN1_MISPLACED_FIELD);\ +if(class != CONTEXT_SPECIFIC || construction != CONSTRUCTED)\ + clean_return(ASN1_BAD_ID);\ get_field_body(var,decoder) /* decode (or skip, if not present) an optional field */ #define opt_field(var,tagexpect,decoder)\ +if(class != CONTEXT_SPECIFIC || construction != CONSTRUCTED)\ + clean_return(ASN1_BAD_ID);\ if(tagnum == (tagexpect)){ get_field_body(var,decoder); } /* field w/ accompanying length *********/ #define get_lenfield_body(len,var,decoder)\ retval = decoder(&subbuf,&(len),&(var));\ if(retval) clean_return(retval);\ +if (indef) { get_eoc(); }\ next_tag() /* decode a field w/ its length (for string types) */ #define get_lenfield(len,var,tagexpect,decoder)\ if(tagnum > (tagexpect)) clean_return(ASN1_MISSING_FIELD);\ if(tagnum < (tagexpect)) clean_return(ASN1_MISPLACED_FIELD);\ +if(class != CONTEXT_SPECIFIC || construction != CONSTRUCTED)\ + clean_return(ASN1_BAD_ID);\ get_lenfield_body(len,var,decoder) /* decode an optional field w/ length */ #define opt_lenfield(len,var,tagexpect,decoder)\ +if(class != CONTEXT_SPECIFIC || construction != CONSTRUCTED)\ + clean_return(ASN1_BAD_ID);\ if(tagnum == (tagexpect)){\ get_lenfield_body(len,var,decoder);\ } diff --git a/src/lib/krb5/ccache/ChangeLog b/src/lib/krb5/ccache/ChangeLog index 2f74235..b9f1516 100644 --- a/src/lib/krb5/ccache/ChangeLog +++ b/src/lib/krb5/ccache/ChangeLog @@ -1,3 +1,64 @@ +2002-04-05 Danilo Almeida + + * Makefile.in: Build cc accessor functions on Windows. + +2002-04-2 Alexandra Ellwood + * ccdefault.c: updated to new KLL function name + +2002-03-03 Alexandra Ellwood + * ccdefault.c: swapped include of KerberosLoginPrivate with k5-int.h + to avoid problems with including CoreServices.h after profile.h and krb.h + +2002-02-28 Alexandra Ellwood + * ccdefault.c: Updated Mac OS X headers to new framework layout + +2002-01-29 Tom Yu + + * ccdefault.c: Add terminal newline. Fixes [krb5-build/1041]. + +2001-11-16 Miro Jurisic + * pullup from krb5-1-2 branch: LoginLib #include changes + +2001-10-29 Miro Jurisic + * pullup from krb5-1-2 branch after krb5-1-2-2-bp + * Makefile.in: Added ccfns.c + * ccdefault.h: Updated Mac OS #defines and #includes for new header layout + and Mac OS X frameworks + +2000-09-12 Alexandra Ellwood + + * ccdefops.c: created #define for USE_CCAPI now that both Mac OS 9 and + Mac OS 10 use ccapi. + +2000-5-31 Alexandra Ellwood + + * ccdefault.c: Changed kerberosPrincipal_V5 to kerberosVersion_V5 to reflect + the new constant name. + +2000-5-19 Alexandra Ellwood + + * ccdefault.c: Added krb5int_cc_default. This function + supports the Kerberos Login Library and pops up a dialog if the cache does + not contain valid tickets. This is used to automatically get a tgt before + obtaining service tickets. Note that this should be an internal function + because callers don't expect krb5_cc_default to pop up a dialog! + (We found this out the hard way :-) + +2000-4-26 Alexandra Ellwood + + * ccdefault.c: Added version number to internal Kerberos Login Library + routine. + +2000-4-13 Alexandra Ellwood + + * ccdefault.c: Added Kerberos Login library support (with ifdefs to control + whether or not it is on. Also added support to store a krb5_principal in the + os_context along with the default ccache name (if known, this principal is + the same as the last time we looked at the ccache. + * ccdefname.c: Added support to store a krb5_principal in the os_context + along with the default ccache name (if known, this principal is the same + as the last time we looked at the ccache. + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/lib/krb5/ccache/Makefile.in b/src/lib/krb5/ccache/Makefile.in index 37abee4..ae09347 100644 --- a/src/lib/krb5/ccache/Makefile.in +++ b/src/lib/krb5/ccache/Makefile.in @@ -35,9 +35,12 @@ SRCS= $(srcdir)/ccbase.c \ $(srcdir)/cccopy.c \ $(srcdir)/ccdefault.c \ $(srcdir)/ccdefops.c \ + $(srcdir)/ccfns.c \ $(srcdir)/cc_retr.c \ $(srcdir)/ser_cc.c +##DOS##OBJS=$(OBJS) $(OUTPRE)ccfns.$(OBJEXT) + all-unix:: all-libobjs all-windows:: subdirs $(OBJFILE) diff --git a/src/lib/krb5/ccache/ccapi/ChangeLog b/src/lib/krb5/ccache/ccapi/ChangeLog index e4dac98..9b07b33 100644 --- a/src/lib/krb5/ccache/ccapi/ChangeLog +++ b/src/lib/krb5/ccache/ccapi/ChangeLog @@ -1,3 +1,93 @@ +2002-04-05 Danilo Almeida + + * winccld.c: Include k5-int.h to get hidden ops struct. + +2002-04-03 Danilo Almeida + + * stdcc.h: Remove KRB5_DLLIMP, KRB5_CALLCONV from + krb5_stdcc_shutdown() prototype (to fix Windows build). + +2002-02-28 Alexandra Ellwood + * stdcc.h: Added prototype for krb5_stdcc_shutdown. + +2002-02-28 Alexandra Ellwood + * stdcc.h, stdcc_util.h, stdcc_util.c: Updated Mac OS X headers to new + framework layout + * stdcc.c: Removed unused variables and fixed macros to reduce warnings + +2001-10-29 Miro Jurisic + * pullup from krb5-1-2 branch after krb5-1-2-2-bp + * stdcc.c: Replaced cc_* macros with functions + * stdcc.h, stdcc_util.h: Updated Mac OS #defines and #includes for new + header layout and Mac OS X frameworks + +2000-10-02 Alexandra Ellwood + + * stdcc_util.c: now Mac OS X uses get_time_offsets to store offset time + like Mac OS 9. + +2000-09-12 Alexandra Ellwood + + * stdcc.h, stdcc_util.h: created #define for USE_CCAPI now that + both Mac OS 9 and Mac OS 10 use ccapi. + +2000-06-08 Alexandra Ellwood + + * stdcc_util.c (dupCCtoK5, dupK5toCC): + Fixed code that stores times in localtime, not in kdc time. + +2000-05-18 Danilo Almeida + + * stdcc_util.c (dupK5toCC): Remove unused variables. + + * stdcc_util.c: Reindent to krb5 coding style. Remove whitespace + at end of lines. Replace C++ comments with C comments. + + * stdcc_util.h: Replace C++ comments with C comments. + + * winccld.h: Define CC_API_VER2 for all Windows code using ccapi. + Update dynamic loading declarations to use CC_API_VER2. + + * winccld.h: Do not define or try to load cc_lock_request, which is + not actually used anywhere in the code. + + * stdcc.c: Define CC_API_VER2 if not defined rather than just if + not Windows. + + * winccld.c (LoadFuncs): Get error on DLL load failure even though + we do not use it in case we are doing source-level debugging. + +2000-05-04 Miro Jurisic + + * stdcc_util.c (dupCCtoK5, dupK5toCC): + Conditionalized local/KDC time conversions for Mac-only + until we figure out what to do about that + +2000-04-07 Jeffrey Altman + + * stdcc_util.c (copyCCDataArrayToK5, copyCCDataArrayToK5): + * stdcc_util.c (dupCCtoK5, dupK5toCC): + + memory was being allocated as (sizeof(foo) * count + 1) + instead of (sizeof(foo) * (count + 1)) + +2000-04-03 Jeffrey Altman + + * stdcc_util.c (copyCCDataArrayToK5, copyCCDataArrayToK5): + * stdcc_util.c (dupCCtoK5, dupK5toCC): + + Changed all references to the type UInt32 to unsigned int + since UInt32 is not a standard type on Unix or Win32 + +2000-03-24 Alexandra Ellwood + + * stdcc_util.c (copyCCDataArrayToK5, copyCCDataArrayToK5): + Modified to copy authdata as well... this code may have + bugs since I couldn't get a good case where authdata != NULL + + * stdcc_util.c (dupCCtoK5, dupK5toCC): + Added code to store times in localtime, not in kdc time. + 2000-03-15 Danilo Almeida * stdcc.c (krb5_stdcc_destroy): Do not mask KRB5_FCC_NOFILE error diff --git a/src/lib/krb5/ccache/ccapi/stdcc.c b/src/lib/krb5/ccache/ccapi/stdcc.c index a17cd02..b885885 100644 --- a/src/lib/krb5/ccache/ccapi/stdcc.c +++ b/src/lib/krb5/ccache/ccapi/stdcc.c @@ -32,6 +32,7 @@ #include "stdcc.h" #include "stdcc_util.h" #include "string.h" +#include "k5-int.h" #include apiCB *gCntrlBlock = NULL; @@ -40,7 +41,7 @@ apiCB *gCntrlBlock = NULL; #include "winccld.h" #endif -#if !defined(_MSDOS) && !defined(_WIN32) +#ifndef CC_API_VER2 #define CC_API_VER2 #endif @@ -264,7 +265,7 @@ krb5_error_code KRB5_CALLCONV krb5_stdcc_resolve stdccCacheDataPtr ccapi_data = NULL; int err; krb5_error_code retval; - char *cName; + char *cName = NULL; if ((retval = stdcc_setup(context, NULL))) return retval; @@ -548,7 +549,9 @@ krb5_error_code KRB5_CALLCONV krb5_stdcc_end_seq_get krb5_error_code retval; stdccCacheDataPtr ccapi_data = NULL; int err; +#ifndef CC_API_VER2 cred_union *credU = NULL; +#endif ccapi_data = id->data; @@ -656,7 +659,6 @@ krb5_stdcc_destroy (krb5_context context, krb5_ccache id) char * KRB5_CALLCONV krb5_stdcc_get_name (krb5_context context, krb5_ccache id ) { - char *name = NULL; stdccCacheDataPtr ccapi_data = id->data; if (!ccapi_data) diff --git a/src/lib/krb5/ccache/ccapi/stdcc.h b/src/lib/krb5/ccache/ccapi/stdcc.h index 109c4fc..a9825b7 100644 --- a/src/lib/krb5/ccache/ccapi/stdcc.h +++ b/src/lib/krb5/ccache/ccapi/stdcc.h @@ -1,7 +1,7 @@ #include "krb5.h" -#if defined(macintosh) -#include "CCache2.h" +#if TARGET_OS_MAC +#include #endif #if defined(_MSDOS) || defined(_WIN32) @@ -24,6 +24,8 @@ typedef struct _stdccCacheData { /* function protoypes */ +void krb5_stdcc_shutdown(void); + KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_stdcc_close KRB5_PROTOTYPE((krb5_context, krb5_ccache id )); diff --git a/src/lib/krb5/ccache/ccapi/stdcc_util.c b/src/lib/krb5/ccache/ccapi/stdcc_util.c index 4262eed..cf2054e 100644 --- a/src/lib/krb5/ccache/ccapi/stdcc_util.c +++ b/src/lib/krb5/ccache/ccapi/stdcc_util.c @@ -23,112 +23,170 @@ * - copy and translate the null terminated arrays of data records * used in k5 tickets */ -int copyCCDataArrayToK5(cc_creds *cc, krb5_creds *kc, char whichArray) { - - cc_data *ccAdr, **cbase; - krb5_address *kAdr, **kbase, **constKBase; - int numRecords = 0; - - - if (whichArray == kAddressArray) { - /* check pointer */ - if (cc->addresses == NULL) { - kc->addresses = NULL; - return 0; - } - } else if (whichArray == kAuthDataArray) { - /* check pointer */ - if (cc->authdata == NULL) { - kc->authdata = NULL; - return 0; - } - } else - return -1; - - - cbase = (whichArray == kAddressArray) ? cc->addresses : cc->authdata; - /* calc number of records */ - while (*cbase++ != NULL) numRecords++; - /* allocate new array */ - constKBase = kbase = (krb5_address **)malloc((numRecords+1)*sizeof(char *)); - //reset base - cbase = (whichArray == kAddressArray) ? cc->addresses : cc->authdata; - - - //copy records - while (*cbase != NULL) { - *kbase = (krb5_address *)malloc(sizeof(krb5_address)); - kAdr = *kbase; - ccAdr = *cbase; - kAdr->magic = (whichArray == kAddressArray) ? KV5M_ADDRESS : KV5M_AUTHDATA; - kAdr->addrtype = ccAdr->type; - kAdr->length = ccAdr->length; - kAdr->contents = (krb5_octet *)malloc(kAdr->length); - memcpy(kAdr->contents, ccAdr->data, kAdr->length); - //next element please - kbase++; cbase++; +int copyCCDataArrayToK5(cc_creds *ccCreds, krb5_creds *v5Creds, char whichArray) { + + if (whichArray == kAddressArray) { + if (ccCreds->addresses == NULL) { + v5Creds->addresses = NULL; + } else { + + krb5_address **addrPtr, *addr; + cc_data **dataPtr, *data; + unsigned int numRecords = 0; + + /* Allocate the array of pointers: */ + for (dataPtr = ccCreds->addresses; *dataPtr != NULL; numRecords++, dataPtr++) {} + + v5Creds->addresses = (krb5_address **) malloc (sizeof(krb5_address *) * (numRecords + 1)); + if (v5Creds->addresses == NULL) + return ENOMEM; + + /* Fill in the array, allocating the address structures: */ + for (dataPtr = ccCreds->addresses, addrPtr = v5Creds->addresses; *dataPtr != NULL; addrPtr++, dataPtr++) { + + *addrPtr = (krb5_address *) malloc (sizeof(krb5_address)); + if (*addrPtr == NULL) + return ENOMEM; + data = *dataPtr; + addr = *addrPtr; + + addr->addrtype = data->type; + addr->magic = KV5M_ADDRESS; + addr->length = data->length; + addr->contents = (krb5_octet *) malloc (sizeof(krb5_octet) * addr->length); + if (addr->contents == NULL) + return ENOMEM; + memmove(addr->contents, data->data, addr->length); /* copy contents */ + } + + /* Write terminator: */ + *addrPtr = NULL; + } + } + + if (whichArray == kAuthDataArray) { + if (ccCreds->authdata == NULL) { + v5Creds->authdata = NULL; + } else { + krb5_authdata **authPtr, *auth; + cc_data **dataPtr, *data; + unsigned int numRecords = 0; + + /* Allocate the array of pointers: */ + for (dataPtr = ccCreds->authdata; *dataPtr != NULL; numRecords++, dataPtr++) {} + + v5Creds->authdata = (krb5_authdata **) malloc (sizeof(krb5_authdata *) * (numRecords + 1)); + if (v5Creds->authdata == NULL) + return ENOMEM; + + /* Fill in the array, allocating the address structures: */ + for (dataPtr = ccCreds->authdata, authPtr = v5Creds->authdata; *dataPtr != NULL; authPtr++, dataPtr++) { + + *authPtr = (krb5_authdata *) malloc (sizeof(krb5_authdata)); + if (*authPtr == NULL) + return ENOMEM; + data = *dataPtr; + auth = *authPtr; + + auth->ad_type = data->type; + auth->magic = KV5M_AUTHDATA; + auth->length = data->length; + auth->contents = (krb5_octet *) malloc (sizeof(krb5_octet) * auth->length); + if (auth->contents == NULL) + return ENOMEM; + memmove(auth->contents, data->data, auth->length); /* copy contents */ + } + + /* Write terminator: */ + *authPtr = NULL; } - - //write terminator - *kbase = NULL; - if (whichArray == kAddressArray) kc->addresses = constKBase; - else kc->authdata = (krb5_authdata **)constKBase; + } - return 0; + return 0; } /* * copyK5DataArrayToCC * - analagous to above, but in the other direction */ -int copyK5DataArrayToCC(krb5_creds *kc, cc_creds *cc, char whichArray) { - - cc_data *ccAdr, **cbase, **constCBase; - krb5_address *kAdr, **kbase; - int numRecords = 0; - - - if (whichArray == kAddressArray) { - //check pointer - if (kc->addresses == NULL) { - cc->addresses = NULL; - return 0; } - } else if (whichArray == kAuthDataArray) { - //check pointer - if (kc->authdata == NULL) { - cc->authdata = NULL; - return 0; } - } else return -1; - - - kbase = (whichArray == kAddressArray) ? kc->addresses : (krb5_address **)kc->authdata; - //calc number of records - while (*kbase++ != NULL) numRecords++; - //allocate new array - constCBase = cbase = (cc_data **)malloc((numRecords+1)*sizeof(char *)); - //reset base - kbase = (whichArray == kAddressArray) ? kc->addresses : (krb5_address **)kc->authdata; - - - //copy records - while (*kbase != NULL) { - *cbase = (cc_data *)malloc(sizeof(krb5_address)); - kAdr = *kbase; - ccAdr = *cbase; - ccAdr->type = kAdr->addrtype; - ccAdr->length = kAdr->length; - ccAdr->data = (unsigned char *)malloc(ccAdr->length); - memcpy(ccAdr->data, kAdr->contents, kAdr->length); - //next element please - kbase++; cbase++; +int copyK5DataArrayToCC(krb5_creds *v5Creds, cc_creds *ccCreds, char whichArray) +{ + if (whichArray == kAddressArray) { + if (v5Creds->addresses == NULL) { + ccCreds->addresses = NULL; + } else { + + krb5_address **addrPtr, *addr; + cc_data **dataPtr, *data; + unsigned int numRecords = 0; + + /* Allocate the array of pointers: */ + for (addrPtr = v5Creds->addresses; *addrPtr != NULL; numRecords++, addrPtr++) {} + + ccCreds->addresses = (cc_data **) malloc (sizeof(cc_data *) * (numRecords + 1)); + if (ccCreds->addresses == NULL) + return ENOMEM; + + /* Fill in the array, allocating the address structures: */ + for (dataPtr = ccCreds->addresses, addrPtr = v5Creds->addresses; *addrPtr != NULL; addrPtr++, dataPtr++) { + + *dataPtr = (cc_data *) malloc (sizeof(cc_data)); + if (*dataPtr == NULL) + return ENOMEM; + data = *dataPtr; + addr = *addrPtr; + + data->type = addr->addrtype; + data->length = addr->length; + data->data = malloc (sizeof(char) * data->length); + if (data->data == NULL) + return ENOMEM; + memmove(data->data, addr->contents, data->length); /* copy contents */ + } + + /* Write terminator: */ + *dataPtr = NULL; + } + } + + if (whichArray == kAuthDataArray) { + if (v5Creds->authdata == NULL) { + ccCreds->authdata = NULL; + } else { + krb5_authdata **authPtr, *auth; + cc_data **dataPtr, *data; + unsigned int numRecords = 0; + + /* Allocate the array of pointers: */ + for (authPtr = v5Creds->authdata; *authPtr != NULL; numRecords++, authPtr++) {} + + ccCreds->authdata = (cc_data **) malloc (sizeof(cc_data *) * (numRecords + 1)); + if (ccCreds->authdata == NULL) + return ENOMEM; + + /* Fill in the array, allocating the address structures: */ + for (dataPtr = ccCreds->authdata, authPtr = v5Creds->authdata; *authPtr != NULL; authPtr++, dataPtr++) { + + *dataPtr = (cc_data *) malloc (sizeof(cc_data)); + if (*dataPtr == NULL) + return ENOMEM; + data = *dataPtr; + auth = *authPtr; + + data->type = auth->ad_type; + data->length = auth->length; + data->data = malloc (sizeof(char) * data->length); + if (data->data == NULL) + return ENOMEM; + memmove(data->data, auth->contents, data->length); /* copy contents */ + } + + /* Write terminator: */ + *dataPtr = NULL; } - - //write terminator - *cbase = NULL; - if (whichArray == kAddressArray) cc->addresses = (cc_data **)constCBase; - else cc->authdata = (cc_data **)constCBase; + } - return 0; + return 0; } /* @@ -136,52 +194,56 @@ int copyK5DataArrayToCC(krb5_creds *kc, cc_creds *cc, char whichArray) { * - allocate an empty k5 style ticket and copy info from the cc_creds ticket */ -void dupCCtoK5(krb5_context context, cc_creds *src, krb5_creds *dest) { - - int err; - - /* - * allocate and copy - * copy all of those damn fields back - */ - err = krb5_parse_name(context, src->client, &(dest->client)); - err = krb5_parse_name(context, src->server, &(dest->server)); - if (err) return; //parsename fails w/o krb5.ini for example - - /* copy keyblock */ - dest->keyblock.enctype = src->keyblock.type; - dest->keyblock.length = src->keyblock.length; - dest->keyblock.contents = (krb5_octet *)malloc(dest->keyblock.length); - memcpy(dest->keyblock.contents, src->keyblock.data, dest->keyblock.length); - - /* copy times */ - dest->times.authtime = src->authtime; - dest->times.starttime = src->starttime; - dest->times.endtime = src->endtime; - dest->times.renew_till = src->renew_till; - dest->is_skey = src->is_skey; - dest->ticket_flags = src->ticket_flags; - - /* more branching fields */ - copyCCDataArrayToK5(src, dest, kAddressArray); - dest->ticket.length = src->ticket.length; - dest->ticket.data = (char *)malloc(src->ticket.length); - memcpy(dest->ticket.data, src->ticket.data, src->ticket.length); - dest->second_ticket.length = src->second_ticket.length; - (dest->second_ticket).data = ( char *)malloc(src->second_ticket.length); - memcpy(dest->second_ticket.data, src->second_ticket.data, src->second_ticket.length); - - /* zero out magic number */ - dest->magic = 0; - /* - * later - * copyCCDataArrayToK5(src, dest, kAuthDataArray); - * krb5 docs say that authdata can be nulled out if we - * only want default behavior - */ - dest->authdata = NULL; - - return; +void dupCCtoK5(krb5_context context, cc_creds *src, krb5_creds *dest) +{ + krb5_int32 offset_seconds = 0, offset_microseconds = 0; + int err; + + /* + * allocate and copy + * copy all of those damn fields back + */ + err = krb5_parse_name(context, src->client, &(dest->client)); + err = krb5_parse_name(context, src->server, &(dest->server)); + if (err) return; /* parsename fails w/o krb5.ini for example */ + + /* copy keyblock */ + dest->keyblock.enctype = src->keyblock.type; + dest->keyblock.length = src->keyblock.length; + dest->keyblock.contents = (krb5_octet *)malloc(dest->keyblock.length); + memcpy(dest->keyblock.contents, src->keyblock.data, dest->keyblock.length); + + /* copy times */ +#if TARGET_OS_MAC + err = krb5_get_time_offsets(context, &offset_seconds, &offset_microseconds); + if (err) return; +#endif + dest->times.authtime = src->authtime + offset_seconds; + dest->times.starttime = src->starttime + offset_seconds; + dest->times.endtime = src->endtime + offset_seconds; + dest->times.renew_till = src->renew_till + offset_seconds; + dest->is_skey = src->is_skey; + dest->ticket_flags = src->ticket_flags; + + /* more branching fields */ + err = copyCCDataArrayToK5(src, dest, kAddressArray); + if (err) return; + + dest->ticket.length = src->ticket.length; + dest->ticket.data = (char *)malloc(src->ticket.length); + memcpy(dest->ticket.data, src->ticket.data, src->ticket.length); + dest->second_ticket.length = src->second_ticket.length; + (dest->second_ticket).data = ( char *)malloc(src->second_ticket.length); + memcpy(dest->second_ticket.data, src->second_ticket.data, src->second_ticket.length); + + /* zero out magic number */ + dest->magic = 0; + + /* authdata */ + err = copyCCDataArrayToK5(src, dest, kAuthDataArray); + if (err) return; + + return; } /* @@ -190,90 +252,97 @@ void dupCCtoK5(krb5_context context, cc_creds *src, krb5_creds *dest) { */ void dupK5toCC(krb5_context context, krb5_creds *creds, cred_union **cu) { - cc_creds *c; - int err; + cc_creds *c; + int err; + krb5_int32 offset_seconds = 0, offset_microseconds = 0; #ifdef macintosh - char *tempname = NULL; + char *tempname = NULL; #endif - - if (cu == NULL) return; - - /* allocate the cred_union */ - *cu = (cred_union *)malloc(sizeof(cred_union)); - if ((*cu) == NULL) - return; - - (*cu)->cred_type = CC_CRED_V5; - - /* allocate creds structure (and install) */ - c = (cc_creds *)malloc(sizeof(cc_creds)); - if (c == NULL) return; - (*cu)->cred.pV5Cred = c; - - /* convert krb5 principals to flat principals */ + + if (cu == NULL) return; + + /* allocate the cred_union */ + *cu = (cred_union *)malloc(sizeof(cred_union)); + if ((*cu) == NULL) + return; + + (*cu)->cred_type = CC_CRED_V5; + + /* allocate creds structure (and install) */ + c = (cc_creds *)malloc(sizeof(cc_creds)); + if (c == NULL) return; + (*cu)->cred.pV5Cred = c; + + /* convert krb5 principals to flat principals */ #ifdef macintosh - /* - * and make sure the memory for c->client and c->server is on - * the system heap with NewPtr for the Mac (krb5_unparse_name - * puts it in appl heap with malloc) - */ - err = krb5_unparse_name(context, creds->client, &tempname); - c->client = malloc(strlen(tempname)+1); - if (c->client != NULL) - strcpy(c->client,tempname); - free(tempname); - tempname = NULL; - - err = krb5_unparse_name(context, creds->server, &tempname); - c->server = malloc(strlen(tempname)+1); - if (c->server != NULL) - strcpy(c->server,tempname); - free(tempname); + /* + * and make sure the memory for c->client and c->server is on + * the system heap with NewPtr for the Mac (krb5_unparse_name + * puts it in appl heap with malloc) + */ + err = krb5_unparse_name(context, creds->client, &tempname); + c->client = malloc(strlen(tempname)+1); + if (c->client != NULL) + strcpy(c->client,tempname); + free(tempname); + tempname = NULL; + + err = krb5_unparse_name(context, creds->server, &tempname); + c->server = malloc(strlen(tempname)+1); + if (c->server != NULL) + strcpy(c->server,tempname); + free(tempname); #else - err = krb5_unparse_name(context, creds->client, &(c->client)); - err = krb5_unparse_name(context, creds->server, &(c->server)); + err = krb5_unparse_name(context, creds->client, &(c->client)); + err = krb5_unparse_name(context, creds->server, &(c->server)); #endif - if (err) return; - - /* copy more fields */ - c->keyblock.type = creds->keyblock.enctype; - c->keyblock.length = creds->keyblock.length; - - if (creds->keyblock.contents != NULL) { - c->keyblock.data = (unsigned char *)malloc(creds->keyblock.length); - memcpy(c->keyblock.data, creds->keyblock.contents, creds->keyblock.length); - } else { - c->keyblock.data = NULL; - } - - c->authtime = creds->times.authtime; - c->starttime = creds->times.starttime; - c->endtime = creds->times.endtime; - c->renew_till = creds->times.renew_till; - c->is_skey = creds->is_skey; - c->ticket_flags = creds->ticket_flags; - - copyK5DataArrayToCC(creds, c, kAddressArray); - - c->ticket.length = creds->ticket.length; - if (creds->ticket.data != NULL) { - c->ticket.data = (unsigned char *)malloc(creds->ticket.length); - memcpy(c->ticket.data, creds->ticket.data, creds->ticket.length); - } else { - c->ticket.data = NULL; - } - - c->second_ticket.length = creds->second_ticket.length; - if (creds->second_ticket.data != NULL) { - c->second_ticket.data = (unsigned char *)malloc(creds->second_ticket.length); - memcpy(c->second_ticket.data, creds->second_ticket.data, creds->second_ticket.length); - } else { - c->second_ticket.data = NULL; - } - - c->authdata = NULL; - - return; + if (err) return; + + /* copy more fields */ + c->keyblock.type = creds->keyblock.enctype; + c->keyblock.length = creds->keyblock.length; + + if (creds->keyblock.contents != NULL) { + c->keyblock.data = (unsigned char *)malloc(creds->keyblock.length); + memcpy(c->keyblock.data, creds->keyblock.contents, creds->keyblock.length); + } else { + c->keyblock.data = NULL; + } + +#if TARGET_OS_MAC + err = krb5_get_time_offsets(context, &offset_seconds, &offset_microseconds); + if (err) return; +#endif + c->authtime = creds->times.authtime - offset_seconds; + c->starttime = creds->times.starttime - offset_seconds; + c->endtime = creds->times.endtime - offset_seconds; + c->renew_till = creds->times.renew_till - offset_seconds; + c->is_skey = creds->is_skey; + c->ticket_flags = creds->ticket_flags; + + err = copyK5DataArrayToCC(creds, c, kAddressArray); + if (err) return; + + c->ticket.length = creds->ticket.length; + if (creds->ticket.data != NULL) { + c->ticket.data = (unsigned char *)malloc(creds->ticket.length); + memcpy(c->ticket.data, creds->ticket.data, creds->ticket.length); + } else { + c->ticket.data = NULL; + } + + c->second_ticket.length = creds->second_ticket.length; + if (creds->second_ticket.data != NULL) { + c->second_ticket.data = (unsigned char *)malloc(creds->second_ticket.length); + memcpy(c->second_ticket.data, creds->second_ticket.data, creds->second_ticket.length); + } else { + c->second_ticket.data = NULL; + } + + err = copyK5DataArrayToCC(creds, c, kAuthDataArray); + if (err) return; + + return; } /* @@ -281,7 +350,7 @@ void dupK5toCC(krb5_context context, krb5_creds *creds, cred_union **cu) */ static krb5_boolean times_match(t1, t2) -register const krb5_ticket_times *t1; + register const krb5_ticket_times *t1; register const krb5_ticket_times *t2; { if (t1->renew_till) { @@ -308,7 +377,7 @@ times_match_exact (t1, t2) static krb5_boolean standard_fields_match(context, mcreds, creds) - krb5_context context; + krb5_context context; register const krb5_creds *mcreds, *creds; { return (krb5_principal_compare(context, mcreds->client,creds->client) && @@ -319,12 +388,12 @@ register const krb5_creds *mcreds, *creds; static krb5_boolean srvname_match(context, mcreds, creds) - krb5_context context; + krb5_context context; register const krb5_creds *mcreds, *creds; { krb5_boolean retval; krb5_principal_data p1, p2; - + retval = krb5_principal_compare(context, mcreds->client,creds->client); if (retval != TRUE) return retval; @@ -368,7 +437,7 @@ authdata_match(mdata, data) static krb5_boolean data_match(data1, data2) -register const krb5_data *data1, *data2; + register const krb5_data *data1, *data2; { if (!data1) { if (!data2) @@ -396,117 +465,113 @@ register const krb5_data *data1, *data2; int stdccCredsMatch(krb5_context context, krb5_creds *base, krb5_creds *match, int whichfields) { - krb5_ticket_times b, m; - krb5_authdata **bp, **mp; - krb5_boolean retval; - - if (((MATCH_SET(KRB5_TC_MATCH_SRV_NAMEONLY) && - srvname_match(context, match, base)) || - standard_fields_match(context, match, base)) - && - (! MATCH_SET(KRB5_TC_MATCH_IS_SKEY) || - match->is_skey == base->is_skey) - && - (! MATCH_SET(KRB5_TC_MATCH_FLAGS_EXACT) || - match->ticket_flags == base->ticket_flags) - && - (! MATCH_SET(KRB5_TC_MATCH_FLAGS) || - flags_match(match->ticket_flags, base->ticket_flags)) - && - (! MATCH_SET(KRB5_TC_MATCH_TIMES_EXACT) || - times_match_exact(&match->times, &base->times)) - && - (! MATCH_SET(KRB5_TC_MATCH_TIMES) || - times_match(&match->times, &base->times)) - && - (! MATCH_SET(KRB5_TC_MATCH_AUTHDATA) || - authdata_match (match->authdata, base->authdata)) - && - (! MATCH_SET(KRB5_TC_MATCH_2ND_TKT) || - data_match (&match->second_ticket, &base->second_ticket)) - && - ((! MATCH_SET(KRB5_TC_MATCH_KTYPE))|| - (match->keyblock.enctype == base->keyblock.enctype)) - ) - return TRUE; - return FALSE; - + if (((MATCH_SET(KRB5_TC_MATCH_SRV_NAMEONLY) && + srvname_match(context, match, base)) || + standard_fields_match(context, match, base)) + && + (! MATCH_SET(KRB5_TC_MATCH_IS_SKEY) || + match->is_skey == base->is_skey) + && + (! MATCH_SET(KRB5_TC_MATCH_FLAGS_EXACT) || + match->ticket_flags == base->ticket_flags) + && + (! MATCH_SET(KRB5_TC_MATCH_FLAGS) || + flags_match(match->ticket_flags, base->ticket_flags)) + && + (! MATCH_SET(KRB5_TC_MATCH_TIMES_EXACT) || + times_match_exact(&match->times, &base->times)) + && + (! MATCH_SET(KRB5_TC_MATCH_TIMES) || + times_match(&match->times, &base->times)) + && + (! MATCH_SET(KRB5_TC_MATCH_AUTHDATA) || + authdata_match (match->authdata, base->authdata)) + && + (! MATCH_SET(KRB5_TC_MATCH_2ND_TKT) || + data_match (&match->second_ticket, &base->second_ticket)) + && + ((! MATCH_SET(KRB5_TC_MATCH_KTYPE))|| + (match->keyblock.enctype == base->keyblock.enctype)) + ) + return TRUE; + return FALSE; } -// ----- free_cc_cred_union, etc -------------- +/* ----- free_cc_cred_union, etc -------------- */ /* - Since the Kerberos5 library allocates a credentials cache structure - (in dupK5toCC() above) with its own memory allocation routines - which - may be different than how the CCache allocates memory - the Kerb5 library - must have its own version of cc_free_creds() to deallocate it. These - functions do that. The top-level function to substitue for cc_free_creds() - is krb5_free_cc_cred_union(). - - If the CCache library wants to use a cred_union structure created by - the Kerb5 library, it should make a deep copy of it to "translate" to its - own memory allocation space. + Since the Kerberos5 library allocates a credentials cache structure + (in dupK5toCC() above) with its own memory allocation routines - which + may be different than how the CCache allocates memory - the Kerb5 library + must have its own version of cc_free_creds() to deallocate it. These + functions do that. The top-level function to substitue for cc_free_creds() + is krb5_free_cc_cred_union(). + + If the CCache library wants to use a cred_union structure created by + the Kerb5 library, it should make a deep copy of it to "translate" to its + own memory allocation space. */ -static void deep_free_cc_data (cc_data data) { - - if (data.data != NULL) - free (data.data); +static void deep_free_cc_data (cc_data data) +{ + if (data.data != NULL) + free (data.data); } static void deep_free_cc_data_array (cc_data** data) { - - unsigned int index; - - if (data == NULL) - return; - - for (index = 0; data [index] != NULL; index++) { - deep_free_cc_data (*(data [index])); - free (data [index]); - } - - free (data); + + unsigned int index; + + if (data == NULL) + return; + + for (index = 0; data [index] != NULL; index++) { + deep_free_cc_data (*(data [index])); + free (data [index]); + } + + free (data); } -static void deep_free_cc_v5_creds (cc_creds* creds) { - - if (creds == NULL) - return; - - if (creds -> client != NULL) - free (creds -> client); - if (creds -> server != NULL) - free (creds -> server); - - deep_free_cc_data (creds -> keyblock); - deep_free_cc_data (creds -> ticket); - deep_free_cc_data (creds -> second_ticket); - - deep_free_cc_data_array (creds -> addresses); - deep_free_cc_data_array (creds -> authdata); - - free(creds); +static void deep_free_cc_v5_creds (cc_creds* creds) +{ + if (creds == NULL) + return; + + if (creds -> client != NULL) + free (creds -> client); + if (creds -> server != NULL) + free (creds -> server); + + deep_free_cc_data (creds -> keyblock); + deep_free_cc_data (creds -> ticket); + deep_free_cc_data (creds -> second_ticket); + + deep_free_cc_data_array (creds -> addresses); + deep_free_cc_data_array (creds -> authdata); + + free(creds); } -static void deep_free_cc_creds (cred_union creds) { - - if (creds.cred_type == CC_CRED_V4) { // we shouldn't get this, of course - free (creds.cred.pV4Cred); - } else if (creds.cred_type == CC_CRED_V5) { - deep_free_cc_v5_creds (creds.cred.pV5Cred); - } +static void deep_free_cc_creds (cred_union creds) +{ + if (creds.cred_type == CC_CRED_V4) { + /* we shouldn't get this, of course */ + free (creds.cred.pV4Cred); + } else if (creds.cred_type == CC_CRED_V5) { + deep_free_cc_v5_creds (creds.cred.pV5Cred); + } } -// top-level exported function -cc_int32 krb5_free_cc_cred_union (cred_union** creds) { - - if (creds == NULL) - return CC_BAD_PARM; - - if (*creds != NULL) { - deep_free_cc_creds (**creds); - free (*creds); - *creds = NULL; - } - - return CC_NOERROR; +/* top-level exported function */ +cc_int32 krb5_free_cc_cred_union (cred_union** creds) +{ + if (creds == NULL) + return CC_BAD_PARM; + + if (*creds != NULL) { + deep_free_cc_creds (**creds); + free (*creds); + *creds = NULL; + } + + return CC_NOERROR; } diff --git a/src/lib/krb5/ccache/ccapi/stdcc_util.h b/src/lib/krb5/ccache/ccapi/stdcc_util.h index 93538bf..e8426d4 100644 --- a/src/lib/krb5/ccache/ccapi/stdcc_util.h +++ b/src/lib/krb5/ccache/ccapi/stdcc_util.h @@ -1,9 +1,10 @@ -//stdcc_util.h -// -// Frank Dabek, July 1998 +/* stdcc_util.h + * + * Frank Dabek, July 1998 + */ -#if defined(macintosh) -#include "CCache2.h" +#if TARGET_OS_MAC +#include #endif #if defined(_MSDOS) || defined(_WIN32) @@ -12,7 +13,7 @@ #include "krb5.h" -//protoypes for private functions declared in stdcc_util.c +/* protoypes for private functions declared in stdcc_util.c */ int copyCCDataArrayToK5(cc_creds *cc, krb5_creds *kc, char whichArray); int copyK5DataArrayToCC(krb5_creds *kc, cc_creds *cc, char whichArray); void dupCCtoK5(krb5_context context, cc_creds *src, krb5_creds *dest); diff --git a/src/lib/krb5/ccache/ccapi/winccld.c b/src/lib/krb5/ccache/ccapi/winccld.c index 2792cee..e6e4d58 100644 --- a/src/lib/krb5/ccache/ccapi/winccld.c +++ b/src/lib/krb5/ccache/ccapi/winccld.c @@ -7,6 +7,7 @@ #include #include #include "stdcc.h" +#include "k5-int.h" /* from fcc-proto.h */ KRB5_DLLIMP extern krb5_cc_ops krb5_fcc_ops; @@ -45,6 +46,8 @@ static int LoadFuncs(const char* dll_name, FUNC_INFO fi[], } if (!(h = LoadLibrary(dll_name))) { + /* Get error for source debugging purposes. */ + error = (int)GetLastError(); return LF_NODLL; } diff --git a/src/lib/krb5/ccache/ccapi/winccld.h b/src/lib/krb5/ccache/ccapi/winccld.h index 09a7ef5..e285d1f 100644 --- a/src/lib/krb5/ccache/ccapi/winccld.h +++ b/src/lib/krb5/ccache/ccapi/winccld.h @@ -6,6 +6,10 @@ #ifndef KRB5_WINCCLD_H_ #define KRB5_WINCCLD_H_ +#ifndef CC_API_VER2 +#define CC_API_VER2 +#endif + #include "cacheapi.h" typedef cc_int32 (*FP_cc_initialize)(apiCB**, const cc_int32, @@ -19,6 +23,9 @@ typedef cc_int32 (*FP_cc_open)(apiCB*, const char*, const enum cc_cred_vers, typedef cc_int32 (*FP_cc_close)(apiCB*, ccache_p**); typedef cc_int32 (*FP_cc_destroy)(apiCB*, ccache_p**); typedef cc_int32 (*FP_cc_seq_fetch_NCs)(apiCB*, ccache_p**, ccache_cit**); +typedef cc_int32 (*FP_cc_seq_fetch_NCs_begin)(apiCB*, ccache_cit**); +typedef cc_int32 (*FP_cc_seq_fetch_NCs_next)(apiCB*, ccache_p**, ccache_cit*); +typedef cc_int32 (*FP_cc_seq_fetch_NCs_end)(apiCB*, ccache_cit**); typedef cc_int32 (*FP_cc_get_NC_info)(apiCB*, struct _infoNC***); typedef cc_int32 (*FP_cc_free_NC_info)(apiCB*, struct _infoNC***); typedef cc_int32 (*FP_cc_get_name)(apiCB*, const ccache_p*, char**); @@ -34,6 +41,11 @@ typedef cc_int32 (*FP_cc_remove_cred)(apiCB*, const ccache_p*, const cred_union); typedef cc_int32 (*FP_cc_seq_fetch_creds)(apiCB*, const ccache_p*, cred_union**, ccache_cit**); +typedef cc_int32 (*FP_cc_seq_fetch_creds_begin)(apiCB*, const ccache_p*, + ccache_cit**); +typedef cc_int32 (*FP_cc_seq_fetch_creds_next)(apiCB*, cred_union**, + ccache_cit*); +typedef cc_int32 (*FP_cc_seq_fetch_creds_end)(apiCB*, ccache_cit**); typedef cc_int32 (*FP_cc_free_principal)(apiCB*, char**); typedef cc_int32 (*FP_cc_free_name)(apiCB*, char** name); typedef cc_int32 (*FP_cc_free_creds)(apiCB*, cred_union** pCred); @@ -58,17 +70,33 @@ DECL_FUNC_PTR(cc_create); DECL_FUNC_PTR(cc_open); DECL_FUNC_PTR(cc_close); DECL_FUNC_PTR(cc_destroy); +#if 0 /* Not used */ +#ifdef CC_API_VER2 +DECL_FUNC_PTR(cc_seq_fetch_NCs_begin); +DECL_FUNC_PTR(cc_seq_fetch_NCs_next); +DECL_FUNC_PTR(cc_seq_fetch_NCs_end); +#else DECL_FUNC_PTR(cc_seq_fetch_NCs); +#endif DECL_FUNC_PTR(cc_get_NC_info); DECL_FUNC_PTR(cc_free_NC_info); +#endif DECL_FUNC_PTR(cc_get_name); DECL_FUNC_PTR(cc_set_principal); DECL_FUNC_PTR(cc_get_principal); DECL_FUNC_PTR(cc_get_cred_version); +#if 0 /* Not used */ DECL_FUNC_PTR(cc_lock_request); +#endif DECL_FUNC_PTR(cc_store); DECL_FUNC_PTR(cc_remove_cred); +#ifdef CC_API_VER2 +DECL_FUNC_PTR(cc_seq_fetch_creds_begin); +DECL_FUNC_PTR(cc_seq_fetch_creds_next); +DECL_FUNC_PTR(cc_seq_fetch_creds_end); +#else DECL_FUNC_PTR(cc_seq_fetch_creds); +#endif DECL_FUNC_PTR(cc_free_principal); DECL_FUNC_PTR(cc_free_name); DECL_FUNC_PTR(cc_free_creds); @@ -82,17 +110,27 @@ FUNC_INFO krbcc_fi[] = { MAKE_FUNC_INFO(cc_open), MAKE_FUNC_INFO(cc_close), MAKE_FUNC_INFO(cc_destroy), +#if 0 /* Not used */ MAKE_FUNC_INFO(cc_seq_fetch_NCs), MAKE_FUNC_INFO(cc_get_NC_info), MAKE_FUNC_INFO(cc_free_NC_info), +#endif MAKE_FUNC_INFO(cc_get_name), MAKE_FUNC_INFO(cc_set_principal), MAKE_FUNC_INFO(cc_get_principal), MAKE_FUNC_INFO(cc_get_cred_version), +#if 0 /* Not used */ MAKE_FUNC_INFO(cc_lock_request), +#endif MAKE_FUNC_INFO(cc_store), MAKE_FUNC_INFO(cc_remove_cred), +#ifdef CC_API_VER2 + MAKE_FUNC_INFO(cc_seq_fetch_creds_begin), + MAKE_FUNC_INFO(cc_seq_fetch_creds_next), + MAKE_FUNC_INFO(cc_seq_fetch_creds_end), +#else MAKE_FUNC_INFO(cc_seq_fetch_creds), +#endif MAKE_FUNC_INFO(cc_free_principal), MAKE_FUNC_INFO(cc_free_name), MAKE_FUNC_INFO(cc_free_creds), @@ -109,17 +147,33 @@ FUNC_INFO krbcc_fi[] = { #define cc_open pcc_open #define cc_close pcc_close #define cc_destroy pcc_destroy +#if 0 /* Not used */ +#ifdef CC_API_VER2 +#define cc_seq_fetch_NCs_begin pcc_seq_fetch_NCs_begin +#define cc_seq_fetch_NCs_next pcc_seq_fetch_NCs_next +#define cc_seq_fetch_NCs_end pcc_seq_fetch_NCs_end +#else #define cc_seq_fetch_NCs pcc_seq_fetch_NCs +#endif #define cc_get_NC_info pcc_get_NC_info #define cc_free_NC_info pcc_free_NC_info +#endif /* End of Not used */ #define cc_get_name pcc_get_name #define cc_set_principal pcc_set_principal #define cc_get_principal pcc_get_principal #define cc_get_cred_version pcc_get_cred_version +#if 0 /* Not used */ #define cc_lock_request pcc_lock_request +#endif #define cc_store pcc_store #define cc_remove_cred pcc_remove_cred +#ifdef CC_API_VER2 +#define cc_seq_fetch_creds_begin pcc_seq_fetch_creds_begin +#define cc_seq_fetch_creds_next pcc_seq_fetch_creds_next +#define cc_seq_fetch_creds_end pcc_seq_fetch_creds_end +#else #define cc_seq_fetch_creds pcc_seq_fetch_creds +#endif #define cc_free_principal pcc_free_principal #define cc_free_name pcc_free_name #define cc_free_creds pcc_free_creds diff --git a/src/lib/krb5/ccache/ccdefault.c b/src/lib/krb5/ccache/ccdefault.c index 3e2699c..fc3e0ad 100644 --- a/src/lib/krb5/ccache/ccdefault.c +++ b/src/lib/krb5/ccache/ccdefault.c @@ -27,6 +27,10 @@ * Find default credential cache */ +#ifdef USE_LOGIN_LIBRARY +#include +#endif + #include "k5-int.h" KRB5_DLLIMP krb5_error_code KRB5_CALLCONV @@ -34,5 +38,83 @@ krb5_cc_default(context, ccache) krb5_context context; krb5_ccache FAR *ccache; { - return krb5_cc_resolve(context, krb5_cc_default_name(context), ccache); + krb5_error_code retval; + krb5_os_context os_ctx; + + if (!context || context->magic != KV5M_CONTEXT) + return KV5M_CONTEXT; + + os_ctx = context->os_context; + + retval = krb5_cc_resolve(context, krb5_cc_default_name(context), ccache); + if (!retval && ccache && !os_ctx->default_ccprincipal) { + /* We got a ccache... remember what principal is associated with it */ + if (krb5_cc_get_principal (context, *ccache, &os_ctx->default_ccprincipal) != 0) + os_ctx->default_ccprincipal = 0; + } + return retval; +} + +/* This is the internal function which opens the default ccache. On platforms supporting + the login library's automatic popup dialog to get tickets, this function also updated the + library's internal view of the current principal associated with this cache. + + All krb5 and GSS functions which need to open a cache to get a tgt to obtain service tickets + should call this function, not krb5_cc_default() */ + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5int_cc_default(context, ccache) + krb5_context context; + krb5_ccache FAR *ccache; +{ +#ifdef USE_LOGIN_LIBRARY + { + /* make sure the default cache has tix before you open it */ + char *outCacheName; + KLPrincipal desiredPrincipal = nil; + krb5_principal desiredKrb5Principal; + krb5_error_code err; + krb5_os_context os_ctx; + + if (!context || context->magic != KV5M_CONTEXT) + return KV5M_CONTEXT; + + os_ctx = context->os_context; + + desiredKrb5Principal = os_ctx->default_ccprincipal; + + /* do we want a specific client principal? */ + if (desiredKrb5Principal != NULL) { + char *desiredName; + + err = krb5_unparse_name (context, desiredKrb5Principal, &desiredName); + if (!err) { + err = KLCreatePrincipalFromString (desiredName, + kerberosVersion_V5, &desiredPrincipal); + krb5_free_unparsed_name (context, desiredName); + if (err != klNoErr) + desiredPrincipal = nil; + } + } + + /* Try to make sure a krb5 tgt is in the cache */ + err = __KLInternalAcquireInitialTicketsForCache (desiredPrincipal, NULL, + krb5_cc_default_name (context), + kerberosVersion_V5, nil, &outCacheName); + if (err == klNoErr) { + /* This function tries to get tickets and put them in the specified + cache, however, if the cache does not exist, it may choose to put + them elsewhere (ie: the system default) so we set that here */ + if (strcmp (krb5_cc_default_name (context), outCacheName) != 0) { + krb5_cc_set_default_name (context, outCacheName); + } + KLDisposeString (outCacheName); + } + + if (desiredPrincipal != nil) + KLDisposePrincipal (desiredPrincipal); + } +#endif + + return krb5_cc_default (context, ccache); } diff --git a/src/lib/krb5/ccache/ccdefops.c b/src/lib/krb5/ccache/ccdefops.c index 2651273..092503e 100644 --- a/src/lib/krb5/ccache/ccdefops.c +++ b/src/lib/krb5/ccache/ccdefops.c @@ -30,7 +30,7 @@ #include "k5-int.h" -#if defined(macintosh) +#if defined(USE_CCAPI) /* * Macs use the shared, memory based credentials cache diff --git a/src/lib/krb5/ccache/ccfns.c b/src/lib/krb5/ccache/ccfns.c new file mode 100644 index 0000000..b12c93e --- /dev/null +++ b/src/lib/krb5/ccache/ccfns.c @@ -0,0 +1,131 @@ +/* + * lib/krb5/ccache/ccfns.c + * + * Copyright 2000 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. + */ + +/* + * Dispatch methods for credentials cache code. + */ + +#include "k5-int.h" +#include "krb5.h" + +#if KRB5_CCACHE_ACCESSOR_FUNCTIONS + +const char FAR * KRB5_CALLCONV +krb5_cc_get_name (krb5_context context, krb5_ccache cache) +{ + return cache->ops->get_name(context, cache); +} + +krb5_error_code KRB5_CALLCONV +krb5_cc_gen_new (krb5_context context, krb5_ccache FAR *cache) +{ + return (*cache)->ops->gen_new(context, cache); +} + +krb5_error_code KRB5_CALLCONV +krb5_cc_initialize(krb5_context context, krb5_ccache cache, + krb5_principal principal) +{ + return cache->ops->init(context, cache, principal); +} + +krb5_error_code KRB5_CALLCONV +krb5_cc_destroy (krb5_context context, krb5_ccache cache) +{ + return cache->ops->destroy(context, cache); +} + +krb5_error_code KRB5_CALLCONV +krb5_cc_close (krb5_context context, krb5_ccache cache) +{ + return cache->ops->close(context, cache); +} + +krb5_error_code KRB5_CALLCONV +krb5_cc_store_cred (krb5_context context, krb5_ccache cache, + krb5_creds FAR *creds) +{ + return cache->ops->store(context, cache, creds); +} + +krb5_error_code KRB5_CALLCONV +krb5_cc_retrieve_cred (krb5_context context, krb5_ccache cache, + krb5_flags flags, krb5_creds FAR *mcreds, + krb5_creds FAR *creds) +{ + return cache->ops->retrieve(context, cache, flags, mcreds, creds); +} + +krb5_error_code KRB5_CALLCONV +krb5_cc_get_principal (krb5_context context, krb5_ccache cache, + krb5_principal FAR *principal) +{ + return cache->ops->get_princ(context, cache, principal); +} + +krb5_error_code KRB5_CALLCONV +krb5_cc_start_seq_get (krb5_context context, krb5_ccache cache, + krb5_cc_cursor FAR *cursor) +{ + return cache->ops->get_first(context, cache, cursor); +} + +krb5_error_code KRB5_CALLCONV +krb5_cc_next_cred (krb5_context context, krb5_ccache cache, + krb5_cc_cursor FAR *cursor, krb5_creds FAR *creds) +{ + return cache->ops->get_next(context, cache, cursor, creds); +} + +krb5_error_code KRB5_CALLCONV +krb5_cc_end_seq_get (krb5_context context, krb5_ccache cache, + krb5_cc_cursor FAR *cursor) +{ + return cache->ops->end_get(context, cache, cursor); +} + +krb5_error_code KRB5_CALLCONV +krb5_cc_remove_cred (krb5_context context, krb5_ccache cache, krb5_flags flags, + krb5_creds FAR *creds) +{ + return cache->ops->remove_cred(context, cache, flags, creds); +} + +krb5_error_code KRB5_CALLCONV +krb5_cc_set_flags (krb5_context context, krb5_ccache cache, krb5_flags flags) +{ + return cache->ops->set_flags(context, cache, flags); +} + +const char FAR * KRB5_CALLCONV +krb5_cc_get_type (krb5_context context, krb5_ccache cache) +{ + return cache->ops->prefix; +} +#else +/* Dummy variable for compilers which don't like empty files */ +static krb5_int dummy = 0; +#endif /* KRB5_CCACHE_ACCESSOR_FUNCTIONS */ \ No newline at end of file diff --git a/src/lib/krb5/ccache/file/ChangeLog b/src/lib/krb5/ccache/file/ChangeLog index 298360b..cda7184 100644 --- a/src/lib/krb5/ccache/file/ChangeLog +++ b/src/lib/krb5/ccache/file/ChangeLog @@ -1,3 +1,6 @@ +2002-02-28 Alexandra Ellwood + * fcc_gprinc.c: removed unused data variable to reduce warnings + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/lib/krb5/ccache/file/fcc_gprin.c b/src/lib/krb5/ccache/file/fcc_gprin.c index b8a2595..bbac185 100644 --- a/src/lib/krb5/ccache/file/fcc_gprin.c +++ b/src/lib/krb5/ccache/file/fcc_gprin.c @@ -50,7 +50,6 @@ krb5_fcc_get_principal(context, id, princ) krb5_principal *princ; { krb5_error_code kret = KRB5_OK; - krb5_fcc_data *data = (krb5_fcc_data *)id->data; MAYBE_OPEN(context, id, FCC_OPEN_RDONLY); diff --git a/src/lib/krb5/ccache/stdio/ChangeLog b/src/lib/krb5/ccache/stdio/ChangeLog index c520ca3..1379190 100644 --- a/src/lib/krb5/ccache/stdio/ChangeLog +++ b/src/lib/krb5/ccache/stdio/ChangeLog @@ -1,3 +1,6 @@ +2002-02-28 Alexandra Ellwood + * scc_skip.c: removed unused princ variable to reduce warnings + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/lib/krb5/ccache/stdio/scc_skip.c b/src/lib/krb5/ccache/stdio/scc_skip.c index c203c71..9c86cb7 100644 --- a/src/lib/krb5/ccache/stdio/scc_skip.c +++ b/src/lib/krb5/ccache/stdio/scc_skip.c @@ -37,7 +37,6 @@ krb5_scc_skip_header(context, id) krb5_ccache id; { krb5_error_code kret; - krb5_principal princ; krb5_scc_data *data = (krb5_scc_data *) id->data; krb5_ui_2 scc_flen; diff --git a/src/lib/krb5/error_tables/ChangeLog b/src/lib/krb5/error_tables/ChangeLog index d93bf5e..710d7a4 100644 --- a/src/lib/krb5/error_tables/ChangeLog +++ b/src/lib/krb5/error_tables/ChangeLog @@ -1,3 +1,19 @@ +2001-10-29 Miro Jurisic + * pullup from krb5-1-2 branch after krb5-1-2-2-bp + * krb5_err.et: Changed Credentials Cache file to Credentials Cache + because on Mac and Windows, the credentials cache is in memory. + +2001-10-24 Tom Yu + + * kdb5_err.et: Add KRB5_KDB_NO_PERMITTED_KEY, + KRB5_KDB_NO_MATCHING_KEY for libkdb so we can return something + other than ENOENT (which was Just Wrong). + +2001-01-31 Tom Yu + + * asn1_err.et: Add error codes MISMATCH_INDEF and MISSING_EOC. + [pullup from trunk] + 1999-12-01 Ken Raeburn * krb5_err.et (KRB5_OBSOLETE_FN): New error code. diff --git a/src/lib/krb5/error_tables/asn1_err.et b/src/lib/krb5/error_tables/asn1_err.et index f0136cf..06078ff 100644 --- a/src/lib/krb5/error_tables/asn1_err.et +++ b/src/lib/krb5/error_tables/asn1_err.et @@ -10,4 +10,6 @@ error_code ASN1_BAD_LENGTH, "ASN.1 length doesn't match expected value" error_code ASN1_BAD_FORMAT, "ASN.1 badly-formatted encoding" error_code ASN1_PARSE_ERROR, "ASN.1 parse error" error_code ASN1_BAD_GMTIME, "ASN.1 bad return from gmtime" +error_code ASN1_MISMATCH_INDEF, "ASN.1 non-constructed indefinite encoding" +error_code ASN1_MISSING_EOC, "ASN.1 missing expected EOC" end diff --git a/src/lib/krb5/error_tables/kdb5_err.et b/src/lib/krb5/error_tables/kdb5_err.et index 982a9c1..aee3c4a 100644 --- a/src/lib/krb5/error_tables/kdb5_err.et +++ b/src/lib/krb5/error_tables/kdb5_err.et @@ -66,4 +66,6 @@ ec KRB5_KDB_BAD_VERSION, "Unsupported version in database entry" ec KRB5_KDB_BAD_SALTTYPE, "Unsupported salt type" ec KRB5_KDB_BAD_ENCTYPE, "Unsupported encryption type" ec KRB5_KDB_BAD_CREATEFLAGS, "Bad database creation flags" +ec KRB5_KDB_NO_PERMITTED_KEY, "No matching key in entry having a permitted enctype" +ec KRB5_KDB_NO_MATCHING_KEY, "No matching key in entry" end diff --git a/src/lib/krb5/error_tables/krb5_err.et b/src/lib/krb5/error_tables/krb5_err.et index 6135a9d..8ff5ff3 100644 --- a/src/lib/krb5/error_tables/krb5_err.et +++ b/src/lib/krb5/error_tables/krb5_err.et @@ -259,10 +259,10 @@ error_code KRB5_CC_TYPE_EXISTS, "Credentials cache type is already registered." error_code KRB5_KT_TYPE_EXISTS, "Key table type is already registered." error_code KRB5_CC_IO, "Credentials cache I/O operation failed XXX" -error_code KRB5_FCC_PERM, "Credentials cache file permissions incorrect" -error_code KRB5_FCC_NOFILE, "No credentials cache file found" -error_code KRB5_FCC_INTERNAL, "Internal file credentials cache error" -error_code KRB5_CC_WRITE, "Error writing to credentials cache file" +error_code KRB5_FCC_PERM, "Credentials cache permissions incorrect" +error_code KRB5_FCC_NOFILE, "No credentials cache found" +error_code KRB5_FCC_INTERNAL, "Internal credentials cache error" +error_code KRB5_CC_WRITE, "Error writing to credentials cache" error_code KRB5_CC_NOMEM, "No more memory to allocate (in credentials cache code)" error_code KRB5_CC_FORMAT, "Bad format in credentials cache" error_code KRB5_CC_NOT_KTYPE, "No credentials found with supported encryption types" diff --git a/src/lib/krb5/keytab/ChangeLog b/src/lib/krb5/keytab/ChangeLog index fa1e715..e1ba1cc 100644 --- a/src/lib/krb5/keytab/ChangeLog +++ b/src/lib/krb5/keytab/ChangeLog @@ -1,3 +1,20 @@ +2002-04-05 Danilo Almeida + + * Makefile.in: Build kt accessor functions on Windows. + + * ktfr_entry.c: Rename krb5_kt_free_entry_contents as + krb5_free_keytab_entry_contents to make it consistent with rest of + API. + +2002-04-02 Ken Raeburn + + * ktfr_entry.c (krb5_kt_free_entry_contents): Rename from + krb5_kt_free_entry, keep old name as wrapper. + +2000-04-01 Miro Jurisic + + * ktfns.c: Merged from trunk + 2000-03-12 Ezra Peisach * ktbase.c (krb5_kt_resolve): Change prototype from const to diff --git a/src/lib/krb5/keytab/Makefile.in b/src/lib/krb5/keytab/Makefile.in index 66677a1..7d2b023 100644 --- a/src/lib/krb5/keytab/Makefile.in +++ b/src/lib/krb5/keytab/Makefile.in @@ -35,6 +35,8 @@ SRCS= \ $(srcdir)/ktremove.c \ $(srcdir)/read_servi.c +##DOS##OBJS=$(OBJS) $(OUTPRE)ktfns.$(OBJEXT) + all-windows:: subdirs $(OBJFILE) ##DOSsubdirs:: file\$(OUTPRE)file.lst srvtab\$(OUTPRE)srvtab.lst diff --git a/src/lib/krb5/keytab/file/ChangeLog b/src/lib/krb5/keytab/file/ChangeLog index 4be401b..d0ececa 100644 --- a/src/lib/krb5/keytab/file/ChangeLog +++ b/src/lib/krb5/keytab/file/ChangeLog @@ -1,3 +1,16 @@ +2002-01-30 Ken Raeburn + + * ktf_g_ent.c (krb5_ktfile_get_entry): For non-zero kvno, match + only low 8 bits. For zero kvno, if any kvno in the keytab is over + 240, assume we're dealing with numbers 128 through (127+256) + instead. This allows for wrapping at 256 while retaining a small + set of consecutively numbered prior keys in the keytab. + +2001-11-19 Tom Yu + + * ktf_g_ent.c (krb5_ktfile_get_entry): Coerce enctype for now to + restore 1.0.x enctype similarity behavior. + 1999-10-26 Tom Yu * Makefile.in: Clean up usage of CFLAGS, CPPFLAGS, DEFS, DEFINES, diff --git a/src/lib/krb5/keytab/file/ktf_g_ent.c b/src/lib/krb5/keytab/file/ktf_g_ent.c index b45ab6f..905ff6c 100644 --- a/src/lib/krb5/keytab/file/ktf_g_ent.c +++ b/src/lib/krb5/keytab/file/ktf_g_ent.c @@ -45,6 +45,7 @@ krb5_ktfile_get_entry(context, id, principal, kvno, enctype, entry) krb5_error_code kerror = 0; int found_wrong_kvno = 0; krb5_boolean similar; + int kvno_offset = 0; /* Open the keyfile for reading */ if ((kerror = krb5_ktfileint_openr(context, id))) @@ -81,6 +82,14 @@ krb5_ktfile_get_entry(context, id, principal, kvno, enctype, entry) krb5_kt_free_entry(context, &new_entry); continue; } + /* + * Coerce the enctype of the output keyblock in case we + * got an inexact match on the enctype; this behavior will + * go away when the key storage architecture gets + * redesigned for 1.3. + */ + new_entry.key.enctype = enctype; + } /* if the principal isn't the one requested, free new_entry @@ -95,9 +104,24 @@ krb5_ktfile_get_entry(context, id, principal, kvno, enctype, entry) /* if this is the first match, or if the new vno is bigger, free the current and keep the new. Otherwise, free the new. */ - + /* A 1.2.x keytab contains only the low 8 bits of the key + version number. Since it can be much bigger, and thus + the 8-bit value can wrap, we need some heuristics to + figure out the "highest" numbered key if some numbers + close to 255 and some near 0 are used. + + The heuristic here: + + If we have any keys with versions over 240, then assume + that all version numbers 0-127 refer to 256+N instead. + Not perfect, but maybe good enough? */ + +#define M(VNO) (((VNO) - kvno_offset + 256) % 256) + + if (new_entry.vno > 240) + kvno_offset = 128; if (! cur_entry.principal || - (new_entry.vno > cur_entry.vno)) { + M(new_entry.vno) > M(cur_entry.vno)) { krb5_kt_free_entry(context, &cur_entry); cur_entry = new_entry; } else { @@ -108,8 +132,12 @@ krb5_ktfile_get_entry(context, id, principal, kvno, enctype, entry) be one?), keep the new, and break out. Otherwise, remember that we were here so we can return the right error, and free the new */ + /* Yuck. The krb5-1.2.x keytab format only stores one byte + for the kvno, so we're toast if the kvno requested is + higher than that. Short-term workaround: only compare + the low 8 bits. */ - if (new_entry.vno == kvno) { + if (new_entry.vno == (kvno & 0xff)) { krb5_kt_free_entry(context, &cur_entry); cur_entry = new_entry; break; diff --git a/src/lib/krb5/keytab/ktfns.c b/src/lib/krb5/keytab/ktfns.c new file mode 100644 index 0000000..5bd6b40 --- /dev/null +++ b/src/lib/krb5/keytab/ktfns.c @@ -0,0 +1,80 @@ +/* + * lib/krb5/keytab/ktfns.c + * + * Copyright 2001 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. + */ + +/* + * Dispatch methods for keytab code. + */ + +#include "krb5.h" +#include "k5-int.h" + +char * KRB5_CALLCONV +krb5_kt_get_type (krb5_context context, krb5_keytab keytab) +{ + return keytab->ops->prefix; +} + +krb5_error_code KRB5_CALLCONV +krb5_kt_get_name(krb5_context context, krb5_keytab keytab, char *name, + unsigned int namelen) +{ + return krb5_x((keytab)->ops->get_name,(context, keytab,name,namelen)); +} + +krb5_error_code KRB5_CALLCONV +krb5_kt_close(krb5_context context, krb5_keytab keytab) +{ + return krb5_x((keytab)->ops->close,(context, keytab)); +} + +krb5_error_code KRB5_CALLCONV +krb5_kt_get_entry(krb5_context context, krb5_keytab keytab, + krb5_const_principal principal, krb5_kvno vno, + krb5_enctype enctype, krb5_keytab_entry *entry) +{ + return krb5_x((keytab)->ops->get,(context, keytab, principal, vno, enctype, entry)); +} + +krb5_error_code KRB5_CALLCONV +krb5_kt_start_seq_get(krb5_context context, krb5_keytab keytab, + krb5_kt_cursor *cursor) +{ + return krb5_x((keytab)->ops->start_seq_get,(context, keytab, cursor)); +} + +krb5_error_code KRB5_CALLCONV +krb5_kt_next_entry(krb5_context context, krb5_keytab keytab, + krb5_keytab_entry *entry, krb5_kt_cursor *cursor) +{ + return krb5_x((keytab)->ops->get_next,(context, keytab, entry, cursor)); +} + +krb5_error_code KRB5_CALLCONV +krb5_kt_end_seq_get(krb5_context context, krb5_keytab keytab, + krb5_kt_cursor *cursor) +{ + return krb5_x((keytab)->ops->end_get,(context, keytab, cursor)); +} diff --git a/src/lib/krb5/keytab/ktfr_entry.c b/src/lib/krb5/keytab/ktfr_entry.c index ddccb17..abd5d4d 100644 --- a/src/lib/krb5/keytab/ktfr_entry.c +++ b/src/lib/krb5/keytab/ktfr_entry.c @@ -30,7 +30,7 @@ #include "k5-int.h" KRB5_DLLIMP krb5_error_code KRB5_CALLCONV -krb5_kt_free_entry (context, entry) +krb5_free_keytab_entry_contents (context, entry) krb5_context context; krb5_keytab_entry FAR *entry; { @@ -44,3 +44,11 @@ krb5_kt_free_entry (context, entry) } return 0; } + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_kt_free_entry (context, entry) + krb5_context context; + krb5_keytab_entry FAR *entry; +{ + return krb5_free_keytab_entry_contents (context, entry); +} diff --git a/src/lib/krb5/keytab/srvtab/ChangeLog b/src/lib/krb5/keytab/srvtab/ChangeLog index a4157a0..8724b71 100644 --- a/src/lib/krb5/keytab/srvtab/ChangeLog +++ b/src/lib/krb5/keytab/srvtab/ChangeLog @@ -1,9 +1,17 @@ +2002-02-28 Alexandra Ellwood + * kts_util.c: removed unused variable n + +2002-02-05 Ken Raeburn + + * kts_g_ent.c (krb5_ktsrvtab_get_entry): If a specific DES enctype + was requested, set the key's enctype to it, instead of always + returning des-cbc-crc. + Fri Jan 28 19:53:44 2000 Ezra Peisach * kts_g_ent.c, ktsrvtab.h (krb5_ktsrvtab_get_entry): Change the third argument to krb5_const_principal (from krb5_principal) to agree with krb5_kts_ops entries. - 1999-10-26 Tom Yu diff --git a/src/lib/krb5/keytab/srvtab/kts_g_ent.c b/src/lib/krb5/keytab/srvtab/kts_g_ent.c index e422c38..0237241 100644 --- a/src/lib/krb5/keytab/srvtab/kts_g_ent.c +++ b/src/lib/krb5/keytab/srvtab/kts_g_ent.c @@ -65,6 +65,7 @@ krb5_ktsrvtab_get_entry(context, id, principal, kvno, enctype, entry) best_entry.vno = 0; best_entry.key.contents = 0; while ((kerror = krb5_ktsrvint_read_entry(context, id, &ent)) == 0) { + ent.key.enctype = enctype; if (krb5_principal_compare(context, principal, ent.principal)) { if (kvno == IGNORE_VNO) { if (!best_entry.principal || (best_entry.vno < ent.vno)) { diff --git a/src/lib/krb5/keytab/srvtab/kts_util.c b/src/lib/krb5/keytab/srvtab/kts_util.c index d95aceb..35f4a16 100644 --- a/src/lib/krb5/keytab/srvtab/kts_util.c +++ b/src/lib/krb5/keytab/srvtab/kts_util.c @@ -62,7 +62,7 @@ read_field(fp, s, len) char *s; int len; { - int c, n = 0; + int c = 0; while ((c = getc(fp)) != 0) { if (c == EOF || len <= 1) diff --git a/src/lib/krb5/krb/ChangeLog b/src/lib/krb5/krb/ChangeLog index 59d8765..470ee9c 100644 --- a/src/lib/krb5/krb/ChangeLog +++ b/src/lib/krb5/krb/ChangeLog @@ -1,3 +1,287 @@ +2002-10-30 Tom Yu + + * chk_trans.c (krb5_check_transited_list): Style nit: check + character against '\0' not NULL. + [pullup from trunk] + +2002-10-30 Sam Hartman + + * chk_trans.c: Ignore trailing null in transited encoding; older + versions of MIT code included this. + [pullup from trunk] + +2002-08-12 Tom Yu + + * unparse.c (krb5_unparse_name_ext): Error out if passed a NULL + pointer. Patch from Mark Levinson; fixes [krb5-admin/1140]. + [pullup from trunk] + +2002-04-05 Danilo Almeida + + * princ_comp.c (krb5_realm_compare), auth_con.c + (krb5_auth_con_setports, krb5_auth_con_getaddrs, + krb5_auth_con_initivector), addr_order.c (krb5_address_order), + addr_comp.c (krb5_address_compare): Make KRB5_CALLCONV. + +2002-04-03 Danilo Almeida + + * bld_princ.c (krb5_build_principal_va): Make + krb5_build_principal_va() KRB5_CALLCONV. + +2002-04-02 Sam Hartman + + * init_keyblock.c: Merge from mainline + +2002-03-15 Sam Hartman + + * walk_rtree.c (krb5_walk_realm_tree): Fix handling of null realms + +2002-03-14 Alexandra Ellwood + * appdefault.c, get_in_tkt.c: made conf_yes and conf_no const to + improve load time on Mach-O + +2002-03-13 Sam Hartman + + * rd_cred.c (krb5_rd_cred): Don't check IP addresses; improves + Heimdal compatibility. + +2002-02-28 Alexandra Ellwood + * conv_princ.c: removed unused variable cpp to reduce warnings + * get_creds.c: removed unused variables fields and mcreds to + reduce warnings + * get_in_tkt.c: removed unused variables cpp and preauth_to_use + to reduce warnings + * init_ctx: fixed Mac OS macros + * parse.c: added type in to avoid "defaults to int" warning + * send_tgs.c: removed unused variable enclen + +2001-12-20 Ken Raeburn + + * ser_actx.c (krb5_auth_context_externalize): Pass address of a + size_t, not a krb5_int32, to krb5_c_block_size. + +2001-11-29 Ken Raeburn + + * fwd_tgt.c (krb5_fwd_tgt_creds): If no session key has been set, + try getting credentials and use the session key type as a hint + for the enctype to use for the forwarded credentials. + + 2001-11-24 Sam Hartman + + * fwd_tgt.c (krb5_fwd_tgt_creds): Get a session key for the + forwarded tgt that is the same as the session key for the + auth_context. This is an enctype we know the remote side + supports. + +2001-10-29 Miro Jurisic + * pullup from krb5-1-2 branch after krb5-1-2-2-bp + * rd_safe.c, rd_priv.c, rd_cred.c, preauth.c, mk_safe.c, + mk_cred.c, appdefault.c: use "" includes for krb5.h, k5-int.h and + syslog.h + * gic_pwd.c, sendauth.c, recvauth.c: com_err.h is already included by + k5-int.h. Removed #include because it was confusing the Mac OS X builds + +2001-09-25 Ken Raeburn + + * chk_trans.c: Reimplemented from scratch. + +2001-01-30 Tom Yu + + * preauth.c (krb5_obtain_padata): Don't dereference a NULL pointer + if we receive an empty ETYPE_INFO preauth. [krb5-libs/903 from + craziboy77@hotmail.com] + + * preauth2.c (krb5_do_preauth): Don't dereference a NULL pointer + if we receive an empty ETYPE_INFO preauth. [krb5-libs/903 from + craziboy77@hotmail.com] + +2001-01-30 Ezra Peisach + + * rd_req_dec.c (krb5_rd_req_decrypt_tkt_part): Free + krb5_keytab_entry if call to krb5_decrypt_tkt_part() + fails. [krb5-libs/855 reported by guy@packeteer.com] + +2001-01-30 Ken Raeburn + + * mk_safe.c (krb5_mk_safe): Only use safe_cksumtype from the + auth_context (derived from the config file or hardcoded default) + if it's suitable for the enctype of the key we're going to use. + +2001-01-29 Alexandra Ellwood + + * conv_princ.c (krb5_524_conv_principal): Fixed strncmp bug where principals + which are left substrings of "changepw" were being remapped into "changepw". + Added length check to if() statement. + +2001-01-29 Ken Raeburn + + * preauth2.c (pa_sam): Check for a null prompter function pointer, + and return an error for that case rather than crashing. + +2000-10-02 Alexandra Ellwood + + * init_ctx.c: Added #defines for Mac OS X (__MACH__) + +2000-06-29 Tom Yu + + * conv_princ.c (krb5_425_conv_principal): NULL, not nil. + +2000-06-28 Miro Jurisic + + * conv_princ.c (krb5_425_conv_principal): Fixed a memory leak + +2000-06-17 Miro Jurisic + + * conv_princ.c (krb5_425_conv_principal): Fixed v4->v5 realm + name conversion + +2000-06-17 Miro Jurisic + + * conv_princ.c (krb5_425_conv_principal): Honor v4/v5 realm name + differences when convertion from v4 principals to v5. + +2000-06-07 Tom Yu + + * get_creds.c (krb5_get_credentials): Translate KRB5_CC_NOTFOUND + returned from krb5_get_cred_from_kdc() if a prior call to + krb5_cc_retrieve_cred() returned KRB5_CC_NOT_KTYPE. + +2000-06-03 Tom Yu + + * rd_priv.c (krb5_rd_priv_basic): Delete code that was incorrectly + doing explicit ivec chaining; c_decrypt() does it now. + + * mk_priv.c (krb5_mk_priv_basic): Delete code that was incorrectly + doing explicit ivec chaining; c_encrypt() does it now. + +2000-06-03 Ken Raeburn + + * get_in_tkt.c (krb5_get_in_tkt): If enctypes are specified, send + the server the intersection of that list and the supported types, + in the order requested. + +2000-06-02 Danilo Almeida + + * init_ctx.c (krb5_get_tgs_ktypes, krb5_free_ktypes): Fix linkage to + be KRB5_CALLCONV. + +2000-05-31 Ken Raeburn + + * recvauth.c (krb5_recvauth_version): New routine, takes a + krb5_data in which to store the client's application version + string. + (recvauth_common): Renamed from krb5_recvauth, added above + functionality depending on extra argument values. + (krb5_recvauth): New stub, calls above routine with extra dummy + values. + +2000-5-19 Alexandra Ellwood + + * sendauth.c, fwd_tgt.c: Changed to use krb5int_cc_default. This function + supports the Kerberos Login Library and pops up a dialog if the cache does + not contain valid tickets. This is used to automatically get a tgt before + obtaining service tickets. Note that this should be an internal function + because callers don't expect krb5_cc_default to pop up a dialog! + (We found this out the hard way :-) + +2000-05-16 Ken Raeburn + Nalin Dahyabhai + + * conv_princ.c (krb5_524_conv_principal): Return an error if name + is too long. Use memcpy for character data since we already know + the length. + +2000-05-16 Ken Raeburn + + * kfree.c: Remove unneeded "return" statements at the end of many + functions. + (krb5_free_*_content, krb5_free_*_contents, + krb5_free_cred_enc_part, krb5_free_pwd_sequences): Set freed + pointer members to null when containing structure isn't being + freed. + +2000-05-16 Tom Yu + + * conv_princ.c (krb5_524_conv_principal): Make a copy of the krb5 + realm that is nul-terminated to avoid falling off the end of the + krb5 realm, which is not necessarily nul-terminated. + +2000-05-16 Nalin Dahyabhai + + * kfree.c (krb5_free_keyblock_contents): Set contents pointer to + null after freeing. + +2000-05-15 Jeffrey Altman + + * Added new source file appdefault.c + Implements new public functions + + krb5_appdefault_string + krb5_appdefault_boolean + +2000-05-12 Ken Raeburn + + * t_kerb.c (test_524_conv_principal): New test code, to exercise + yesterday's code addition. + (main, usage): Updated. + * t_krb5.conf: Added stanford.edu->IR.STANFORD.EDU mapping, and a + test case for improperly long v4 realm names. + * Makefile.in (check-unix): Run 524 conversion test for some test + Athena and Stanford names. + * t_ref_kerb.out: Updated. + + * init_ctx.c (init_common): Feed current-microsecond time and + process-id into PRNG, instead of just current-second time. + * mk_req_ext.c (krb5_mk_req_extended): Feed current time into + PRNG if a subkey will be generated. + * sendauth.c (krb5_sendauth): Feed local and remote addresses of + socket, if they can be determined, into the PRNG if a subkey will + be used. + +2000-05-11 Ken Raeburn + Booker C. Bense + + * conv_princ.c (krb5_524_conv_principal): Look up v4_realm in + config file, in case site's krb4 realm name isn't the same as the + krb5 realm name. + +2000-04-28 Nalin Dahyabhai + + * chk_trans.c (krb5_check_transited_list): Don't overflow buffers + "prev" and "next". + * conv_princ.c (krb5_425_conv_principal): Don't overflow buffer + "buf". + +2000-04-28 Alexandra Ellwood + + * gic_pwd.c (krb5_init_creds_password) added code to return to + login library if the password is expired (login library handles + this error appropriately). + +2000-04-18 Ken Raeburn + + * init_ctx.c (krb5_free_ktypes): New routine, to free values + returned by krb5_get_tgs_ktypes, krb5_get_permitted_enctypes, and + krb5_get_default_in_tkt_ktypes. + (krb5_set_default_tgs_ktypes, krb5_is_permitted_enctype): Use it. + (get_profile_etype_list): Use passed-in enctype list if the + passed-in count is non-zero, instead of checking the + in_tkt_ktype_count value in the context. + +2000-04-08 Tom Yu + + * vfy_increds.c (krb5_verify_init_creds): appdefault_boolean -> + libdefault_boolean; it somehow got missed earlier. + +2000-04-07 Jeffrey Altman + + * gic_pwd.c (krb5_get_init_creds_keytab), gic_pwd.c + (krb5_get_init_creds_password) when determining whether or not to + retry with a "master kdc" do not retry if the return value from + the first attempt was KRB5_REALM_CANT_RESOLV. Also, do not + overwrite the return code if the return value from the access to + the "master kdc" was KRB5_REALM_CANT_RESOLV. + 2000-03-15 Danilo Almeida * init_ctx.c (init_common), gic_pwd.c (krb5_get_as_key_password, diff --git a/src/lib/krb5/krb/Makefile.in b/src/lib/krb5/krb/Makefile.in index ba76662..484cd39 100644 --- a/src/lib/krb5/krb/Makefile.in +++ b/src/lib/krb5/krb/Makefile.in @@ -15,6 +15,7 @@ STLIBOBJS= \ addr_comp.o \ addr_order.o \ addr_srch.o \ + appdefault.o \ auth_con.o \ bld_pr_ext.o \ bld_princ.o \ @@ -52,6 +53,7 @@ STLIBOBJS= \ in_tkt_pwd.o \ in_tkt_sky.o \ init_ctx.o \ + init_keyblock.o \ kdc_rep_dc.o \ kfree.o \ mk_cred.o \ @@ -99,6 +101,7 @@ STLIBOBJS= \ OBJS= $(OUTPRE)addr_comp.$(OBJEXT) \ $(OUTPRE)addr_order.$(OBJEXT) \ $(OUTPRE)addr_srch.$(OBJEXT) \ + $(OUTPRE)appdefault.$(OBJEXT) \ $(OUTPRE)auth_con.$(OBJEXT) \ $(OUTPRE)bld_pr_ext.$(OBJEXT) \ $(OUTPRE)bld_princ.$(OBJEXT) \ @@ -136,6 +139,7 @@ OBJS= $(OUTPRE)addr_comp.$(OBJEXT) \ $(OUTPRE)in_tkt_pwd.$(OBJEXT) \ $(OUTPRE)in_tkt_sky.$(OBJEXT) \ $(OUTPRE)init_ctx.$(OBJEXT) \ + $(OUTPRE)init_keyblock.$(OBJEXT) \ $(OUTPRE)kdc_rep_dc.$(OBJEXT) \ $(OUTPRE)kfree.$(OBJEXT) \ $(OUTPRE)mk_cred.$(OBJEXT) \ @@ -183,6 +187,7 @@ OBJS= $(OUTPRE)addr_comp.$(OBJEXT) \ SRCS= $(srcdir)/addr_comp.c \ $(srcdir)/addr_order.c \ $(srcdir)/addr_srch.c \ + $(srcdir)/appdefault.c \ $(srcdir)/auth_con.c \ $(srcdir)/bld_pr_ext.c \ $(srcdir)/bld_princ.c \ @@ -221,6 +226,7 @@ SRCS= $(srcdir)/addr_comp.c \ $(srcdir)/in_tkt_pwd.c \ $(srcdir)/in_tkt_sky.c \ $(srcdir)/init_ctx.c \ + $(srcdir)/init_keyblock.c \ $(srcdir)/kdc_rep_dc.c \ $(srcdir)/kfree.c \ $(srcdir)/mk_cred.c \ @@ -324,6 +330,8 @@ check-unix:: $(TEST_PROGS) 425_conv_principal rcmd uunet UU.NET \ 425_conv_principal zephyr zephyr ATHENA.MIT.EDU \ 425_conv_principal kadmin ATHENA.MIT.EDU ATHENA.MIT.EDU \ + 524_conv_principal host/e40-po.mit.edu@ATHENA.MIT.EDU \ + 524_conv_principal host/foobar.stanford.edu@stanford.edu \ set_realm marc@MIT.EDU CYGNUS.COM \ > test.out cmp test.out $(srcdir)/t_ref_kerb.out diff --git a/src/lib/krb5/krb/addr_comp.c b/src/lib/krb5/krb/addr_comp.c index 587bd5f..f9e10bb 100644 --- a/src/lib/krb5/krb/addr_comp.c +++ b/src/lib/krb5/krb/addr_comp.c @@ -32,7 +32,7 @@ /* * If the two addresses are the same, return TRUE, else return FALSE */ -krb5_boolean +krb5_boolean KRB5_CALLCONV krb5_address_compare(context, addr1, addr2) krb5_context context; krb5_const krb5_address *addr1; diff --git a/src/lib/krb5/krb/addr_order.c b/src/lib/krb5/krb/addr_order.c index 800fa2b..2598205 100644 --- a/src/lib/krb5/krb/addr_order.c +++ b/src/lib/krb5/krb/addr_order.c @@ -37,7 +37,7 @@ * Return an ordering on two addresses: 0 if the same, * < 0 if first is less than 2nd, > 0 if first is greater than 2nd. */ -int +int KRB5_CALLCONV krb5_address_order(context, addr1, addr2) krb5_context context; register krb5_const krb5_address *addr1; diff --git a/src/lib/krb5/krb/appdefault.c b/src/lib/krb5/krb/appdefault.c new file mode 100644 index 0000000..65a9459 --- /dev/null +++ b/src/lib/krb5/krb/appdefault.c @@ -0,0 +1,183 @@ +/* + * appdefault - routines designed to be called from applications to + * handle the [appdefaults] profile section + */ + +#include +#include +#include "k5-int.h" + + + + /*xxx Duplicating this is annoying; try to work on a better way.*/ +static const char *conf_yes[] = { + "y", "yes", "true", "t", "1", "on", + 0, +}; + +static const char *conf_no[] = { + "n", "no", "false", "nil", "0", "off", + 0, +}; + +static int conf_boolean(s) + char *s; +{ + char **p; + for(p=conf_yes; *p; p++) { + if (!strcasecmp(*p,s)) + return 1; + } + for(p=conf_no; *p; p++) { + if (!strcasecmp(*p,s)) + return 0; + } + /* Default to "no" */ + return 0; +} + +static krb5_error_code appdefault_get(context, appname, realm, option, + ret_value) + krb5_context context; + const char *appname, *option; + const krb5_data *realm; + char **ret_value; +{ + profile_t profile; + const char *names[5]; + char **nameval = NULL; + krb5_error_code retval; + const char * realmstr = realm?realm->data:NULL; + + if (!context || (context->magic != KV5M_CONTEXT)) + return KV5M_CONTEXT; + + profile = context->profile; + + /* + * Try number one: + * + * [appdefaults] + * app = { + * SOME.REALM = { + * option = + * } + * } + */ + + names[0] = "appdefaults"; + names[1] = appname; + + if (realmstr) { + names[2] = realmstr; + names[3] = option; + names[4] = 0; + retval = profile_get_values(profile, names, &nameval); + if (retval == 0 && nameval && nameval[0]) { + *ret_value = strdup(nameval[0]); + goto goodbye; + } + } + + /* + * Try number two: + * + * [appdefaults] + * app = { + * option = + * } + */ + + names[2] = option; + names[3] = 0; + retval = profile_get_values(profile, names, &nameval); + if (retval == 0 && nameval && nameval[0]) { + *ret_value = strdup(nameval[0]); + goto goodbye; + } + + /* + * Try number three: + * + * [appdefaults] + * realm = { + * option = + */ + + if (realmstr) { + names[1] = realmstr; + names[2] = option; + names[3] = 0; + retval = profile_get_values(profile, names, &nameval); + if (retval == 0 && nameval && nameval[0]) { + *ret_value = strdup(nameval[0]); + goto goodbye; + } + } + + /* + * Try number four: + * + * [appdefaults] + * option = + */ + + names[1] = option; + names[2] = 0; + retval = profile_get_values(profile, names, &nameval); + if (retval == 0 && nameval && nameval[0]) { + *ret_value = strdup(nameval[0]); + } else { + return retval; + } + +goodbye: + if (nameval) { + char **cpp; + for (cpp = nameval; *cpp; cpp++) + free(*cpp); + free(nameval); + } + return 0; +} + +KRB5_DLLIMP void KRB5_CALLCONV +krb5_appdefault_boolean(context, appname, realm, option, + default_value, ret_value) + krb5_context context; + const char *appname, *option; + const krb5_data *realm; + int default_value; + int *ret_value; +{ + char *string = NULL; + krb5_error_code retval; + + retval = appdefault_get(context, appname, realm, option, &string); + + if (! retval && string) { + *ret_value = conf_boolean(string); + free(string); + } else + *ret_value = default_value; +} + +KRB5_DLLIMP void KRB5_CALLCONV +krb5_appdefault_string(context, appname, realm, option, default_value, + ret_value) + krb5_context context; + const char *appname, *option, *default_value; + char **ret_value; + const krb5_data *realm; + { + krb5_error_code retval; + char *string; + + retval = appdefault_get(context, appname, realm, option, &string); + + if (! retval && string) { + *ret_value = string; + } else { + *ret_value = strdup(default_value); + } +} diff --git a/src/lib/krb5/krb/auth_con.c b/src/lib/krb5/krb/auth_con.c index 335f7ae..f80a167 100644 --- a/src/lib/krb5/krb/auth_con.c +++ b/src/lib/krb5/krb/auth_con.c @@ -109,7 +109,7 @@ krb5_auth_con_setaddrs(context, auth_context, local_addr, remote_addr) return retval; } -krb5_error_code +krb5_error_code KRB5_CALLCONV krb5_auth_con_getaddrs(context, auth_context, local_addr, remote_addr) krb5_context context; krb5_auth_context auth_context; @@ -132,7 +132,7 @@ krb5_auth_con_getaddrs(context, auth_context, local_addr, remote_addr) return retval; } -krb5_error_code +krb5_error_code KRB5_CALLCONV krb5_auth_con_setports(context, auth_context, local_port, remote_port) krb5_context context; krb5_auth_context auth_context; @@ -270,7 +270,7 @@ krb5_auth_con_getremoteseqnumber(context, auth_context, seqnumber) return 0; } -krb5_error_code +krb5_error_code KRB5_CALLCONV krb5_auth_con_initivector(context, auth_context) krb5_context context; krb5_auth_context auth_context; diff --git a/src/lib/krb5/krb/bld_princ.c b/src/lib/krb5/krb/bld_princ.c index bf49105..34b50c0 100644 --- a/src/lib/krb5/krb/bld_princ.c +++ b/src/lib/krb5/krb/bld_princ.c @@ -37,6 +37,7 @@ #endif krb5_error_code +KRB5_CALLCONV krb5_build_principal_va(context, princ, rlen, realm, ap) krb5_context context; krb5_principal princ; diff --git a/src/lib/krb5/krb/chk_trans.c b/src/lib/krb5/krb/chk_trans.c index c2ac716..9fe73c8 100644 --- a/src/lib/krb5/krb/chk_trans.c +++ b/src/lib/krb5/krb/chk_trans.c @@ -1,12 +1,14 @@ /* - * Copyright (c) 1994 CyberSAFE Corporation. - * All rights reserved. + * lib/krb5/krb/chk_trans.c + * + * Copyright 2001 by the Massachusetts Institute of Technology. + * All Rights Reserved. * * Export of this software from the United States of America may * 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 @@ -14,97 +16,426 @@ * 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. Neither M.I.T., the Open Computing Security Group, nor - * CyberSAFE Corporation make any representations about the suitability of + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. + * + * + * krb5_check_transited_list() */ - #include "k5-int.h" -#include +#include -#define MAX_REALM_LN 500 +#if defined (TEST) || defined (TEST2) +# undef DEBUG +# define DEBUG +#endif -krb5_error_code -krb5_check_transited_list(context, trans, realm1, realm2) - krb5_context context; -krb5_data *trans; -krb5_data *realm1; -krb5_data *realm2; +#ifdef DEBUG +#define verbose krb5int_chk_trans_verbose +static int verbose = 0; +# define Tprintf(ARGS) if (verbose) printf ARGS +#else +# define Tprintf(ARGS) (void)(0) +#endif + +#define MAXLEN 512 + +static krb5_error_code +process_intermediates (krb5_error_code (*fn)(krb5_data *, void *), void *data, + const krb5_data *n1, const krb5_data *n2) { + unsigned int len1, len2, i; + char *p1, *p2; + + Tprintf (("process_intermediates(%.*s,%.*s)\n", + (int) n1->length, n1->data, (int) n2->length, n2->data)); + + len1 = n1->length; + len2 = n2->length; + + Tprintf (("(walking intermediates now)\n")); + /* Simplify... */ + if (len1 > len2) { + const krb5_data *p; + int tmp = len1; + len1 = len2; + len2 = tmp; + p = n1; + n1 = n2; + n2 = p; + } + /* Okay, now len1 is always shorter or equal. */ + if (len1 == len2) { + if (memcmp (n1->data, n2->data, len1)) { + Tprintf (("equal length but different strings in path: '%.*s' '%.*s'\n", + (int) n1->length, n1->data, (int) n2->length, n2->data)); + return KRB5KRB_AP_ERR_ILL_CR_TKT; + } + Tprintf (("(end intermediates)\n")); + return 0; + } + /* Now len1 is always shorter. */ + if (len1 == 0) + /* Shouldn't be possible. Internal error? */ + return KRB5KRB_AP_ERR_ILL_CR_TKT; + p1 = n1->data; + p2 = n2->data; + if (p1[0] == '/') { + /* X.500 style names, with common prefix. */ + if (p2[0] != '/') { + Tprintf (("mixed name formats in path: x500='%.*s' domain='%.*s'\n", + (int) len1, p1, (int) len2, p2)); + return KRB5KRB_AP_ERR_ILL_CR_TKT; + } + if (memcmp (p1, p2, len1)) { + Tprintf (("x500 names with different prefixes '%.*s' '%.*s'\n", + (int) len1, p1, (int) len2, p2)); + return KRB5KRB_AP_ERR_ILL_CR_TKT; + } + for (i = len1 + 1; i < len2; i++) + if (p2[i] == '/') { + krb5_data d; + krb5_error_code r; + + d.data = p2; + d.length = i; + r = (*fn) (&d, data); + if (r) + return r; + } + } else { + /* Domain style names, with common suffix. */ + if (p2[0] == '/') { + Tprintf (("mixed name formats in path: domain='%.*s' x500='%.*s'\n", + (int) len1, p1, (int) len2, p2)); + return KRB5KRB_AP_ERR_ILL_CR_TKT; + } + if (memcmp (p1, p2 + (len2 - len1), len1)) { + Tprintf (("domain names with different suffixes '%.*s' '%.*s'\n", + (int) len1, p1, (int) len2, p2)); + return KRB5KRB_AP_ERR_ILL_CR_TKT; + } + for (i = len2 - len1 - 1; i > 0; i--) { + Tprintf (("looking at '%.*s'\n", (int) (len2 - i), p2+i)); + if (p2[i-1] == '.') { + krb5_data d; + krb5_error_code r; + + d.data = p2+i; + d.length = len2 - i; + r = (*fn) (&d, data); + if (r) + return r; + } + } + } + Tprintf (("(end intermediates)\n")); + return 0; +} + +static krb5_error_code +maybe_join (krb5_data *last, krb5_data *buf, int bufsiz) +{ + if (buf->length == 0) + return 0; + if (buf->data[0] == '/') { + if (last->length + buf->length > bufsiz) { + Tprintf (("too big: last=%d cur=%d max=%d\n", last->length, buf->length, bufsiz)); + return KRB5KRB_AP_ERR_ILL_CR_TKT; + } + memmove (buf->data+last->length, buf->data, buf->length); + memcpy (buf->data, last->data, last->length); + buf->length += last->length; + } else if (buf->data[buf->length-1] == '.') { + /* We can ignore the case where the previous component was + empty; the strcat will be a no-op. It should probably + be an error case, but let's be flexible. */ + if (last->length+buf->length > bufsiz) { + Tprintf (("too big\n")); + return KRB5KRB_AP_ERR_ILL_CR_TKT; + } + memcpy (buf->data + buf->length, last->data, last->length); + buf->length += last->length; + } + /* Otherwise, do nothing. */ + return 0; +} + +/* The input strings cannot contain any \0 bytes, according to the + spec, but our API is such that they may not be \0 terminated + either. Thus we keep on treating them as krb5_data objects instead + of C strings. */ +static krb5_error_code +foreach_realm (krb5_error_code (*fn)(krb5_data *comp,void *data), void *data, + const krb5_data *crealm, const krb5_data *srealm, + const krb5_data *transit) +{ + char buf[MAXLEN], last[MAXLEN]; + char *p, *bufp; + int next_lit, intermediates, l; + krb5_data this_component; + krb5_error_code r; + krb5_data last_component; + + /* Invariants: + - last_component points to last[] + - this_component points to buf[] + - last_component has length of last + - this_component has length of buf when calling out + Keep these consistent, and we should be okay. */ + + next_lit = 0; + intermediates = 0; + memset (buf, 0, sizeof (buf)); + + this_component.data = buf; + last_component.data = last; + last_component.length = 0; + +#define print_data(fmt,d) Tprintf((fmt,(int)(d)->length,(d)->data)) + print_data ("client realm: %.*s\n", crealm); + print_data ("server realm: %.*s\n", srealm); + print_data ("transit enc.: %.*s\n", transit); + + if (transit->length == 0) { + Tprintf (("no other realms transited\n")); + return 0; + } + + bufp = buf; + for (p = transit->data, l = transit->length; l; p++, l--) { + if (next_lit) { + *bufp++ = *p; + if (bufp == buf+sizeof(buf)) + return KRB5KRB_AP_ERR_ILL_CR_TKT; + next_lit = 0; + } else if (*p == '\\') { + next_lit = 1; + } else if (*p == ',') { + if (bufp != buf) { + this_component.length = bufp - buf; + r = maybe_join (&last_component, &this_component, sizeof(buf)); + if (r) + return r; + r = (*fn) (&this_component, data); + if (r) + return r; + if (intermediates) { + if (p == transit->data) + r = process_intermediates (fn, data, + &this_component, crealm); + else { + r = process_intermediates (fn, data, &this_component, + &last_component); + } + if (r) + return r; + } + intermediates = 0; + memcpy (last, buf, sizeof (buf)); + last_component.length = this_component.length; + memset (buf, 0, sizeof (buf)); + bufp = buf; + } else { + intermediates = 1; + if (p == transit->data) { + if (crealm->length >= MAXLEN) + return KRB5KRB_AP_ERR_ILL_CR_TKT; + memcpy (last, crealm->data, crealm->length); + last[crealm->length] = '\0'; + last_component.length = crealm->length; + } + } + } else if (*p == ' ' && bufp == buf) { + /* This next component stands alone, even if it has a + trailing dot or leading slash. */ + memset (last, 0, sizeof (last)); + last_component.length = 0; + } else { + /* Not a special character; literal. */ + *bufp++ = *p; + if (bufp == buf+sizeof(buf)) + return KRB5KRB_AP_ERR_ILL_CR_TKT; + } + } + /* At end. Must be normal state. */ + if (next_lit) + Tprintf (("ending in next-char-literal state\n")); + /* Process trailing element or comma. */ + if (bufp == buf) { + /* Trailing comma. */ + r = process_intermediates (fn, data, &last_component, srealm); + } else { + /* Trailing component. */ + this_component.length = bufp - buf; + r = maybe_join (&last_component, &this_component, sizeof(buf)); + if (r) + return r; + r = (*fn) (&this_component, data); + if (r) + return r; + if (intermediates) + r = process_intermediates (fn, data, &this_component, + &last_component); + } + if (r != 0) + return r; + return 0; +} + + +struct check_data { + krb5_context ctx; + krb5_principal *tgs; +}; + +static int +same_data (krb5_data *d1, krb5_data *d2) { - char prev[MAX_REALM_LN+1]; - char next[MAX_REALM_LN+1]; - char *nextp; - int i, j; - int trans_length; - krb5_error_code retval = 0; - krb5_principal *tgs_list; - - if (trans == NULL || trans->data == NULL || trans->length == 0) - return(0); - trans_length = trans->data[trans->length-1] ? - trans->length : trans->length - 1; - - for (i = 0; i < trans_length; i++) - if (trans->data[i] == '\0') { - /* Realms may not contain ASCII NUL character. */ - return(KRB5KRB_AP_ERR_ILL_CR_TKT); + return (d1->length == d2->length + && !memcmp (d1->data, d2->data, d1->length)); +} + +static krb5_error_code +check_realm_in_list (krb5_data *realm, void *data) +{ + struct check_data *cdata = data; + int i; + + Tprintf ((".. checking '%.*s'\n", (int) realm->length, realm->data)); + for (i = 0; cdata->tgs[i]; i++) { + if (same_data (krb5_princ_realm (cdata->ctx, cdata->tgs[i]), realm)) + return 0; } + Tprintf (("BAD!\n")); + return KRB5KRB_AP_ERR_ILL_CR_TKT; +} + +krb5_error_code +krb5_check_transited_list (krb5_context ctx, const krb5_data *trans_in, + const krb5_data *crealm, const krb5_data *srealm) +{ + krb5_data trans; + struct check_data cdata; + krb5_error_code r; - if ((retval = krb5_walk_realm_tree(context, realm1, realm2, &tgs_list, - KRB5_REALM_BRANCH_CHAR))) { - return(retval); - } - - memset(prev, 0, MAX_REALM_LN + 1); - memset(next, 0, MAX_REALM_LN + 1), nextp = next; - for (i = 0; i < trans_length; i++) { - if (i < trans_length-1 && trans->data[i] == '\\') { - i++; - *nextp++ = trans->data[i]; - if (nextp - next > MAX_REALM_LN) { - retval = KRB5KRB_AP_ERR_ILL_CR_TKT; - goto finish; - } - continue; + trans.length = trans_in->length; + trans.data = (char *) trans_in->data; + if (trans.length && (trans.data[trans.length-1] == '\0')) + trans.length--; + + Tprintf (("krb5_check_transited_list(trans=\"%.*s\", crealm=\"%.*s\", srealm=\"%.*s\")\n", + (int) trans.length, trans.data, + (int) crealm->length, crealm->data, + (int) srealm->length, srealm->data)); + if (trans.length == 0) + return 0; + r = krb5_walk_realm_tree (ctx, crealm, srealm, &cdata.tgs, + KRB5_REALM_BRANCH_CHAR); + if (r) { + Tprintf (("error %ld\n", (long) r)); + return r; + } +#ifdef DEBUG /* avoid compiler warning about 'd' unused */ + { + int i; + Tprintf (("tgs list = {\n")); + for (i = 0; cdata.tgs[i]; i++) { + char *name; + r = krb5_unparse_name (ctx, cdata.tgs[i], &name); + Tprintf (("\t'%s'\n", name)); + free (name); + } + Tprintf (("}\n")); } - if (i < trans_length && trans->data[i] != ',') { - *nextp++ = trans->data[i]; - if (nextp - next > MAX_REALM_LN) { - retval = KRB5KRB_AP_ERR_ILL_CR_TKT; - goto finish; - } - continue; +#endif + cdata.ctx = ctx; + r = foreach_realm (check_realm_in_list, &cdata, crealm, srealm, &trans); + krb5_free_realm_tree (ctx, cdata.tgs); + return r; +} + +#ifdef TEST + +static krb5_error_code +print_a_realm (krb5_data *realm, void *data) +{ + printf ("%.*s\n", (int) realm->length, realm->data); + return 0; +} + +int main (int argc, char *argv[]) { + const char *me; + krb5_data crealm, srealm, transit; + krb5_error_code r; + int expand_only = 0; + + me = strrchr (argv[0], '/'); + me = me ? me+1 : argv[0]; + + while (argc > 3 && argv[1][0] == '-') { + if (!strcmp ("-v", argv[1])) + verbose++, argc--, argv++; + else if (!strcmp ("-x", argv[1])) + expand_only++, argc--, argv++; + else + goto usage; } - if (strlen(next) > 0) { - if (next[0] != '/') { - if (*(nextp-1) == '.' && strlen(next) + strlen(prev) <= MAX_REALM_LN) - strcat(next, prev); - retval = KRB5KRB_AP_ERR_ILL_CR_TKT; - for (j = 0; tgs_list[j]; j++) { - if (strlen(next) == (size_t) krb5_princ_realm(context, tgs_list[j])->length && - !memcmp(next, krb5_princ_realm(context, tgs_list[j])->data, - strlen(next))) { - retval = 0; - break; - } - } - if (retval) goto finish; - } - if (i+1 < trans_length && trans->data[i+1] == ' ') { - i++; - memset(next, 0, MAX_REALM_LN + 1), nextp = next; - continue; - } - if (i+1 < trans_length && trans->data[i+1] != '/') { - strcpy(prev, next); - memset(next, 0, MAX_REALM_LN + 1), nextp = next; - continue; - } + + if (argc != 4) { + usage: + printf ("usage: %s [-v] [-x] clientRealm serverRealm transitEncoding\n", + me); + return 1; } - } -finish: - krb5_free_realm_tree(context, tgs_list); - return(retval); + crealm.data = argv[1]; + crealm.length = strlen(argv[1]); + srealm.data = argv[2]; + srealm.length = strlen(argv[2]); + transit.data = argv[3]; + transit.length = strlen(argv[3]); + + if (expand_only) { + + printf ("client realm: %s\n", argv[1]); + printf ("server realm: %s\n", argv[2]); + printf ("transit enc.: %s\n", argv[3]); + + if (argv[3][0] == 0) { + printf ("no other realms transited\n"); + return 0; + } + + r = foreach_realm (print_a_realm, NULL, &crealm, &srealm, &transit); + if (r) + printf ("--> returned error %ld\n", (long) r); + return r != 0; + + } else { + + /* Actually check the values against the supplied krb5.conf file. */ + krb5_context ctx; + r = krb5_init_context (&ctx); + if (r) { + com_err (me, r, "initializing krb5 context"); + return 1; + } + r = krb5_check_transited_list (ctx, &transit, &crealm, &srealm); + if (r == KRB5KRB_AP_ERR_ILL_CR_TKT) { + printf ("NO\n"); + } else if (r == 0) { + printf ("YES\n"); + } else { + printf ("kablooey!\n"); + com_err (me, r, "checking transited-realm list"); + return 1; + } + return 0; + } } + +#endif /* TEST */ diff --git a/src/lib/krb5/krb/conv_princ.c b/src/lib/krb5/krb/conv_princ.c index b90289a..e7aab77 100644 --- a/src/lib/krb5/krb/conv_princ.c +++ b/src/lib/krb5/krb/conv_princ.c @@ -137,7 +137,8 @@ krb5_524_conv_principal(context, princ, name, inst, realm) { const struct krb_convert *p; krb5_data *compo; - char *c; + char *c, *tmp_realm, *tmp_prealm; + int tmp_realm_len, retval; *name = *inst = '\0'; switch (krb5_princ_size(context, princ)) { @@ -146,19 +147,24 @@ krb5_524_conv_principal(context, princ, name, inst, realm) compo = krb5_princ_component(context, princ, 0); p = sconv_list; while (p->v4_str) { - if (strncmp(p->v5_str, compo->data, compo->length) == 0) { - /* It is, so set the new name now, and chop off */ - /* instance's domain name if requested */ - strcpy(name, p->v4_str); - if (p->flags & DO_REALM_CONVERSION) { - compo = krb5_princ_component(context, princ, 1); - c = strnchr(compo->data, '.', compo->length); - if (!c || (c - compo->data) > INST_SZ - 1) - return KRB5_INVALID_PRINCIPAL; - strncpy(inst, compo->data, c - compo->data); - inst[c - compo->data] = '\0'; - } - break; + if (strncmp(p->v5_str, compo->data, compo->length) == 0 && + strlen(p->v5_str) == compo->length) { + /* + * It is, so set the new name now, and chop off + * instance's domain name if requested. + */ + if (strlen (p->v4_str) > ANAME_SZ - 1) + return KRB5_INVALID_PRINCIPAL; + strcpy(name, p->v4_str); + if (p->flags & DO_REALM_CONVERSION) { + compo = krb5_princ_component(context, princ, 1); + c = strnchr(compo->data, '.', compo->length); + if (!c || (c - compo->data) >= INST_SZ - 1) + return KRB5_INVALID_PRINCIPAL; + memcpy(inst, compo->data, c - compo->data); + inst[c - compo->data] = '\0'; + } + break; } p++; } @@ -168,7 +174,7 @@ krb5_524_conv_principal(context, princ, name, inst, realm) compo = krb5_princ_component(context, princ, 1); if (compo->length >= INST_SZ - 1) return KRB5_INVALID_PRINCIPAL; - strncpy(inst, compo->data, compo->length); + memcpy(inst, compo->data, compo->length); inst[compo->length] = '\0'; } /* fall through */ @@ -178,7 +184,7 @@ krb5_524_conv_principal(context, princ, name, inst, realm) compo = krb5_princ_component(context, princ, 0); if (compo->length >= ANAME_SZ) return KRB5_INVALID_PRINCIPAL; - strncpy(name, compo->data, compo->length); + memcpy(name, compo->data, compo->length); name[compo->length] = '\0'; } break; @@ -187,11 +193,39 @@ krb5_524_conv_principal(context, princ, name, inst, realm) } compo = krb5_princ_realm(context, princ); - if (compo->length > REALM_SZ - 1) - return KRB5_INVALID_PRINCIPAL; - strncpy(realm, compo->data, compo->length); - realm[compo->length] = '\0'; + tmp_prealm = malloc(compo->length + 1); + if (tmp_prealm == NULL) + return ENOMEM; + strncpy(tmp_prealm, compo->data, compo->length); + tmp_prealm[compo->length] = '\0'; + + /* Ask for v4_realm corresponding to + krb5 principal realm from krb5.conf realms stanza */ + + if (context->profile == 0) + return KRB5_CONFIG_CANTOPEN; + retval = profile_get_string(context->profile, "realms", + tmp_prealm, "v4_realm", 0, + &tmp_realm); + free(tmp_prealm); + if (retval) { + return retval; + } else { + if (tmp_realm == 0) { + if (compo->length > REALM_SZ - 1) + return KRB5_INVALID_PRINCIPAL; + strncpy(realm, compo->data, compo->length); + realm[compo->length] = '\0'; + } else { + tmp_realm_len = strlen(tmp_realm); + if (tmp_realm_len > REALM_SZ - 1) + return KRB5_INVALID_PRINCIPAL; + strncpy(realm, tmp_realm, tmp_realm_len); + realm[tmp_realm_len] = '\0'; + profile_release_string(tmp_realm); + } + } return 0; } @@ -207,8 +241,47 @@ krb5_425_conv_principal(context, name, instance, realm, princ) char buf[256]; /* V4 instances are limited to 40 characters */ krb5_error_code retval; char *domain, *cp; - char **full_name = 0, **cpp; + char **full_name = 0; const char *names[5]; + void* iterator = NULL; + char** v4realms = NULL; + char* realm_name = NULL; + char* dummy_value = NULL; + + /* First, convert the realm, since the v4 realm is not necessarily the same as the v5 realm + To do that, iterate over all the realms in the config file, looking for a matching + v4_realm line */ + names [0] = "realms"; + names [1] = NULL; + retval = profile_iterator_create (context -> profile, names, PROFILE_ITER_LIST_SECTION | PROFILE_ITER_SECTIONS_ONLY, &iterator); + while (retval == 0) { + retval = profile_iterator (&iterator, &realm_name, &dummy_value); + if ((retval == 0) && (realm_name != NULL)) { + names [0] = "realms"; + names [1] = realm_name; + names [2] = "v4_realm"; + names [3] = NULL; + + retval = profile_get_values (context -> profile, names, &v4realms); + if ((retval == 0) && (v4realms != NULL) && (v4realms [0] != NULL) && (strcmp (v4realms [0], realm) == 0)) { + realm = realm_name; + break; + } else if (retval == PROF_NO_RELATION) { + /* If it's not found, just keep going */ + retval = 0; + } + } else if ((retval == 0) && (realm_name == NULL)) { + break; + } + if (realm_name != NULL) { + profile_release_string (realm_name); + realm_name = NULL; + } + if (dummy_value != NULL) { + profile_release_string (dummy_value); + dummy_value = NULL; + } + } if (instance) { if (instance[0] == '\0') { @@ -234,7 +307,8 @@ krb5_425_conv_principal(context, name, instance, realm, princ) if (retval == 0 && full_name && full_name[0]) { instance = full_name[0]; } else { - strcpy(buf, instance); + strncpy(buf, instance, sizeof(buf)); + buf[sizeof(buf) - 1] = '\0'; retval = krb5_get_realm_domain(context, realm, &domain); if (retval) return retval; @@ -242,8 +316,8 @@ krb5_425_conv_principal(context, name, instance, realm, princ) for (cp = domain; *cp; cp++) if (isupper(*cp)) *cp = tolower(*cp); - strcat(buf, "."); - strcat(buf, domain); + strncat(buf, ".", sizeof(buf) - 1 - strlen(buf)); + strncat(buf, domain, sizeof(buf) - 1 - strlen(buf)); krb5_xfree(domain); } instance = buf; @@ -254,6 +328,10 @@ krb5_425_conv_principal(context, name, instance, realm, princ) not_service: retval = krb5_build_principal(context, princ, strlen(realm), realm, name, instance, 0); + profile_iterator_free (&iterator); profile_free_list(full_name); + profile_free_list(v4realms); + profile_release_string (realm_name); + profile_release_string (dummy_value); return retval; } diff --git a/src/lib/krb5/krb/fwd_tgt.c b/src/lib/krb5/krb/fwd_tgt.c index 814195a..2e2c5db 100644 --- a/src/lib/krb5/krb/fwd_tgt.c +++ b/src/lib/krb5/krb/fwd_tgt.c @@ -53,6 +53,8 @@ krb5_fwd_tgt_creds(context, auth_context, rhost, client, server, cc, krb5_flags kdcoptions; int close_cc = 0; int free_rhost = 0; + krb5_enctype enctype = 0; + krb5_keyblock *session_key; memset((char *)&creds, 0, sizeof(creds)); memset((char *)&tgt, 0, sizeof(creds)); @@ -71,7 +73,36 @@ krb5_fwd_tgt_creds(context, auth_context, rhost, client, server, cc, memcpy(rhost, server->data[1].data, server->data[1].length); rhost[server->data[1].length] = '\0'; } - + retval = krb5_auth_con_getkey (context, auth_context, &session_key); + if (retval) + goto errout; + if (session_key) { + enctype = session_key->enctype; + krb5_free_keyblock (context, session_key); + session_key = NULL; + } else if (server) { /* must server be non-NULL when rhost is given? */ + /* Try getting credentials to see what the remote side supports. + Not bulletproof, just a heuristic. */ + krb5_creds in, *out = 0; + memset (&in, 0, sizeof(in)); + + retval = krb5_copy_principal (context, server, &in.server); + if (retval) + goto punt; + retval = krb5_copy_principal (context, client, &in.client); + if (retval) + goto punt; + retval = krb5_get_credentials (context, 0, cc, &in, &out); + if (retval) + goto punt; + /* Got the credentials. Okay, now record the enctype and + throw them away. */ + enctype = out->keyblock.enctype; + krb5_free_creds (context, out); + punt: + krb5_free_cred_contents (context, &in); + } + retval = krb5_os_hostaddr(context, rhost, &addrs); if (retval) goto errout; @@ -90,7 +121,7 @@ krb5_fwd_tgt_creds(context, auth_context, rhost, client, server, cc, goto errout; if (cc == 0) { - if ((retval = krb5_cc_default(context, &cc))) + if ((retval = krb5int_cc_default(context, &cc))) goto errout; close_cc = 1; } @@ -111,7 +142,8 @@ krb5_fwd_tgt_creds(context, auth_context, rhost, client, server, cc, retval = KRB5_NO_TKT_SUPPLIED; goto errout; } - + + creds.keyblock.enctype = enctype; creds.times = tgt.times; creds.times.starttime = 0; kdcoptions = flags2options(tgt.ticket_flags)|KDC_OPT_FORWARDED; diff --git a/src/lib/krb5/krb/get_creds.c b/src/lib/krb5/krb/get_creds.c index 3bcaa0b..de8d29f 100644 --- a/src/lib/krb5/krb/get_creds.c +++ b/src/lib/krb5/krb/get_creds.c @@ -102,6 +102,7 @@ krb5_get_credentials(context, options, ccache, in_creds, out_creds) krb5_creds *ncreds; krb5_creds **tgts; krb5_flags fields; + int not_ktype; retval = krb5_get_credentials_core(context, options, ccache, in_creds, out_creds, @@ -128,6 +129,11 @@ krb5_get_credentials(context, options, ccache, in_creds, out_creds) || options & KRB5_GC_CACHED) return retval; + if (retval == KRB5_CC_NOT_KTYPE) + not_ktype = 1; + else + not_ktype = 0; + retval = krb5_get_cred_from_kdc(context, ccache, ncreds, out_creds, &tgts); if (tgts) { register int i = 0; @@ -141,6 +147,21 @@ krb5_get_credentials(context, options, ccache, in_creds, out_creds) } krb5_free_tgt_creds(context, tgts); } + /* + * Translate KRB5_CC_NOTFOUND if we previously got + * KRB5_CC_NOT_KTYPE from krb5_cc_retrieve_cred(), in order to + * handle the case where there is no TGT in the ccache and the + * input enctype didn't match. This handling is necessary because + * some callers, such as GSSAPI, iterate through enctypes and + * KRB5_CC_NOTFOUND passed through from the + * krb5_get_cred_from_kdc() is semantically incorrect, since the + * actual failure was the non-existence of a ticket of the correct + * enctype rather than the missing TGT. + */ + if ((retval == KRB5_CC_NOTFOUND || retval == KRB5_CC_NOT_KTYPE) + && not_ktype) + retval = KRB5_CC_NOT_KTYPE; + if (!retval) retval = krb5_cc_store_cred(context, ccache, *out_creds); return retval; @@ -160,10 +181,8 @@ krb5_get_credentials_val_renew_core(context, options, ccache, int which; { krb5_error_code retval; - krb5_creds mcreds; krb5_principal tmp; krb5_creds **tgts = 0; - krb5_flags fields; switch(which) { case INT_GC_VALIDATE: diff --git a/src/lib/krb5/krb/get_in_tkt.c b/src/lib/krb5/krb/get_in_tkt.c index c1c6df1..57d0313 100644 --- a/src/lib/krb5/krb/get_in_tkt.c +++ b/src/lib/krb5/krb/get_in_tkt.c @@ -84,13 +84,13 @@ static krb5_error_code make_preauth_list PROTOTYPE((krb5_context, */ static krb5_error_code send_as_request(context, request, time_now, ret_err_reply, ret_as_reply, - master) + use_master) krb5_context context; krb5_kdc_req *request; krb5_timestamp *time_now; krb5_error ** ret_err_reply; krb5_kdc_rep ** ret_as_reply; - int * master; + int use_master; { krb5_kdc_rep *as_reply = 0; krb5_error_code retval; @@ -116,7 +116,7 @@ send_as_request(context, request, time_now, ret_err_reply, ret_as_reply, k4_version = packet->data[0]; retval = krb5_sendto_kdc(context, packet, krb5_princ_realm(context, request->client), - &reply, master); + &reply, use_master); krb5_free_data(context, packet); if (retval) goto cleanup; @@ -367,7 +367,6 @@ make_preauth_list(context, ptypes, nptypes, ret_list) { krb5_preauthtype * ptypep; krb5_pa_data ** preauthp; - krb5_pa_data ** preauth_to_use; int i; if (nptypes < 0) { @@ -457,12 +456,35 @@ krb5_get_in_tkt(context, options, addrs, ktypes, ptypes, key_proc, keyseed, request.from = creds->times.starttime; request.till = creds->times.endtime; request.rtime = creds->times.renew_till; - if (ktypes) - request.ktype = ktypes; - else - if ((retval = krb5_get_default_in_tkt_ktypes(context, &request.ktype))) - goto cleanup; + if ((retval = krb5_get_default_in_tkt_ktypes(context, &request.ktype))) + goto cleanup; for (request.nktypes = 0;request.ktype[request.nktypes];request.nktypes++); + if (ktypes) { + int i, req, next = 0; + for (req = 0; ktypes[req]; req++) { + if (ktypes[req] == request.ktype[next]) { + next++; + continue; + } + for (i = next + 1; i < request.nktypes; i++) + if (ktypes[req] == request.ktype[i]) { + /* Found the enctype we want, but not in the + position we want. Move it, but keep the old + one from the desired slot around in case it's + later in our requested-ktypes list. */ + krb5_enctype t; + t = request.ktype[next]; + request.ktype[next] = request.ktype[i]; + request.ktype[i] = t; + next++; + break; + } + /* If we didn't find it, don't do anything special, just + drop it. */ + } + request.ktype[next] = 0; + request.nktypes = next; + } request.authorization_data.ciphertext.length = 0; request.authorization_data.ciphertext.data = 0; request.unenc_authdata = 0; @@ -538,7 +560,7 @@ krb5_get_in_tkt(context, options, addrs, ktypes, ptypes, key_proc, keyseed, goto cleanup; cleanup: - if (!ktypes && request.ktype) + if (request.ktype) free(request.ktype); if (!addrs && request.addresses) krb5_free_addresses(context, request.addresses); @@ -559,17 +581,17 @@ cleanup: return (retval); } -/* begin appdefaults parsing code. This should almost certainly move +/* begin libdefaults parsing code. This should almost certainly move somewhere else, but I don't know where the correct somewhere else is yet. */ /* XXX Duplicating this is annoying; try to work on a better way.*/ -static char *conf_yes[] = { +static const char *conf_yes[] = { "y", "yes", "true", "t", "1", "on", 0, }; -static char *conf_no[] = { +static const char *conf_no[] = { "n", "no", "false", "nil", "0", "off", 0, }; @@ -595,7 +617,7 @@ _krb5_conf_boolean(s) } static krb5_error_code -krb5_appdefault_string(context, realm, option, ret_value) +krb5_libdefault_string(context, realm, option, ret_value) krb5_context context; const krb5_data *realm; const char *option; @@ -606,7 +628,6 @@ krb5_appdefault_string(context, realm, option, ret_value) char **nameval = NULL; krb5_error_code retval; char realmstr[1024]; - char **cpp; if (realm->length > sizeof(realmstr)-1) return(EINVAL); @@ -673,7 +694,7 @@ goodbye: /* as well as the DNS code */ krb5_error_code -krb5_appdefault_boolean(context, realm, option, ret_value) +krb5_libdefault_boolean(context, realm, option, ret_value) krb5_context context; const char *option; const krb5_data *realm; @@ -682,7 +703,7 @@ krb5_appdefault_boolean(context, realm, option, ret_value) char *string = NULL; krb5_error_code retval; - retval = krb5_appdefault_string(context, realm, option, &string); + retval = krb5_libdefault_string(context, realm, option, &string); if (retval) return(retval); @@ -696,7 +717,7 @@ krb5_appdefault_boolean(context, realm, option, ret_value) KRB5_DLLIMP krb5_error_code KRB5_CALLCONV krb5_get_init_creds(context, creds, client, prompter, prompter_data, start_time, in_tkt_service, options, gak_fct, gak_data, - master, as_reply) + use_master, as_reply) krb5_context context; krb5_creds *creds; krb5_principal client; @@ -707,7 +728,7 @@ krb5_get_init_creds(context, creds, client, prompter, prompter_data, krb5_get_init_creds_opt *options; krb5_gic_get_as_key_fct gak_fct; void *gak_data; - int *master; + int use_master; krb5_kdc_rep **as_reply; { krb5_error_code ret; @@ -751,7 +772,7 @@ krb5_get_init_creds(context, creds, client, prompter, prompter_data, if (options && (options->flags & KRB5_GET_INIT_CREDS_OPT_FORWARDABLE)) tempint = options->forwardable; - else if ((ret = krb5_appdefault_boolean(context, &client->realm, + else if ((ret = krb5_libdefault_boolean(context, &client->realm, "forwardable", &tempint)) == 0) ; else @@ -763,7 +784,7 @@ krb5_get_init_creds(context, creds, client, prompter, prompter_data, if (options && (options->flags & KRB5_GET_INIT_CREDS_OPT_PROXIABLE)) tempint = options->proxiable; - else if ((ret = krb5_appdefault_boolean(context, &client->realm, + else if ((ret = krb5_libdefault_boolean(context, &client->realm, "proxiable", &tempint)) == 0) ; else @@ -775,7 +796,7 @@ krb5_get_init_creds(context, creds, client, prompter, prompter_data, if (options && (options->flags & KRB5_GET_INIT_CREDS_OPT_RENEW_LIFE)) { renew_life = options->renew_life; - } else if ((ret = krb5_appdefault_string(context, &client->realm, + } else if ((ret = krb5_libdefault_string(context, &client->realm, "renew_lifetime", &tempstr)) == 0) { if (ret = krb5_string_to_deltat(tempstr, &renew_life)) { @@ -868,7 +889,7 @@ krb5_get_init_creds(context, creds, client, prompter, prompter_data, } /* it would be nice if this parsed out an address list, but that would be work. */ - else if (((ret = krb5_appdefault_boolean(context, &client->realm, + else if (((ret = krb5_libdefault_boolean(context, &client->realm, "noaddresses", &tempint)) == 0) && tempint) { ; @@ -923,7 +944,7 @@ krb5_get_init_creds(context, creds, client, prompter, prompter_data, err_reply = 0; local_as_reply = 0; if ((ret = send_as_request(context, &request, &time_now, &err_reply, - &local_as_reply, master))) + &local_as_reply, use_master))) goto cleanup; if (err_reply) { diff --git a/src/lib/krb5/krb/gic_keytab.c b/src/lib/krb5/krb/gic_keytab.c index 8b6f231..98bbbd0 100644 --- a/src/lib/krb5/krb/gic_keytab.c +++ b/src/lib/krb5/krb/gic_keytab.c @@ -61,7 +61,7 @@ krb5_get_init_creds_keytab(context, creds, client, arg_keytab, krb5_get_init_creds_opt *options; { krb5_error_code ret, ret2; - int master; + int use_master; krb5_keytab keytab; if (arg_keytab == NULL) { @@ -71,14 +71,14 @@ krb5_get_init_creds_keytab(context, creds, client, arg_keytab, keytab = arg_keytab; } - master = 0; + use_master = 0; /* first try: get the requested tkt from any kdc */ ret = krb5_get_init_creds(context, creds, client, NULL, NULL, start_time, in_tkt_service, options, krb5_get_as_key_keytab, (void *) keytab, - &master, NULL); + use_master,NULL); /* check for success */ @@ -87,19 +87,19 @@ krb5_get_init_creds_keytab(context, creds, client, arg_keytab, /* If all the kdc's are unavailable fail */ - if (ret == KRB5_KDC_UNREACH) + if ((ret == KRB5_KDC_UNREACH) || (ret == KRB5_REALM_CANT_RESOLVE)) goto cleanup; /* if the reply did not come from the master kdc, try again with the master kdc */ - if (!master) { - master = 1; + if (!use_master) { + use_master = 1; ret2 = krb5_get_init_creds(context, creds, client, NULL, NULL, start_time, in_tkt_service, options, krb5_get_as_key_keytab, (void *) keytab, - &master, NULL); + use_master, NULL); if (ret2 == 0) { ret = 0; @@ -109,7 +109,7 @@ krb5_get_init_creds_keytab(context, creds, client, arg_keytab, /* if the master is unreachable, return the error from the slave we were able to contact */ - if (ret2 == KRB5_KDC_UNREACH) + if ((ret2 == KRB5_KDC_UNREACH) || (ret == KRB5_REALM_CANT_RESOLVE)) goto cleanup; ret = ret2; diff --git a/src/lib/krb5/krb/gic_pwd.c b/src/lib/krb5/krb/gic_pwd.c index 7ca4343..f867989 100644 --- a/src/lib/krb5/krb/gic_pwd.c +++ b/src/lib/krb5/krb/gic_pwd.c @@ -1,5 +1,4 @@ #include "k5-int.h" -#include "com_err.h" static krb5_error_code krb5_get_as_key_password(context, client, etype, prompter, prompter_data, @@ -97,7 +96,7 @@ krb5_get_init_creds_password(context, creds, client, password, prompter, data, krb5_get_init_creds_opt *options; { krb5_error_code ret, ret2; - int master; + int use_master; krb5_kdc_rep *as_reply; int tries; krb5_creds chpw_creds; @@ -107,7 +106,7 @@ krb5_get_init_creds_password(context, creds, client, password, prompter, data, krb5_prompt prompt[2]; krb5_prompt_type prompt_types[sizeof(prompt)/sizeof(prompt[0])]; - master = 0; + use_master = 0; as_reply = NULL; memset(&chpw_creds, 0, sizeof(chpw_creds)); @@ -133,7 +132,7 @@ krb5_get_init_creds_password(context, creds, client, password, prompter, data, ret = krb5_get_init_creds(context, creds, client, prompter, data, start_time, in_tkt_service, options, krb5_get_as_key_password, (void *) &pw0, - &master, &as_reply); + use_master, &as_reply); /* check for success */ @@ -144,19 +143,20 @@ krb5_get_init_creds_password(context, creds, client, password, prompter, data, user interrupt, fail */ if ((ret == KRB5_KDC_UNREACH) || - (ret == KRB5_LIBOS_PWDINTR)) + (ret == KRB5_LIBOS_PWDINTR) || + (ret == KRB5_REALM_CANT_RESOLVE)) goto cleanup; /* if the reply did not come from the master kdc, try again with the master kdc */ - if (!master) { - master = 1; + if (!use_master) { + use_master = 1; ret2 = krb5_get_init_creds(context, creds, client, prompter, data, start_time, in_tkt_service, options, krb5_get_as_key_password, (void *) &pw0, - &master, &as_reply); + use_master, &as_reply); if (ret2 == 0) { ret = 0; @@ -166,12 +166,18 @@ krb5_get_init_creds_password(context, creds, client, password, prompter, data, /* if the master is unreachable, return the error from the slave we were able to contact */ - if (ret2 == KRB5_KDC_UNREACH) + if ((ret2 == KRB5_KDC_UNREACH) || + (ret2 == KRB5_REALM_CANT_RESOLVE)) goto cleanup; ret = ret2; } +#ifdef USE_LOGIN_LIBRARY + if (ret == KRB5KDC_ERR_KEY_EXP) + goto cleanup; /* Login library will deal appropriately with this error */ +#endif + /* at this point, we have an error from the master. if the error is not password expired, or if it is but there's no prompter, return this error */ @@ -195,7 +201,7 @@ krb5_get_init_creds_password(context, creds, client, password, prompter, data, prompter, data, start_time, "kadmin/changepw", &chpw_opts, krb5_get_as_key_password, (void *) &pw0, - &master, NULL))) + use_master, NULL))) goto cleanup; prompt[0].prompt = "Enter new password"; @@ -282,7 +288,7 @@ krb5_get_init_creds_password(context, creds, client, password, prompter, data, ret = krb5_get_init_creds(context, creds, client, prompter, data, start_time, in_tkt_service, options, krb5_get_as_key_password, (void *) &pw0, - &master, &as_reply); + use_master, &as_reply); cleanup: krb5int_set_prompt_types(context, 0); diff --git a/src/lib/krb5/krb/init_ctx.c b/src/lib/krb5/krb/init_ctx.c index e2eccc4..abcb573 100644 --- a/src/lib/krb5/krb/init_ctx.c +++ b/src/lib/krb5/krb/init_ctx.c @@ -1,7 +1,7 @@ /* * lib/krb5/krb/init_ctx.c * - * Copyright 1994 by the Massachusetts Institute of Technology. + * Copyright 1994,1999,2000 by the Massachusetts Institute of Technology. * All Rights Reserved. * * Export of this software from the United States of America may @@ -84,7 +84,10 @@ init_common (context, secure) { krb5_context ctx = 0; krb5_error_code retval; - krb5_timestamp now; + struct { + krb5_int32 now, now_usec; + long pid; + } seed_data; krb5_data seed; int tmp; @@ -129,10 +132,11 @@ init_common (context, secure) goto cleanup; /* initialize the prng (not well, but passable) */ - if ((retval = krb5_timeofday(ctx, &now))) + if ((retval = krb5_crypto_us_timeofday(&seed_data.now, &seed_data.now_usec))) goto cleanup; - seed.length = sizeof(now); - seed.data = (char *) &now; + seed_data.pid = getpid (); + seed.length = sizeof(seed_data); + seed.data = (char *) &seed_data; if ((retval = krb5_c_random_seed(ctx, &seed))) goto cleanup; @@ -169,7 +173,7 @@ init_common (context, secure) "kdc_default_options", 0, KDC_OPT_RENEWABLE_OK, &tmp); ctx->kdc_default_options = KDC_OPT_RENEWABLE_OK; -#ifdef macintosh +#if TARGET_OS_MAC #define DEFAULT_KDC_TIMESYNC 1 #else #define DEFAULT_KDC_TIMESYNC 0 @@ -187,7 +191,7 @@ init_common (context, secure) * Note: DCE 1.0.3a only supports a cache type of 1 * DCE 1.1 supports a cache type of 2. */ -#ifdef macintosh +#if TARGET_OS_MAC #define DEFAULT_CCACHE_TYPE 4 #else #define DEFAULT_CCACHE_TYPE 3 @@ -281,7 +285,7 @@ get_profile_etype_list(context, ktypes, profstr, ctx_count, ctx_list) { krb5_enctype *old_ktypes; - if (context->in_tkt_ktype_count) { + if (ctx_count) { /* application-set defaults */ if ((old_ktypes = (krb5_enctype *)malloc(sizeof(krb5_enctype) * @@ -370,8 +374,8 @@ krb5_get_default_in_tkt_ktypes(context, ktypes) context->in_tkt_ktypes)); } -krb5_error_code -krb5_set_default_tgs_ktypes(context, ktypes) +krb5_error_code KRB5_CALLCONV +krb5_set_default_tgs_enctypes (context, ktypes) krb5_context context; const krb5_enctype *ktypes; { @@ -396,13 +400,30 @@ krb5_set_default_tgs_ktypes(context, ktypes) } if (context->tgs_ktypes) - free(context->tgs_ktypes); + krb5_free_ktypes(context, context->tgs_ktypes); context->tgs_ktypes = new_ktypes; context->tgs_ktype_count = i; return 0; } +krb5_error_code krb5_set_default_tgs_ktypes +(krb5_context context, const krb5_enctype *etypes) +{ + return (krb5_set_default_tgs_enctypes (context, etypes)); +} + + +void +KRB5_CALLCONV +krb5_free_ktypes (context, val) + krb5_context context; + krb5_enctype FAR *val; +{ + free (val); +} + krb5_error_code +KRB5_CALLCONV krb5_get_tgs_ktypes(context, princ, ktypes) krb5_context context; krb5_const_principal princ; @@ -441,7 +462,7 @@ krb5_is_permitted_enctype(context, etype) if (*ptr == etype) ret = 1; - krb5_xfree(list); + krb5_free_ktypes (context, list); return(ret); } diff --git a/src/lib/krb5/krb/init_keyblock.c b/src/lib/krb5/krb/init_keyblock.c new file mode 100644 index 0000000..eb60b06 --- /dev/null +++ b/src/lib/krb5/krb/init_keyblock.c @@ -0,0 +1,61 @@ +/* + * lib/krb5/krb/init_keyblock.c + * + * Copyright (C) 2002 by the Massachusetts Institute of Technology. + * All rights reserved. + * + * Export of this software from the United States of America may + * 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. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * 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. + * + * + * + * krb5_init_keyblock- a function to set up + * an empty keyblock + */ + + +#include "k5-int.h" +#include + +krb5_error_code KRB5_CALLCONV +krb5_init_keyblock(krb5_context context, krb5_enctype enctype, + size_t length, krb5_keyblock **out) +{ + krb5_keyblock *kb; + kb = malloc (sizeof(krb5_keyblock)); + assert (out); + *out = NULL; + if (!kb) { + return ENOMEM; + } + kb->magic = KV5M_KEYBLOCK; + kb->enctype = enctype; + kb->length = length; + if(length) { + kb->contents = malloc (length); + if(!kb->contents) { + free (kb); + return ENOMEM; + } + } else { + kb->contents = NULL; + } + *out = kb; + return 0; +} diff --git a/src/lib/krb5/krb/kfree.c b/src/lib/krb5/krb/kfree.c index 24d8aaf..8e57f83 100644 --- a/src/lib/krb5/krb/kfree.c +++ b/src/lib/krb5/krb/kfree.c @@ -36,7 +36,6 @@ krb5_free_address(context, val) if (val->contents) krb5_xfree(val->contents); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -52,7 +51,6 @@ krb5_free_addresses(context, val) krb5_xfree(*temp); } krb5_xfree(val); - return; } @@ -64,7 +62,6 @@ krb5_free_ap_rep(context, val) if (val->enc_part.ciphertext.data) krb5_xfree(val->enc_part.ciphertext.data); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -77,7 +74,6 @@ krb5_free_ap_req(context, val) if (val->authenticator.ciphertext.data) krb5_xfree(val->authenticator.ciphertext.data); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -88,7 +84,6 @@ krb5_free_ap_rep_enc_part(context, val) if (val->subkey) krb5_free_keyblock(context, val->subkey); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -96,15 +91,22 @@ krb5_free_authenticator_contents(context, val) krb5_context context; krb5_authenticator FAR *val; { - if (val->checksum) + if (val->checksum) { krb5_free_checksum(context, val->checksum); - if (val->client) + val->checksum = 0; + } + if (val->client) { krb5_free_principal(context, val->client); - if (val->subkey) + val->client = 0; + } + if (val->subkey) { krb5_free_keyblock(context, val->subkey); - if (val->authorization_data) - krb5_free_authdata(context, val->authorization_data); - return; + val->subkey = 0; + } + if (val->authorization_data) { + krb5_free_authdata(context, val->authorization_data); + val->authorization_data = 0; + } } KRB5_DLLIMP void KRB5_CALLCONV @@ -120,7 +122,6 @@ krb5_free_authdata(context, val) krb5_xfree(*temp); } krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -128,16 +129,8 @@ krb5_free_authenticator(context, val) krb5_context context; krb5_authenticator FAR *val; { - if (val->checksum) - krb5_free_checksum(context, val->checksum); - if (val->client) - krb5_free_principal(context, val->client); - if (val->subkey) - krb5_free_keyblock(context, val->subkey); - if (val->authorization_data) - krb5_free_authdata(context, val->authorization_data); + krb5_free_authenticator_contents(context, val); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -145,10 +138,8 @@ krb5_free_checksum(context, val) krb5_context context; register krb5_checksum *val; { - if (val->contents) - krb5_xfree(val->contents); + krb5_free_checksum_contents(context, val); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -156,9 +147,10 @@ krb5_free_checksum_contents(context, val) krb5_context context; register krb5_checksum *val; { - if (val->contents) + if (val->contents) { krb5_xfree(val->contents); - return; + val->contents = 0; + } } KRB5_DLLIMP void KRB5_CALLCONV @@ -171,7 +163,6 @@ krb5_free_cred(context, val) if (val->enc_part.ciphertext.data) krb5_xfree(val->enc_part.ciphertext.data); krb5_xfree(val); - return; } /* @@ -184,23 +175,35 @@ krb5_free_cred_contents(context, val) krb5_context context; krb5_creds FAR *val; { - if (val->client) + if (val->client) { krb5_free_principal(context, val->client); - if (val->server) + val->client = 0; + } + if (val->server) { krb5_free_principal(context, val->server); + val->server = 0; + } if (val->keyblock.contents) { memset((char *)val->keyblock.contents, 0, val->keyblock.length); krb5_xfree(val->keyblock.contents); + val->keyblock.contents = 0; } - if (val->ticket.data) + if (val->ticket.data) { krb5_xfree(val->ticket.data); - if (val->second_ticket.data) + val->ticket.data = 0; + } + if (val->second_ticket.data) { krb5_xfree(val->second_ticket.data); - if (val->addresses) + val->second_ticket.data = 0; + } + if (val->addresses) { krb5_free_addresses(context, val->addresses); - if (val->authdata) + val->addresses = 0; + } + if (val->authdata) { krb5_free_authdata(context, val->authdata); - return; + val->authdata = 0; + } } KRB5_DLLIMP void KRB5_CALLCONV @@ -210,10 +213,14 @@ krb5_free_cred_enc_part(context, val) { register krb5_cred_info **temp; - if (val->r_address) - krb5_free_address(context, val->r_address); - if (val->s_address) - krb5_free_address(context, val->s_address); + if (val->r_address) { + krb5_free_address(context, val->r_address); + val->r_address = 0; + } + if (val->s_address) { + krb5_free_address(context, val->s_address); + val->s_address = 0; + } if (val->ticket_info) { for (temp = val->ticket_info; *temp; temp++) { @@ -228,8 +235,8 @@ krb5_free_cred_enc_part(context, val) krb5_xfree((*temp)); } krb5_xfree(val->ticket_info); + val->ticket_info = 0; } - return; } @@ -240,7 +247,6 @@ krb5_free_creds(context, val) { krb5_free_cred_contents(context, val); krb5_xfree(val); - return; } @@ -252,7 +258,6 @@ krb5_free_data(context, val) if (val->data) krb5_xfree(val->data); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -260,9 +265,10 @@ krb5_free_data_contents(context, val) krb5_context context; krb5_data FAR * val; { - if (val->data) + if (val->data) { krb5_xfree(val->data); - return; + val->data = 0; + } } void krb5_free_etype_info(context, info) @@ -294,7 +300,6 @@ krb5_free_enc_kdc_rep_part(context, val) if (val->caddrs) krb5_free_addresses(context, val->caddrs); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -313,7 +318,6 @@ krb5_free_enc_tkt_part(context, val) if (val->authorization_data) krb5_free_authdata(context, val->authorization_data); krb5_xfree(val); - return; } @@ -331,7 +335,6 @@ krb5_free_error(context, val) if (val->e_data.data) krb5_xfree(val->e_data.data); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -350,7 +353,6 @@ krb5_free_kdc_rep(context, val) if (val->enc_part2) krb5_free_enc_kdc_rep_part(context, val->enc_part2); krb5_xfree(val); - return; } @@ -376,7 +378,6 @@ krb5_free_kdc_req(context, val) if (val->second_ticket) krb5_free_tickets(context, val->second_ticket); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -387,8 +388,8 @@ krb5_free_keyblock_contents(context, key) if (key->contents) { memset(key->contents, 0, key->length); krb5_xfree(key->contents); + key->contents = 0; } - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -398,7 +399,6 @@ krb5_free_keyblock(context, val) { krb5_free_keyblock_contents(context, val); krb5_xfree(val); - return; } @@ -413,7 +413,6 @@ krb5_free_last_req(context, val) for (temp = val; *temp; temp++) krb5_xfree(*temp); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -429,7 +428,6 @@ krb5_free_pa_data(context, val) krb5_xfree(*temp); } krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -451,7 +449,6 @@ krb5_free_principal(context, val) if (val->realm.data) krb5_xfree(val->realm.data); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -462,7 +459,6 @@ krb5_free_priv(context, val) if (val->enc_part.ciphertext.data) krb5_xfree(val->enc_part.ciphertext.data); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -477,7 +473,6 @@ krb5_free_priv_enc_part(context, val) if (val->s_address) krb5_free_address(context, val->s_address); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -488,7 +483,6 @@ krb5_free_pwd_data(context, val) if (val->element) krb5_free_pwd_sequences(context, val->element); krb5_xfree(val); - return; } @@ -497,11 +491,14 @@ krb5_free_pwd_sequences(context, val) krb5_context context; passwd_phrase_element FAR * FAR *val; { - if ((*val)->passwd) + if ((*val)->passwd) { krb5_xfree((*val)->passwd); - if ((*val)->phrase) + (*val)->passwd = 0; + } + if ((*val)->phrase) { krb5_xfree((*val)->phrase); - return; + (*val)->phrase = 0; + } } @@ -519,7 +516,6 @@ krb5_free_safe(context, val) if (val->checksum) krb5_free_checksum(context, val->checksum); krb5_xfree(val); - return; } @@ -535,7 +531,6 @@ krb5_free_ticket(context, val) if (val->enc_part2) krb5_free_enc_tkt_part(context, val->enc_part2); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -548,7 +543,6 @@ krb5_free_tickets(context, val) for (temp = val; *temp; temp++) krb5_free_ticket(context, *temp); krb5_xfree(val); - return; } @@ -573,7 +567,6 @@ krb5_free_tkt_authent(context, val) if (val->authenticator) krb5_free_authenticator(context, val->authenticator); krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -583,7 +576,6 @@ krb5_free_unparsed_name(context, val) { if (val) krb5_xfree(val); - return; } KRB5_DLLIMP void KRB5_CALLCONV @@ -612,8 +604,10 @@ krb5_free_sam_challenge_contents(krb5_context ctx, krb5_sam_challenge FAR *sc) krb5_free_data_contents(ctx, &sc->sam_response_prompt); if (sc->sam_pk_for_sad.data) krb5_free_data_contents(ctx, &sc->sam_pk_for_sad); - if (sc->sam_cksum.contents) + if (sc->sam_cksum.contents) { krb5_xfree(sc->sam_cksum.contents); + sc->sam_cksum.contents = 0; + } } KRB5_DLLIMP void KRB5_CALLCONV @@ -656,8 +650,10 @@ krb5_free_predicted_sam_response_contents(krb5_context ctx, return; if (psr->sam_key.contents) krb5_free_keyblock_contents(ctx, &psr->sam_key); - if (psr->client) + if (psr->client) { krb5_free_principal(ctx, psr->client); + psr->client = 0; + } if (psr->msd.data) krb5_free_data_contents(ctx, &psr->msd); } @@ -689,4 +685,3 @@ krb5_free_pa_enc_ts(krb5_context ctx, krb5_pa_enc_ts FAR *pa_enc_ts) return; krb5_xfree(pa_enc_ts); } - diff --git a/src/lib/krb5/krb/mk_cred.c b/src/lib/krb5/krb/mk_cred.c index cdda80d..9bcfe84 100644 --- a/src/lib/krb5/krb/mk_cred.c +++ b/src/lib/krb5/krb/mk_cred.c @@ -7,7 +7,7 @@ * structures. * */ -#include +#include "k5-int.h" #include "cleanup.h" #include "auth_con.h" diff --git a/src/lib/krb5/krb/mk_priv.c b/src/lib/krb5/krb/mk_priv.c index 7685817..d72f6b2 100644 --- a/src/lib/krb5/krb/mk_priv.c +++ b/src/lib/krb5/krb/mk_priv.c @@ -93,14 +93,6 @@ krb5_mk_priv_basic(context, userdata, keyblock, replaydata, local_addr, scratch1, &privmsg.enc_part))) goto clean_encpart; - /* put last block into the i_vector */ - - if (i_vector) - memcpy(i_vector, - privmsg.enc_part.ciphertext.data + - (privmsg.enc_part.ciphertext.length - blocksize), - blocksize); - if ((retval = encode_krb5_priv(&privmsg, &scratch2))) goto clean_encpart; diff --git a/src/lib/krb5/krb/mk_req_ext.c b/src/lib/krb5/krb/mk_req_ext.c index a8b20eb..88daab5 100644 --- a/src/lib/krb5/krb/mk_req_ext.c +++ b/src/lib/krb5/krb/mk_req_ext.c @@ -126,10 +126,24 @@ krb5_mk_req_extended(context, auth_context, ap_req_options, in_data, in_creds, /* generate subkey if needed */ - if ((ap_req_options & AP_OPTS_USE_SUBKEY)&&(!(*auth_context)->local_subkey)) + if ((ap_req_options & AP_OPTS_USE_SUBKEY)&&(!(*auth_context)->local_subkey)) { + /* Provide some more fodder for random number code. + This isn't strong cryptographically; the point here is not + to guarantee randomness, but to make it less likely that multiple + sessions could pick the same subkey. */ + struct { + krb5_int32 sec, usec; + } rnd_data; + krb5_data d; + krb5_crypto_us_timeofday (&rnd_data.sec, &rnd_data.usec); + d.length = sizeof (rnd_data); + d.data = (char *) &rnd_data; + (void) krb5_c_random_seed (context, &d); + if ((retval = krb5_generate_subkey(context, &(in_creds)->keyblock, &(*auth_context)->local_subkey))) goto cleanup; + } if (in_data) { if ((*auth_context)->req_cksumtype == 0x8003) { diff --git a/src/lib/krb5/krb/mk_safe.c b/src/lib/krb5/krb/mk_safe.c index 781e256..dd7d1ef 100644 --- a/src/lib/krb5/krb/mk_safe.c +++ b/src/lib/krb5/krb/mk_safe.c @@ -27,7 +27,7 @@ * krb5_mk_safe() */ -#include +#include "k5-int.h" #include "cleanup.h" #include "auth_con.h" @@ -169,6 +169,7 @@ krb5_mk_safe(context, auth_context, userdata, outbuf, outdata) krb5_address * plocal_fulladdr = NULL; krb5_address remote_fulladdr; krb5_address local_fulladdr; + krb5_cksumtype sumtype; CLEANUP_INIT(2); @@ -204,9 +205,33 @@ krb5_mk_safe(context, auth_context, userdata, outbuf, outdata) } } + { + unsigned int nsumtypes; + unsigned int i; + krb5_cksumtype *sumtypes; + retval = krb5_c_keyed_checksum_types (context, keyblock->enctype, + &nsumtypes, &sumtypes); + if (retval) { + CLEANUP_DONE (); + goto error; + } + if (nsumtypes == 0) { + retval = KRB5_BAD_ENCTYPE; + krb5_free_cksumtypes (context, sumtypes); + CLEANUP_DONE (); + goto error; + } + for (i = 0; i < nsumtypes; i++) + if (auth_context->safe_cksumtype == sumtypes[i]) + break; + if (i == nsumtypes) + i = 0; + sumtype = sumtypes[i]; + krb5_free_cksumtypes (context, sumtypes); + } if ((retval = krb5_mk_safe_basic(context, userdata, keyblock, &replaydata, plocal_fulladdr, premote_fulladdr, - auth_context->safe_cksumtype, outbuf))) { + sumtype, outbuf))) { CLEANUP_DONE(); goto error; } diff --git a/src/lib/krb5/krb/parse.c b/src/lib/krb5/krb/parse.c index b628a0d..3e18aba 100644 --- a/src/lib/krb5/krb/parse.c +++ b/src/lib/krb5/krb/parse.c @@ -71,7 +71,7 @@ krb5_parse_name(context, name, nprincipal) { register const char *cp; register char *q; - register i,c,size; + register int i,c,size; int components = 0; const char *parsed_realm = NULL; int fcompsize[FCOMPNUM]; diff --git a/src/lib/krb5/krb/preauth.c b/src/lib/krb5/krb/preauth.c index 9f301da..173170a 100644 --- a/src/lib/krb5/krb/preauth.c +++ b/src/lib/krb5/krb/preauth.c @@ -32,7 +32,6 @@ #include "k5-int.h" #include #include -#include #ifdef _MSDOS #define getpid _getpid #include @@ -172,6 +171,10 @@ krb5_error_code krb5_obtain_padata(context, preauth_to_use, key_proc, retval = decode_krb5_etype_info(&scratch, &etype_info); if (retval) return retval; + if (etype_info[0] == NULL) { + krb5_free_etype_info(context, etype_info); + etype_info = NULL; + } } } diff --git a/src/lib/krb5/krb/preauth2.c b/src/lib/krb5/krb/preauth2.c index 5ea61c9..78afab9 100644 --- a/src/lib/krb5/krb/preauth2.c +++ b/src/lib/krb5/krb/preauth2.c @@ -256,6 +256,9 @@ krb5_error_code pa_sam(krb5_context context, krb5_data * scratch; krb5_pa_data * pa; + if (prompter == NULL) + return KRB5_LIBOS_CANTREADPWD; + tmpsam.length = in_padata->length; tmpsam.data = (char *) in_padata->contents; if (ret = decode_krb5_sam_challenge(&tmpsam, &sam_challenge)) @@ -530,6 +533,11 @@ krb5_do_preauth(krb5_context context, } return ret; } + if (etype_info[0] == NULL) { + krb5_free_etype_info(context, etype_info); + etype_info = NULL; + break; + } salt->data = (char *) etype_info[0]->salt; salt->length = etype_info[0]->length; *etype = etype_info[0]->etype; diff --git a/src/lib/krb5/krb/princ_comp.c b/src/lib/krb5/krb/princ_comp.c index cba26a6..dbcd29d 100644 --- a/src/lib/krb5/krb/princ_comp.c +++ b/src/lib/krb5/krb/princ_comp.c @@ -30,7 +30,7 @@ #include "k5-int.h" -krb5_boolean +krb5_boolean KRB5_CALLCONV krb5_realm_compare(context, princ1, princ2) krb5_context context; krb5_const_principal princ1; diff --git a/src/lib/krb5/krb/rd_cred.c b/src/lib/krb5/krb/rd_cred.c index 86c5ccf..593eb42 100644 --- a/src/lib/krb5/krb/rd_cred.c +++ b/src/lib/krb5/krb/rd_cred.c @@ -1,4 +1,4 @@ -#include +#include "k5-int.h" #include "cleanup.h" #include "auth_con.h" @@ -55,24 +55,22 @@ cleanup: /*----------------------- krb5_rd_cred_basic -----------------------*/ static krb5_error_code -krb5_rd_cred_basic(context, pcreddata, pkeyblock, local_addr, remote_addr, +krb5_rd_cred_basic(context, pcreddata, pkeyblock, replaydata, pppcreds) krb5_context context; krb5_data * pcreddata; krb5_keyblock * pkeyblock; - krb5_address * local_addr; - krb5_address * remote_addr; krb5_replay_data * replaydata; krb5_creds *** pppcreds; { - krb5_error_code retval; - krb5_cred * pcred; + krb5_error_code retval; + krb5_cred * pcred; krb5_int32 ncreds; krb5_int32 i = 0; krb5_cred_enc_part encpart; /* decode cred message */ - if ((retval = decode_krb5_cred(pcreddata, &pcred))) + if ((retval = decode_krb5_cred(pcreddata, &pcred))) return retval; memset(&encpart, 0, sizeof(encpart)); @@ -80,38 +78,6 @@ krb5_rd_cred_basic(context, pcreddata, pkeyblock, local_addr, remote_addr, if ((retval = decrypt_credencdata(context, pcred, pkeyblock, &encpart))) goto cleanup_cred; - /* - * Only check the remote address if the KRB_CRED message was - * protected by encryption. If it came in the checksum field of - * an init_sec_context message, skip over this check. - */ - if (remote_addr && encpart.s_address && pkeyblock != NULL) { - if (!krb5_address_compare(context, remote_addr, encpart.s_address)) { - retval = KRB5KRB_AP_ERR_BADADDR; - goto cleanup_cred; - } - } - - if (encpart.r_address) { - if (local_addr) { - if (!krb5_address_compare(context, local_addr, encpart.r_address)) { - retval = KRB5KRB_AP_ERR_BADADDR; - goto cleanup_cred; - } - } else { - krb5_address **our_addrs; - - if ((retval = krb5_os_localaddr(context, &our_addrs))) { - goto cleanup_cred; - } - if (!krb5_address_search(context, encpart.r_address, our_addrs)) { - krb5_free_addresses(context, our_addrs); - retval = KRB5KRB_AP_ERR_BADADDR; - goto cleanup_cred; - } - krb5_free_addresses(context, our_addrs); - } - } replaydata->timestamp = encpart.timestamp; replaydata->usec = encpart.usec; @@ -232,54 +198,12 @@ krb5_rd_cred(context, auth_context, pcreddata, pppcreds, outdata) (auth_context->rcache == NULL)) return KRB5_RC_REQUIRED; -{ - krb5_address * premote_fulladdr = NULL; - krb5_address * plocal_fulladdr = NULL; - krb5_address remote_fulladdr; - krb5_address local_fulladdr; - CLEANUP_INIT(2); - - if (auth_context->local_addr) { - if (auth_context->local_port) { - if (!(retval = krb5_make_fulladdr(context,auth_context->local_addr, - auth_context->local_port, - &local_fulladdr))){ - CLEANUP_PUSH(local_fulladdr.contents, free); - plocal_fulladdr = &local_fulladdr; - } else { - return retval; - } - } else { - plocal_fulladdr = auth_context->local_addr; - } - } - - if (auth_context->remote_addr) { - if (auth_context->remote_port) { - if (!(retval = krb5_make_fulladdr(context,auth_context->remote_addr, - auth_context->remote_port, - &remote_fulladdr))){ - CLEANUP_PUSH(remote_fulladdr.contents, free); - premote_fulladdr = &remote_fulladdr; - } else { - return retval; - } - } else { - premote_fulladdr = auth_context->remote_addr; - } - } if ((retval = krb5_rd_cred_basic(context, pcreddata, keyblock, - plocal_fulladdr, premote_fulladdr, &replaydata, pppcreds))) { - CLEANUP_DONE(); - return retval; + return retval; } - CLEANUP_DONE(); -} - - if (auth_context->auth_context_flags & KRB5_AUTH_CONTEXT_DO_TIME) { krb5_donot_replay replay; krb5_timestamp currenttime; @@ -327,4 +251,3 @@ error:; return retval; } - diff --git a/src/lib/krb5/krb/rd_priv.c b/src/lib/krb5/krb/rd_priv.c index 9629b0c..bf33ad2 100644 --- a/src/lib/krb5/krb/rd_priv.c +++ b/src/lib/krb5/krb/rd_priv.c @@ -27,7 +27,7 @@ * krb5_rd_priv() */ -#include +#include "k5-int.h" #include "cleanup.h" #include "auth_con.h" @@ -101,13 +101,6 @@ krb5_rd_priv_basic(context, inbuf, keyblock, local_addr, remote_addr, &privmsg->enc_part, &scratch))) goto cleanup_scratch; - /* if i_vector is set, put last block into the i_vector */ - if (i_vector) - memcpy(i_vector, - privmsg->enc_part.ciphertext.data + - (privmsg->enc_part.ciphertext.length - blocksize), - blocksize); - /* now decode the decrypted stuff */ if ((retval = decode_krb5_enc_priv_part(&scratch, &privmsg_enc_part))) goto cleanup_scratch; diff --git a/src/lib/krb5/krb/rd_req_dec.c b/src/lib/krb5/krb/rd_req_dec.c index 442e78b..4e9f44e 100644 --- a/src/lib/krb5/krb/rd_req_dec.c +++ b/src/lib/krb5/krb/rd_req_dec.c @@ -83,8 +83,8 @@ krb5_rd_req_decrypt_tkt_part(context, req, keytab) enctype, &ktent))) return retval; - if ((retval = krb5_decrypt_tkt_part(context, &ktent.key, req->ticket))) - return retval; + retval = krb5_decrypt_tkt_part(context, &ktent.key, req->ticket); + /* Upon error, Free keytab entry first, then return */ (void) krb5_kt_free_entry(context, &ktent); return retval; diff --git a/src/lib/krb5/krb/rd_safe.c b/src/lib/krb5/krb/rd_safe.c index 19c541f..3909f16 100644 --- a/src/lib/krb5/krb/rd_safe.c +++ b/src/lib/krb5/krb/rd_safe.c @@ -27,7 +27,7 @@ * krb5_rd_safe() */ -#include +#include "k5-int.h" #include "cleanup.h" #include "auth_con.h" diff --git a/src/lib/krb5/krb/recvauth.c b/src/lib/krb5/krb/recvauth.c index 3d5bce4..7458cb9 100644 --- a/src/lib/krb5/krb/recvauth.c +++ b/src/lib/krb5/krb/recvauth.c @@ -30,27 +30,24 @@ #define NEED_SOCKETS #include "k5-int.h" #include "auth_con.h" -#include "com_err.h" #include #include #include static char *sendauth_version = "KRB5_SENDAUTH_V1.0"; -KRB5_DLLIMP krb5_error_code KRB5_CALLCONV -krb5_recvauth(context, auth_context, - /* IN */ - fd, appl_version, server, flags, keytab, - /* OUT */ - ticket) - krb5_context context; - krb5_auth_context FAR * auth_context; - krb5_pointer fd; - char FAR * appl_version; - krb5_principal server; - krb5_int32 flags; - krb5_keytab keytab; - krb5_ticket FAR * FAR * ticket; +krb5_error_code +recvauth_common(krb5_context context, + krb5_auth_context FAR * auth_context, + /* IN */ + krb5_pointer fd, + char FAR *appl_version, + krb5_principal server, + krb5_int32 flags, + krb5_keytab keytab, + /* OUT */ + krb5_ticket FAR * FAR * ticket, + krb5_data FAR *version) { krb5_auth_context new_auth_context; krb5_flags ap_option; @@ -91,12 +88,15 @@ krb5_recvauth(context, auth_context, */ if ((retval = krb5_read_message(context, fd, &inbuf))) return(retval); - if (strcmp(inbuf.data, appl_version)) { + if (appl_version && strcmp(inbuf.data, appl_version)) { krb5_xfree(inbuf.data); if (!problem) problem = KRB5_SENDAUTH_BADAPPLVERS; } - krb5_xfree(inbuf.data); + if (version && !problem) + *version = inbuf; + else + krb5_xfree(inbuf.data); /* * OK, now check the problem variable. If it's zero, we're * fine and we can continue. Otherwise, we have to signal an @@ -243,3 +243,38 @@ cleanup:; } return retval; } + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_recvauth(context, auth_context, + /* IN */ + fd, appl_version, server, flags, keytab, + /* OUT */ + ticket) + krb5_context context; + krb5_auth_context FAR * auth_context; + krb5_pointer fd; + char FAR * appl_version; + krb5_principal server; + krb5_int32 flags; + krb5_keytab keytab; + krb5_ticket FAR * FAR * ticket; +{ + return recvauth_common (context, auth_context, fd, appl_version, + server, flags, keytab, ticket, 0); +} + +KRB5_DLLIMP krb5_error_code KRB5_CALLCONV +krb5_recvauth_version(krb5_context context, + krb5_auth_context FAR *auth_context, + /* IN */ + krb5_pointer fd, + krb5_principal server, + krb5_int32 flags, + krb5_keytab keytab, + /* OUT */ + krb5_ticket FAR * FAR *ticket, + krb5_data FAR *version) +{ + return recvauth_common (context, auth_context, fd, 0, + server, flags, keytab, ticket, version); +} diff --git a/src/lib/krb5/krb/send_tgs.c b/src/lib/krb5/krb/send_tgs.c index 520c0e2..49bc1c9 100644 --- a/src/lib/krb5/krb/send_tgs.c +++ b/src/lib/krb5/krb/send_tgs.c @@ -150,7 +150,6 @@ krb5_send_tgs(context, kdcoptions, timestruct, ktypes, sname, addrs, krb5_timestamp time_now; krb5_pa_data **combined_padata; krb5_pa_data ap_req_padata; - size_t enclen; /* * in_creds MUST be a valid credential NOT just a partially filled in diff --git a/src/lib/krb5/krb/sendauth.c b/src/lib/krb5/krb/sendauth.c index 4e7c3a7..24d8a8e 100644 --- a/src/lib/krb5/krb/sendauth.c +++ b/src/lib/krb5/krb/sendauth.c @@ -30,7 +30,6 @@ #define NEED_SOCKETS #include "k5-int.h" -#include "com_err.h" #include "auth_con.h" #include #include @@ -119,7 +118,7 @@ krb5_sendauth(context, auth_context, if (!in_creds || !in_creds->ticket.length) { if (ccache) use_ccache = ccache; - else if ((retval = krb5_cc_default(context, &use_ccache))) + else if ((retval = krb5int_cc_default(context, &use_ccache))) goto error_return; } if (!in_creds) { @@ -152,9 +151,32 @@ krb5_sendauth(context, auth_context, credsp = in_creds; } - if ((retval = krb5_mk_req_extended(context, auth_context, ap_req_options, - in_data, credsp, &outbuf))) - goto error_return; + if (ap_req_options & AP_OPTS_USE_SUBKEY) { + /* Provide some more fodder for random number code. + This isn't strong cryptographically; the point here is + not to guarantee randomness, but to make it less likely + that multiple sessions could pick the same subkey. */ + char rnd_data[1024]; + size_t len; + krb5_data d; + d.length = sizeof (rnd_data); + d.data = rnd_data; + len = sizeof (rnd_data); + if (getpeername (*(int*)fd, (struct sockaddr *) rnd_data, &len) == 0) { + d.length = len; + (void) krb5_c_random_seed (context, &d); + } + len = sizeof (rnd_data); + if (getsockname (*(int*)fd, (struct sockaddr *) rnd_data, &len) == 0) { + d.length = len; + (void) krb5_c_random_seed (context, &d); + } + } + + if ((retval = krb5_mk_req_extended(context, auth_context, + ap_req_options, in_data, credsp, + &outbuf))) + goto error_return; /* * First write the length of the AP_REQ message, then write diff --git a/src/lib/krb5/krb/ser_actx.c b/src/lib/krb5/krb/ser_actx.c index bac90e3..fdebbe3 100644 --- a/src/lib/krb5/krb/ser_actx.c +++ b/src/lib/krb5/krb/ser_actx.c @@ -208,6 +208,7 @@ krb5_auth_context_externalize(kcontext, arg, buffer, lenremain) krb5_octet *bp; size_t remain; krb5_int32 obuf; + size_t vecsize; required = 0; bp = *buffer; @@ -237,11 +238,14 @@ krb5_auth_context_externalize(kcontext, arg, buffer, lenremain) if (auth_context->i_vector) { kret = krb5_c_block_size(kcontext, auth_context->keyblock->enctype, - &obuf); + &vecsize); } else { - obuf = 0; + vecsize = 0; } - + obuf = vecsize; + if (obuf != vecsize) + kret = EINVAL; + if (!kret) (void) krb5_ser_pack_int32(obuf, &bp, &remain); diff --git a/src/lib/krb5/krb/t_kerb.c b/src/lib/krb5/krb/t_kerb.c index 2feef39..458015d 100644 --- a/src/lib/krb5/krb/t_kerb.c +++ b/src/lib/krb5/krb/t_kerb.c @@ -4,6 +4,7 @@ */ #include "krb5.h" +#include "kerberosIV/krb.h" #include #include #include @@ -56,6 +57,32 @@ void test_425_conv_principal(ctx, name, inst, realm) krb5_free_principal(ctx, princ); } +void test_524_conv_principal(ctx, name) + krb5_context ctx; + char *name; +{ + krb5_principal princ = 0; + krb5_error_code retval; + char aname[ANAME_SZ+1], inst[INST_SZ+1], realm[REALM_SZ+1]; + + aname[ANAME_SZ] = inst[INST_SZ] = realm[REALM_SZ] = 0; + retval = krb5_parse_name(ctx, name, &princ); + if (retval) { + com_err("krb5_parse_name", retval, 0); + goto fail; + } + retval = krb5_524_conv_principal(ctx, princ, aname, inst, realm); + if (retval) { + com_err("krb5_524_conv_principal", retval, 0); + goto fail; + } + printf("524_converted_principal(%s): '%s' '%s' '%s'\n", + name, aname, inst, realm); + fail: + if (princ) + krb5_free_principal (ctx, princ); +} + void test_parse_name(ctx, name) krb5_context ctx; const char *name; @@ -131,6 +158,7 @@ void usage(progname) { fprintf(stderr, "%s: Usage: %s 425_conv_principal \n", progname); fprintf(stderr, "\t%s parse_name \n", progname); fprintf(stderr, "\t%s set_realm \n", progname); fprintf(stderr, "\t%s string_to_timestamp