]> git.sur5r.net Git - openldap/blob - libraries/macintosh/kerberos-macos.c
Initial revision
[openldap] / libraries / macintosh / kerberos-macos.c
1 /*
2  *  Copyright (c) 1992, 1994 Regents of the University of Michigan.
3  *  All rights reserved.
4  *
5  *  kerberos-macos.c
6  */
7
8 #ifndef lint 
9 static char copyright[] = "@(#) Copyright (c) 1994 Regents of the University of Michigan.\nAll rights reserved.\n";
10 #endif
11
12 #include "lber.h"
13 #include "ldap.h"
14
15 #ifdef KERBEROS
16
17 #include <stdio.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #ifdef THINK_C
21 #include <pascal.h>
22 #else /* THINK_C */
23 #include <Strings.h>
24 #endif /* THINK_C */
25 #ifdef AUTHMAN
26 #include <MixedMode.h>
27 #include <Errors.h>
28 #include "authLibrary.h"
29 #include "ldap-int.h"
30
31 /*
32  * get_kerberosv4_credentials - obtain kerberos v4 credentials for ldap.
33  */
34
35 /* ARGSUSED */
36 char *
37 get_kerberosv4_credentials( LDAP *ld, char *who, char *service, int *len )
38 {
39         static short    authman_refnum = 0;
40         char            *cred, ticket[ MAX_KTXT_LEN ];
41         short           version, ticketlen, err;
42         Str255          svcps, instps;
43         
44         /*
45          * make sure RJC's Authentication Manager 2.0 or better is available
46          */
47         if ( authman_refnum == 0 && (( err = openAuthMan( &authman_refnum, &version )) != noErr || version < 2 )) {
48                 authman_refnum = 0;
49                 ld->ld_errno = LDAP_AUTH_UNKNOWN;
50                 return( NULL );
51         }
52         
53         strcpy( (char *)svcps, service );
54         CtoPstr( (char *)svcps );
55 #ifdef LDAP_REFERRALS
56         strcpy( (char *)instps, ld->ld_defconn->lconn_krbinstance );
57 #else /* LDAP_REFERRALS */
58         strcpy( (char *)instps, ld->ld_host );
59 #endif /* LDAP_REFERRALS */
60
61         CtoPstr( (char *)instps );
62         if (( err = getV4Ticket( authman_refnum, &ticket, &ticketlen, &svcps, &instps,
63                         NULL, INFINITE_LIFETIME, 1 )) != noErr ) {
64                 ld->ld_errno = ( err == userCanceledErr ) ?
65                         LDAP_USER_CANCELLED : LDAP_INVALID_CREDENTIALS;
66                 return( NULL );
67         }
68
69         if (( cred = malloc( ticketlen )) == NULL ) {
70                 ld->ld_errno = LDAP_NO_MEMORY;
71                 return( NULL );
72         }
73
74         *len = ticketlen;
75         memcpy( cred, (char *)ticket, ticketlen );
76         return( cred );
77 }
78
79 #endif
80 #endif