43 #ifndef CURL_DISABLE_FTP
64 #if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
73 #define LOCAL_ADDR (&conn->local_addr)
74 #define REMOTE_ADDR (&conn->serv_addr)
75 #define myctladdr LOCAL_ADDR
76 #define hisctladdr REMOTE_ADDR
80 des_key_schedule schedule;
82 char instance[INST_SZ];
89 strlcpy (
char *
dst,
const char *
src,
size_t dst_sz)
95 n + 1 < dst_sz && *src !=
'\0';
102 return n + strlen (src);
105 size_t strlcpy (
char *dst,
const char *src,
size_t dst_sz);
109 krb4_check_prot(
void *app_data,
int level)
112 if(level == prot_confidential)
118 krb4_decode(
void *app_data,
void *buf,
int len,
int level,
123 struct krb4_data *d = app_data;
125 if(level == prot_safe)
126 e = krb_rd_safe(buf, len, &d->key,
127 (
struct sockaddr_in *)REMOTE_ADDR,
128 (
struct sockaddr_in *)LOCAL_ADDR, &m);
130 e = krb_rd_priv(buf, len, d->schedule, &d->key,
131 (
struct sockaddr_in *)REMOTE_ADDR,
132 (
struct sockaddr_in *)LOCAL_ADDR, &m);
135 infof(data,
"krb4_decode: %s\n", krb_get_err_text(e));
138 memmove(buf, m.app_data, m.app_length);
143 krb4_overhead(
void *app_data,
int level,
int len)
153 krb4_encode(
void *app_data,
void *from,
int length,
int level,
void **to,
156 struct krb4_data *d = app_data;
157 *to = malloc(length + 31);
158 if(level == prot_safe)
159 return krb_mk_safe(from, *to, length, &d->key,
160 (
struct sockaddr_in *)LOCAL_ADDR,
161 (
struct sockaddr_in *)REMOTE_ADDR);
162 else if(level == prot_private)
163 return krb_mk_priv(from, *to, length, d->schedule, &d->key,
164 (
struct sockaddr_in *)LOCAL_ADDR,
165 (
struct sockaddr_in *)REMOTE_ADDR);
171 mk_auth(
struct krb4_data *d, KTEXT adat,
172 const char *service,
char *host,
int checksum)
176 char sname[SNAME_SZ], inst[INST_SZ], realm[REALM_SZ];
178 strlcpy(sname, service,
sizeof(sname));
179 strlcpy(inst, krb_get_phost(host),
sizeof(inst));
180 strlcpy(realm, krb_realmofhost(host),
sizeof(realm));
181 ret = krb_mk_req(adat, sname, inst, realm, checksum);
184 strlcpy(sname, service,
sizeof(sname));
185 strlcpy(inst, krb_get_phost(host),
sizeof(inst));
186 strlcpy(realm, krb_realmofhost(host),
sizeof(realm));
187 ret = krb_get_cred(sname, inst, realm, &cred);
188 memmove(&d->key, &cred.session,
sizeof(des_cblock));
189 des_key_sched(&d->key, d->schedule);
190 memset(&cred, 0,
sizeof(cred));
194 #ifdef HAVE_KRB_GET_OUR_IP_FOR_REALM
195 int krb_get_our_ip_for_realm(
char *,
struct in_addr *);
199 krb4_auth(
void *app_data,
struct connectdata *conn)
208 struct krb4_data *d = app_data;
211 int l =
sizeof(conn->local_addr);
216 (
struct sockaddr *)LOCAL_ADDR, &l) < 0)
217 perror(
"getsockname()");
220 ret = mk_auth(d, &adat,
"ftp", host, checksum);
221 if(ret == KDC_PR_UNKNOWN)
222 ret = mk_auth(d, &adat,
"rcmd", host, checksum);
224 Curl_infof(data,
"%s\n", krb_get_err_text(ret));
228 #ifdef HAVE_KRB_GET_OUR_IP_FOR_REALM
229 if (krb_get_config_bool(
"nat_in_use")) {
230 struct sockaddr_in *localaddr = (
struct sockaddr_in *)LOCAL_ADDR;
231 struct in_addr natAddr;
233 if (krb_get_our_ip_for_realm(krb_realmofhost(host),
234 &natAddr) != KSUCCESS
235 && krb_get_our_ip_for_realm(
NULL, &natAddr) != KSUCCESS)
236 Curl_infof(data,
"Can't get address for realm %s\n",
237 krb_realmofhost(host));
239 if (natAddr.s_addr != localaddr->sin_addr.s_addr) {
240 #ifdef HAVE_INET_NTOA_R
242 char *ip = (
char *)
inet_ntoa_r(natAddr, ntoa_buf,
sizeof(ntoa_buf));
246 Curl_infof(data,
"Using NAT IP address (%s) for kerberos 4\n", ip);
247 localaddr->sin_addr = natAddr;
254 Curl_failf(data,
"Out of memory base64-encoding");
269 Curl_failf(data,
"Server didn't accept auth data");
275 Curl_failf(data,
"Remote host didn't send adat reply");
281 Curl_failf(data,
"Failed to decode base64 from server");
285 ret = krb_rd_safe(adat.dat, adat.length, &d->key,
286 (
struct sockaddr_in *)hisctladdr,
287 (
struct sockaddr_in *)myctladdr, &msg_data);
289 Curl_failf(data,
"Error reading reply from server: %s",
290 krb_get_err_text(ret));
293 krb_get_int(msg_data.app_data, &cs, 4, 0);
294 if(cs - checksum != 1) {
295 Curl_failf(data,
"Bad checksum returned from server");
303 sizeof(
struct krb4_data),
316 des_key_schedule schedule;
317 KTEXT_ST tkt, tktcopy;
357 tktcopy.length = tkt.length;
366 for(; *p && *p !=
' ' && *p !=
'\r' && *p !=
'\n'; p++);
369 des_string_to_key (conn->
passwd, &key);
370 des_key_sched(&key, schedule);
372 des_pcbc_encrypt((
void *)tkt.dat, (
void *)tktcopy.dat,
374 schedule, &key, DES_DECRYPT);
375 if (
strcmp ((
char*)tktcopy.dat + 8,
376 KRB_TICKET_GRANTING_TICKET) != 0) {
377 afs_string_to_key(passwd,
380 des_key_sched(&key, schedule);
381 des_pcbc_encrypt((
void *)tkt.dat, (
void *)tktcopy.dat,
383 schedule, &key, DES_DECRYPT);
385 memset(key, 0,
sizeof(key));
386 memset(schedule, 0,
sizeof(schedule));
387 memset(passwd, 0,
sizeof(passwd));
389 failf(conn->
data,
"Out of memory base64-encoding.");
393 memset (tktcopy.dat, 0, tktcopy.length);
CURLcode Curl_krb_kauth(struct connectdata *conn)
void Curl_failf(struct SessionHandle *data, const char *fmt,...)
struct Curl_sec_client_mech Curl_krb4_client_mech
size_t Curl_base64_encode(const char *inp, size_t insize, char **outptr)
CURLcode Curl_GetFTPResponse(ssize_t *nreadp, struct connectdata *conn, int *ftpcode)
size_t Curl_base64_decode(const char *src, char *dest)
CURLcode Curl_ftpsendf(struct connectdata *conn, const char *fmt,...)
char * inet_ntoa_r(const struct in_addr in, char *buffer, int buflen)
GLsizei GLsizei GLenum GLenum const GLvoid * data
struct SessionHandle * data
enum protection_level Curl_set_command_prot(struct connectdata *, enum protection_level)
void Curl_infof(struct SessionHandle *data, const char *fmt,...)
GLsizei const GLcharARB const GLint * length