3 * Copyright (c) 1990 Regents of the University of Michigan.
6 * Redistribution and use in source and binary forms are permitted
7 * provided that this notice is preserved and that due credit is given
8 * to the University of Michigan at Ann Arbor. The name of the University
9 * may not be used to endorse or promote products derived from this
10 * software without specific prior written permission. This software
11 * is provided ``as is'' without express or implied warranty.
21 #include <ac/socket.h>
23 #include <quipu/bind.h>
24 #if ISODEPACKAGE == IC
25 #include <quipu/DAS-types.h>
27 #include <pepsy/DAS-types.h>
35 kerberosv4_ldap_auth( char *cred, long len )
39 char instance[INST_SZ];
43 Debug( LDAP_DEBUG_TRACE, "kerberosv4_ldap_auth\n", 0, 0, 0 );
45 SAFEMEMCPY( ktxt->dat, cred, len );
48 strcpy( instance, "*" );
49 if ( (err = krb_rd_req( ktxt, krb_ldap_service, instance, 0L,
50 &ad, kerberos_keyfile )) != KSUCCESS ) {
51 Debug( LDAP_DEBUG_ANY, "krb_rd_req failed (%s)\n",
52 krb_err_txt[err], 0, 0 );
53 return( LDAP_INVALID_CREDENTIALS );
56 return( LDAP_SUCCESS );
61 struct ds_bind_arg *ba,
68 struct type_UNIV_EXTERNAL *e;
69 struct kerberos_parms kp;
75 Debug( LDAP_DEBUG_TRACE, "kerberosv4_bindarg\n", 0, 0, 0 );
77 e = (struct type_UNIV_EXTERNAL *) calloc( 1,
78 sizeof(struct type_UNIV_EXTERNAL) );
79 e->encoding = (struct choice_UNIV_0 *) calloc( 1,
80 sizeof(struct choice_UNIV_0) );
82 ba->dba_version = DBA_VERSION_V1988;
83 ba->dba_auth_type = DBA_AUTH_EXTERNAL;
85 e->indirect__reference = AUTH_TYPE_KERBEROS_V4;
86 e->direct__reference = NULLOID;
87 e->data__value__descriptor = str2qb( "KRBv4 client credentials",
91 kp.kp_version = AUTH_TYPE_KERBEROS_V4;
93 if ( (err = krb_get_lrealm( realm, 1 )) != KSUCCESS ) {
94 Debug( LDAP_DEBUG_ANY, "krb_get_lrealm failed (%s)\n",
95 krb_err_txt[err], 0, 0 );
96 return( LDAP_OPERATIONS_ERROR );
99 gettimeofday( &tv, NULL );
101 SAFEMEMCPY( kp.kp_ktxt.dat, cred, len );
102 kp.kp_ktxt.length = len;
103 if ( encode_kerberos_parms( &pe, &kp ) == NOTOK ) {
104 Debug( LDAP_DEBUG_ANY, "kerberos parms encoding failed\n", 0,
106 return( LDAP_OPERATIONS_ERROR );
109 e->encoding->offset = choice_UNIV_0_single__ASN1__type;
110 e->encoding->un.single__ASN1__type = pe;
116 kerberos_check_mutual(
117 struct ds_bind_arg *res,
121 struct type_UNIV_EXTERNAL *e = res->dba_external;
122 struct kerberos_parms *kp;
125 Debug( LDAP_DEBUG_TRACE, "kerberos_check_mutual\n", 0, 0, 0 );
127 if ( decode_kerberos_parms( e->encoding->un.single__ASN1__type, &kp )
130 ret = ((kp->kp_nonce == (nonce + 1)) ? OK : NOTOK );
132 Debug( LDAP_DEBUG_TRACE, "expecting %d got %d\n", nonce, kp->kp_nonce,
135 pe_free( e->encoding->un.single__ASN1__type );
136 dn_free( kp->kp_dn );