2 * Copyright (c) 1990 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
20 #include <ac/socket.h>
22 #include <quipu/bind.h>
23 #if ISODEPACKAGE == IC
24 #include <quipu/DAS-types.h>
26 #include <pepsy/DAS-types.h>
34 kerberosv4_ldap_auth( char *cred, long len )
38 char instance[INST_SZ];
42 Debug( LDAP_DEBUG_TRACE, "kerberosv4_ldap_auth\n", 0, 0, 0 );
44 SAFEMEMCPY( ktxt->dat, cred, len );
47 strcpy( instance, "*" );
48 if ( (err = krb_rd_req( ktxt, krb_ldap_service, instance, 0L,
49 &ad, kerberos_keyfile )) != KSUCCESS ) {
50 Debug( LDAP_DEBUG_ANY, "krb_rd_req failed (%s)\n",
51 krb_err_txt[err], 0, 0 );
52 return( LDAP_INVALID_CREDENTIALS );
55 return( LDAP_SUCCESS );
60 struct ds_bind_arg *ba,
67 struct type_UNIV_EXTERNAL *e;
68 struct kerberos_parms kp;
74 Debug( LDAP_DEBUG_TRACE, "kerberosv4_bindarg\n", 0, 0, 0 );
76 e = (struct type_UNIV_EXTERNAL *) calloc( 1,
77 sizeof(struct type_UNIV_EXTERNAL) );
78 e->encoding = (struct choice_UNIV_0 *) calloc( 1,
79 sizeof(struct choice_UNIV_0) );
81 ba->dba_version = DBA_VERSION_V1988;
82 ba->dba_auth_type = DBA_AUTH_EXTERNAL;
84 e->indirect__reference = AUTH_TYPE_KERBEROS_V4;
85 e->direct__reference = NULLOID;
86 e->data__value__descriptor = str2qb( "KRBv4 client credentials",
90 kp.kp_version = AUTH_TYPE_KERBEROS_V4;
92 if ( (err = krb_get_lrealm( realm, 1 )) != KSUCCESS ) {
93 Debug( LDAP_DEBUG_ANY, "krb_get_lrealm failed (%s)\n",
94 krb_err_txt[err], 0, 0 );
95 return( LDAP_OPERATIONS_ERROR );
98 gettimeofday( &tv, NULL );
100 SAFEMEMCPY( kp.kp_ktxt.dat, cred, len );
101 kp.kp_ktxt.length = len;
102 if ( encode_kerberos_parms( &pe, &kp ) == NOTOK ) {
103 Debug( LDAP_DEBUG_ANY, "kerberos parms encoding failed\n", 0,
105 return( LDAP_OPERATIONS_ERROR );
108 e->encoding->offset = choice_UNIV_0_single__ASN1__type;
109 e->encoding->un.single__ASN1__type = pe;
115 kerberos_check_mutual(
116 struct ds_bind_arg *res,
120 struct type_UNIV_EXTERNAL *e = res->dba_external;
121 struct kerberos_parms *kp;
124 Debug( LDAP_DEBUG_TRACE, "kerberos_check_mutual\n", 0, 0, 0 );
126 if ( decode_kerberos_parms( e->encoding->un.single__ASN1__type, &kp )
129 ret = ((kp->kp_nonce == (nonce + 1)) ? OK : NOTOK );
131 Debug( LDAP_DEBUG_TRACE, "expecting %d got %d\n", nonce, kp->kp_nonce,
134 pe_free( e->encoding->un.single__ASN1__type );
135 dn_free( kp->kp_dn );