2 Copyright (C) 2003 - 2010 Chaskiel Grundman
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <afsconfig.h>
28 #include <afs/param.h>
31 #include <afs/cellconfig.h>
32 #ifndef AFSCONF_CLIENTNAME
33 #include <afs/dirpath.h>
34 #define AFSCONF_CLIENTNAME AFSDIR_CLIENT_ETC_DIRPATH
37 #include <rx/rx_null.h>
40 # define KERBEROS_APPLE_DEPRECATED(x)
44 #include "afscp_internal.h"
46 #ifdef HAVE_KRB5_CREDS_KEYBLOCK_ENCTYPE
47 #define Z_keydata(keyblock) ((keyblock)->contents)
48 #define Z_keylen(keyblock) ((keyblock)->length)
49 #define Z_credskey(creds) (&(creds)->keyblock)
50 #define Z_enctype(keyblock) ((keyblock)->enctype)
52 #define Z_keydata(keyblock) ((keyblock)->keyvalue.data)
53 #define Z_keylen(keyblock) ((keyblock)->keyvalue.length)
54 #define Z_credskey(creds) (&(creds)->session)
55 #define Z_enctype(keyblock) ((keyblock)->keytype)
58 static int insecure
= 0;
59 static int try_anonymous
= 0;
69 afscp_AnonymousAuth(int state
)
71 try_anonymous
= state
;
75 static struct afsconf_dir
*confdir
;
78 afscp_SetConfDir(char *confDir
)
81 afsconf_Close(confdir
);
83 confdir
= afsconf_Open(confDir
);
87 _GetCellInfo(char *cell
, struct afsconf_cell
*celldata
)
91 confdir
= afsconf_Open(AFSCONF_CLIENTNAME
);
92 if (confdir
== NULL
) {
95 code
= afsconf_GetCellInfo(confdir
, cell
, AFSCONF_VLDBSERVICE
, celldata
);
100 _GetNullSecurityObject(struct afscp_cell
*cell
)
102 cell
->security
= (struct rx_securityClass
*)rxnull_NewClientSecurityObject();
103 cell
->scindex
= RX_SECIDX_NULL
;
108 _GetSecurityObject(struct afscp_cell
*cell
)
112 krb5_context context
;
116 char **realms
, *realm
;
117 struct afsconf_cell celldata
;
118 char localcell
[MAXCELLCHARS
+ 1];
119 struct rx_securityClass
*sc
;
120 struct ktc_encryptionKey k
;
123 code
= _GetCellInfo(cell
->name
, &celldata
);
128 code
= krb5_init_context(&context
); /* see aklog.c main() */
133 if (cell
->realm
== NULL
) {
135 code
= krb5_get_host_realm(context
, celldata
.hostName
[0], &realms
);
138 strlcpy(localcell
, realms
[0], sizeof(localcell
));
139 krb5_free_host_realm(context
, realms
);
144 strlcpy(localcell
, realm
, MAXCELLCHARS
+ 1);
148 for (i
= 0; (i
< MAXCELLCHARS
&& cell
->name
[i
]); i
++) {
149 if (isalpha(cell
->name
[i
]))
150 localcell
[i
] = toupper(cell
->name
[i
]);
152 localcell
[i
] = cell
->name
[i
];
158 code
= krb5_cc_default(context
, &cc
);
160 memset(&match
, 0, sizeof(match
));
161 Z_enctype(Z_credskey(&match
)) = ENCTYPE_DES_CBC_CRC
;
164 code
= krb5_cc_get_principal(context
, cc
, &match
.client
);
166 code
= krb5_build_principal(context
, &match
.server
,
167 strlen(realm
), realm
,
168 "afs", cell
->name
, NULL
);
171 krb5_free_cred_contents(context
, &match
);
173 krb5_cc_close(context
, cc
);
174 krb5_free_context(context
);
178 code
= krb5_get_credentials(context
, 0, cc
, &match
, &cred
);
180 krb5_free_principal(context
, match
.server
);
183 code
= krb5_build_principal(context
, &match
.server
,
184 strlen(realm
), realm
, "afs", (void *)NULL
);
186 code
= krb5_get_credentials(context
, 0, cc
, &match
, &cred
);
188 krb5_free_cred_contents(context
, &match
);
190 krb5_cc_close(context
, cc
);
191 krb5_free_context(context
);
200 memcpy(&k
.data
, Z_keydata(Z_credskey(cred
)), 8);
201 sc
= (struct rx_securityClass
*)rxkad_NewClientSecurityObject
202 (l
, &k
, RXKAD_TKT_TYPE_KERBEROS_V5
,
203 cred
->ticket
.length
, cred
->ticket
.data
);
204 krb5_free_creds(context
, cred
);
205 krb5_free_cred_contents(context
, &match
);
207 krb5_cc_close(context
, cc
);
208 krb5_free_context(context
);
214 #endif /* HAVE_KERBEROS */
216 return _GetNullSecurityObject(cell
);
222 _GetVLservers(struct afscp_cell
*cell
)
224 struct rx_connection
*conns
[MAXHOSTSPERCELL
+ 1];
227 struct afsconf_cell celldata
;
229 code
= _GetCellInfo(cell
->name
, &celldata
);
234 for (i
= 0; i
< celldata
.numServers
; i
++) {
235 conns
[i
] = rx_NewConnection(celldata
.hostAddr
[i
].sin_addr
.s_addr
,
236 htons(AFSCONF_VLDBPORT
),
237 USER_SERVICE_ID
, cell
->security
,
241 return ubik_ClientInit(conns
, &cell
->vlservers
);