2001-08-17 18:12:51 +08:00
|
|
|
|
/* This source code was modified by Martin Hedenfalk <mhe@stacken.kth.se> for
|
2006-01-26 18:39:25 +08:00
|
|
|
|
* use in Curl. Martin's latest changes were done 2000-09-18.
|
2001-08-17 18:12:51 +08:00
|
|
|
|
*
|
2006-01-26 18:39:25 +08:00
|
|
|
|
* It has since been patched away like a madman by Daniel Stenberg to make it
|
|
|
|
|
* better applied to curl conditions, and to make it not use globals, pollute
|
|
|
|
|
* name space and more.
|
2001-08-17 18:12:51 +08:00
|
|
|
|
*
|
2000-09-21 16:46:14 +08:00
|
|
|
|
* Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska H<EFBFBD>gskolan
|
|
|
|
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
2011-04-20 21:17:42 +08:00
|
|
|
|
* Copyright (c) 2004 - 2011 Daniel Stenberg
|
2000-09-21 16:46:14 +08:00
|
|
|
|
* All rights reserved.
|
2004-06-24 15:43:48 +08:00
|
|
|
|
*
|
2000-09-21 16:46:14 +08:00
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
2004-06-24 15:43:48 +08:00
|
|
|
|
*
|
2000-09-21 16:46:14 +08:00
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2004-06-24 15:43:48 +08:00
|
|
|
|
*
|
2000-09-21 16:46:14 +08:00
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2004-06-24 15:43:48 +08:00
|
|
|
|
*
|
2000-09-21 16:46:14 +08:00
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
2004-06-24 15:43:48 +08:00
|
|
|
|
*
|
2000-09-21 16:46:14 +08:00
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
2006-01-26 18:39:25 +08:00
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2000-09-21 16:46:14 +08:00
|
|
|
|
|
2013-01-07 02:06:49 +08:00
|
|
|
|
#include "curl_setup.h"
|
2000-09-21 16:46:14 +08:00
|
|
|
|
|
2002-06-11 19:13:01 +08:00
|
|
|
|
#ifndef CURL_DISABLE_FTP
|
2003-12-02 21:27:29 +08:00
|
|
|
|
#ifdef HAVE_KRB4
|
2000-09-21 16:46:14 +08:00
|
|
|
|
|
2003-12-04 23:21:49 +08:00
|
|
|
|
#ifdef HAVE_NETDB_H
|
2000-09-21 16:46:14 +08:00
|
|
|
|
#include <netdb.h>
|
2003-12-04 23:21:49 +08:00
|
|
|
|
#endif
|
2000-09-21 16:46:14 +08:00
|
|
|
|
#include <krb.h>
|
2003-01-27 22:19:22 +08:00
|
|
|
|
#include <des.h>
|
2000-09-21 16:46:14 +08:00
|
|
|
|
|
2013-01-04 09:50:28 +08:00
|
|
|
|
#include "urldata.h"
|
2008-08-17 08:25:38 +08:00
|
|
|
|
#include "curl_base64.h"
|
2013-01-04 09:50:28 +08:00
|
|
|
|
#include "ftp.h"
|
|
|
|
|
#include "sendf.h"
|
|
|
|
|
#include "krb4.h"
|
|
|
|
|
#include "inet_ntop.h"
|
2009-04-21 19:46:16 +08:00
|
|
|
|
#include "curl_memory.h"
|
2001-01-05 18:11:41 +08:00
|
|
|
|
|
2000-10-09 19:12:34 +08:00
|
|
|
|
/* The last #include file should be: */
|
2013-01-04 09:50:28 +08:00
|
|
|
|
#include "memdebug.h"
|
2000-10-09 19:12:34 +08:00
|
|
|
|
|
2001-08-17 18:12:51 +08:00
|
|
|
|
#define LOCAL_ADDR (&conn->local_addr)
|
2004-06-24 15:43:48 +08:00
|
|
|
|
#define REMOTE_ADDR conn->ip_addr->ai_addr
|
2000-09-21 16:46:14 +08:00
|
|
|
|
#define myctladdr LOCAL_ADDR
|
|
|
|
|
#define hisctladdr REMOTE_ADDR
|
|
|
|
|
|
|
|
|
|
struct krb4_data {
|
2003-12-04 23:21:49 +08:00
|
|
|
|
des_cblock key;
|
|
|
|
|
des_key_schedule schedule;
|
|
|
|
|
char name[ANAME_SZ];
|
|
|
|
|
char instance[INST_SZ];
|
|
|
|
|
char realm[REALM_SZ];
|
2000-09-21 16:46:14 +08:00
|
|
|
|
};
|
|
|
|
|
|
2000-09-27 06:28:46 +08:00
|
|
|
|
#ifndef HAVE_STRLCPY
|
2001-05-18 18:02:12 +08:00
|
|
|
|
/* if it ever goes non-static, make it Curl_ prefixed! */
|
2001-05-31 13:55:42 +08:00
|
|
|
|
static size_t
|
2000-09-27 06:28:46 +08:00
|
|
|
|
strlcpy (char *dst, const char *src, size_t dst_sz)
|
|
|
|
|
{
|
2003-12-04 23:21:49 +08:00
|
|
|
|
size_t n;
|
|
|
|
|
char *p;
|
|
|
|
|
|
2011-04-20 21:17:42 +08:00
|
|
|
|
for(p = dst, n = 0;
|
|
|
|
|
n + 1 < dst_sz && *src != '\0';
|
|
|
|
|
++p, ++src, ++n)
|
2003-12-04 23:21:49 +08:00
|
|
|
|
*p = *src;
|
|
|
|
|
*p = '\0';
|
2007-11-07 17:21:35 +08:00
|
|
|
|
if(*src == '\0')
|
2003-12-04 23:21:49 +08:00
|
|
|
|
return n;
|
|
|
|
|
else
|
|
|
|
|
return n + strlen (src);
|
2000-09-27 06:28:46 +08:00
|
|
|
|
}
|
2001-01-05 18:11:41 +08:00
|
|
|
|
#else
|
|
|
|
|
size_t strlcpy (char *dst, const char *src, size_t dst_sz);
|
2000-09-27 06:28:46 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
2000-09-21 16:46:14 +08:00
|
|
|
|
static int
|
|
|
|
|
krb4_check_prot(void *app_data, int level)
|
|
|
|
|
{
|
2001-08-14 16:30:08 +08:00
|
|
|
|
app_data = NULL; /* prevent compiler warning */
|
2010-11-14 06:42:34 +08:00
|
|
|
|
if(level == PROT_CONFIDENTIAL)
|
2001-08-14 16:30:08 +08:00
|
|
|
|
return -1;
|
|
|
|
|
return 0;
|
2000-09-21 16:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
krb4_decode(void *app_data, void *buf, int len, int level,
|
2004-10-06 15:50:18 +08:00
|
|
|
|
struct connectdata *conn)
|
2000-09-21 16:46:14 +08:00
|
|
|
|
{
|
2003-12-04 23:21:49 +08:00
|
|
|
|
MSG_DAT m;
|
|
|
|
|
int e;
|
|
|
|
|
struct krb4_data *d = app_data;
|
2004-06-24 15:43:48 +08:00
|
|
|
|
|
2010-11-14 06:42:34 +08:00
|
|
|
|
if(level == PROT_SAFE)
|
2003-12-04 23:21:49 +08:00
|
|
|
|
e = krb_rd_safe(buf, len, &d->key,
|
|
|
|
|
(struct sockaddr_in *)REMOTE_ADDR,
|
|
|
|
|
(struct sockaddr_in *)LOCAL_ADDR, &m);
|
|
|
|
|
else
|
2004-06-24 15:43:48 +08:00
|
|
|
|
e = krb_rd_priv(buf, len, d->schedule, &d->key,
|
2003-12-04 23:21:49 +08:00
|
|
|
|
(struct sockaddr_in *)REMOTE_ADDR,
|
|
|
|
|
(struct sockaddr_in *)LOCAL_ADDR, &m);
|
|
|
|
|
if(e) {
|
|
|
|
|
struct SessionHandle *data = conn->data;
|
|
|
|
|
infof(data, "krb4_decode: %s\n", krb_get_err_text(e));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
memmove(buf, m.app_data, m.app_length);
|
|
|
|
|
return m.app_length;
|
2000-09-21 16:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
krb4_overhead(void *app_data, int level, int len)
|
|
|
|
|
{
|
2001-08-14 16:30:08 +08:00
|
|
|
|
/* no arguments are used, just init them to prevent compiler warnings */
|
|
|
|
|
app_data = NULL;
|
|
|
|
|
level = 0;
|
|
|
|
|
len = 0;
|
|
|
|
|
return 31;
|
2000-09-21 16:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2008-05-09 19:27:54 +08:00
|
|
|
|
krb4_encode(void *app_data, const void *from, int length, int level, void **to,
|
2004-10-06 15:50:18 +08:00
|
|
|
|
struct connectdata *conn)
|
2000-09-21 16:46:14 +08:00
|
|
|
|
{
|
2003-12-04 23:21:49 +08:00
|
|
|
|
struct krb4_data *d = app_data;
|
|
|
|
|
*to = malloc(length + 31);
|
2008-11-16 20:26:50 +08:00
|
|
|
|
if(!*to)
|
|
|
|
|
return -1;
|
2010-11-14 06:42:34 +08:00
|
|
|
|
if(level == PROT_SAFE)
|
2008-05-09 19:27:54 +08:00
|
|
|
|
/* NOTE that the void* cast is safe, krb_mk_safe/priv don't modify the
|
|
|
|
|
* input buffer
|
|
|
|
|
*/
|
|
|
|
|
return krb_mk_safe((void*)from, *to, length, &d->key,
|
2003-12-04 23:21:49 +08:00
|
|
|
|
(struct sockaddr_in *)LOCAL_ADDR,
|
|
|
|
|
(struct sockaddr_in *)REMOTE_ADDR);
|
2010-11-14 06:42:34 +08:00
|
|
|
|
else if(level == PROT_PRIVATE)
|
2008-05-09 19:27:54 +08:00
|
|
|
|
return krb_mk_priv((void*)from, *to, length, d->schedule, &d->key,
|
2003-12-04 23:21:49 +08:00
|
|
|
|
(struct sockaddr_in *)LOCAL_ADDR,
|
|
|
|
|
(struct sockaddr_in *)REMOTE_ADDR);
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
2000-09-21 16:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2004-06-24 15:43:48 +08:00
|
|
|
|
mk_auth(struct krb4_data *d, KTEXT adat,
|
2004-10-06 15:50:18 +08:00
|
|
|
|
const char *service, char *host, int checksum)
|
2000-09-21 16:46:14 +08:00
|
|
|
|
{
|
2003-12-04 23:21:49 +08:00
|
|
|
|
int ret;
|
|
|
|
|
CREDENTIALS cred;
|
|
|
|
|
char sname[SNAME_SZ], inst[INST_SZ], realm[REALM_SZ];
|
|
|
|
|
|
|
|
|
|
strlcpy(sname, service, sizeof(sname));
|
|
|
|
|
strlcpy(inst, krb_get_phost(host), sizeof(inst));
|
|
|
|
|
strlcpy(realm, krb_realmofhost(host), sizeof(realm));
|
|
|
|
|
ret = krb_mk_req(adat, sname, inst, realm, checksum);
|
|
|
|
|
if(ret)
|
2000-09-21 16:46:14 +08:00
|
|
|
|
return ret;
|
2003-12-04 23:21:49 +08:00
|
|
|
|
strlcpy(sname, service, sizeof(sname));
|
|
|
|
|
strlcpy(inst, krb_get_phost(host), sizeof(inst));
|
|
|
|
|
strlcpy(realm, krb_realmofhost(host), sizeof(realm));
|
|
|
|
|
ret = krb_get_cred(sname, inst, realm, &cred);
|
|
|
|
|
memmove(&d->key, &cred.session, sizeof(des_cblock));
|
|
|
|
|
des_key_sched(&d->key, d->schedule);
|
|
|
|
|
memset(&cred, 0, sizeof(cred));
|
|
|
|
|
return ret;
|
2000-09-21 16:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-01-27 22:19:22 +08:00
|
|
|
|
#ifdef HAVE_KRB_GET_OUR_IP_FOR_REALM
|
|
|
|
|
int krb_get_our_ip_for_realm(char *, struct in_addr *);
|
|
|
|
|
#endif
|
|
|
|
|
|
2000-09-21 16:46:14 +08:00
|
|
|
|
static int
|
|
|
|
|
krb4_auth(void *app_data, struct connectdata *conn)
|
|
|
|
|
{
|
2001-08-14 16:30:08 +08:00
|
|
|
|
int ret;
|
|
|
|
|
char *p;
|
2005-02-22 20:10:30 +08:00
|
|
|
|
unsigned char *ptr;
|
2011-08-24 14:07:36 +08:00
|
|
|
|
size_t len = 0;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
KTEXT_ST adat;
|
|
|
|
|
MSG_DAT msg_data;
|
|
|
|
|
int checksum;
|
|
|
|
|
u_int32_t cs;
|
|
|
|
|
struct krb4_data *d = app_data;
|
2004-04-29 04:34:04 +08:00
|
|
|
|
char *host = conn->host.name;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
ssize_t nread;
|
2001-08-17 18:12:51 +08:00
|
|
|
|
int l = sizeof(conn->local_addr);
|
2002-01-04 17:52:44 +08:00
|
|
|
|
struct SessionHandle *data = conn->data;
|
2002-12-03 18:25:31 +08:00
|
|
|
|
CURLcode result;
|
2011-08-24 14:07:36 +08:00
|
|
|
|
size_t base64_sz = 0;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
|
2003-11-24 17:04:09 +08:00
|
|
|
|
if(getsockname(conn->sock[FIRSTSOCKET],
|
2001-08-14 16:30:08 +08:00
|
|
|
|
(struct sockaddr *)LOCAL_ADDR, &l) < 0)
|
|
|
|
|
perror("getsockname()");
|
|
|
|
|
|
|
|
|
|
checksum = getpid();
|
|
|
|
|
ret = mk_auth(d, &adat, "ftp", host, checksum);
|
|
|
|
|
if(ret == KDC_PR_UNKNOWN)
|
|
|
|
|
ret = mk_auth(d, &adat, "rcmd", host, checksum);
|
|
|
|
|
if(ret) {
|
2004-11-12 00:34:24 +08:00
|
|
|
|
infof(data, "%s\n", krb_get_err_text(ret));
|
2001-08-14 16:30:08 +08:00
|
|
|
|
return AUTH_CONTINUE;
|
|
|
|
|
}
|
2004-06-24 15:43:48 +08:00
|
|
|
|
|
2000-09-21 16:46:14 +08:00
|
|
|
|
#ifdef HAVE_KRB_GET_OUR_IP_FOR_REALM
|
2007-11-07 17:21:35 +08:00
|
|
|
|
if(krb_get_config_bool("nat_in_use")) {
|
2002-01-04 17:52:44 +08:00
|
|
|
|
struct sockaddr_in *localaddr = (struct sockaddr_in *)LOCAL_ADDR;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
struct in_addr natAddr;
|
|
|
|
|
|
2007-11-07 17:21:35 +08:00
|
|
|
|
if(krb_get_our_ip_for_realm(krb_realmofhost(host),
|
2001-08-14 16:30:08 +08:00
|
|
|
|
&natAddr) != KSUCCESS
|
|
|
|
|
&& krb_get_our_ip_for_realm(NULL, &natAddr) != KSUCCESS)
|
2004-11-12 00:34:24 +08:00
|
|
|
|
infof(data, "Can't get address for realm %s\n",
|
2002-01-04 17:52:44 +08:00
|
|
|
|
krb_realmofhost(host));
|
2001-08-14 16:30:08 +08:00
|
|
|
|
else {
|
2007-11-07 17:21:35 +08:00
|
|
|
|
if(natAddr.s_addr != localaddr->sin_addr.s_addr) {
|
2008-09-24 03:16:56 +08:00
|
|
|
|
char addr_buf[128];
|
|
|
|
|
if(Curl_inet_ntop(AF_INET, natAddr, addr_buf, sizeof(addr_buf)))
|
|
|
|
|
infof(data, "Using NAT IP address (%s) for kerberos 4\n", addr_buf);
|
2001-08-14 16:30:08 +08:00
|
|
|
|
localaddr->sin_addr = natAddr;
|
2000-09-21 16:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-08-14 16:30:08 +08:00
|
|
|
|
}
|
2000-09-21 16:46:14 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
2011-08-24 14:07:36 +08:00
|
|
|
|
result = Curl_base64_encode(conn->data, (char *)adat.dat, adat.length,
|
2011-08-24 19:58:37 +08:00
|
|
|
|
&p, &base64_sz);
|
2011-08-24 14:07:36 +08:00
|
|
|
|
if(result) {
|
|
|
|
|
Curl_failf(data, "base64-encoding: %s", curl_easy_strerror(result));
|
2001-08-14 16:30:08 +08:00
|
|
|
|
return AUTH_CONTINUE;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-03 18:25:31 +08:00
|
|
|
|
result = Curl_ftpsendf(conn, "ADAT %s", p);
|
|
|
|
|
|
|
|
|
|
free(p);
|
|
|
|
|
|
|
|
|
|
if(result)
|
2001-10-31 23:06:38 +08:00
|
|
|
|
return -2;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
|
2002-12-03 18:25:31 +08:00
|
|
|
|
if(Curl_GetFTPResponse(&nread, conn, NULL))
|
2001-10-02 06:31:43 +08:00
|
|
|
|
return -1;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
|
2011-07-05 04:10:32 +08:00
|
|
|
|
if(data->state.buffer[0] != '2') {
|
2002-01-04 17:52:44 +08:00
|
|
|
|
Curl_failf(data, "Server didn't accept auth data");
|
2001-08-14 16:30:08 +08:00
|
|
|
|
return AUTH_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-04 17:52:44 +08:00
|
|
|
|
p = strstr(data->state.buffer, "ADAT=");
|
|
|
|
|
if(!p) {
|
|
|
|
|
Curl_failf(data, "Remote host didn't send adat reply");
|
2001-08-14 16:30:08 +08:00
|
|
|
|
return AUTH_ERROR;
|
|
|
|
|
}
|
|
|
|
|
p += 5;
|
2011-08-24 14:07:36 +08:00
|
|
|
|
result = Curl_base64_decode(p, &ptr, &len);
|
|
|
|
|
if(result) {
|
|
|
|
|
Curl_failf(data, "base64-decoding: %s", curl_easy_strerror(result));
|
|
|
|
|
return AUTH_ERROR;
|
|
|
|
|
}
|
2005-02-22 20:10:30 +08:00
|
|
|
|
if(len > sizeof(adat.dat)-1) {
|
|
|
|
|
free(ptr);
|
2011-08-24 14:07:36 +08:00
|
|
|
|
ptr = NULL;
|
|
|
|
|
len = 0;
|
2005-02-22 20:10:30 +08:00
|
|
|
|
}
|
|
|
|
|
if(!len || !ptr) {
|
2002-01-04 17:52:44 +08:00
|
|
|
|
Curl_failf(data, "Failed to decode base64 from server");
|
2001-08-14 16:30:08 +08:00
|
|
|
|
return AUTH_ERROR;
|
|
|
|
|
}
|
2005-02-22 20:10:30 +08:00
|
|
|
|
memcpy((char *)adat.dat, ptr, len);
|
|
|
|
|
free(ptr);
|
2001-08-14 16:30:08 +08:00
|
|
|
|
adat.length = len;
|
2004-06-24 15:43:48 +08:00
|
|
|
|
ret = krb_rd_safe(adat.dat, adat.length, &d->key,
|
|
|
|
|
(struct sockaddr_in *)hisctladdr,
|
2001-08-14 16:30:08 +08:00
|
|
|
|
(struct sockaddr_in *)myctladdr, &msg_data);
|
2002-01-04 17:52:44 +08:00
|
|
|
|
if(ret) {
|
2004-06-24 15:43:48 +08:00
|
|
|
|
Curl_failf(data, "Error reading reply from server: %s",
|
2002-01-04 17:52:44 +08:00
|
|
|
|
krb_get_err_text(ret));
|
2001-08-14 16:30:08 +08:00
|
|
|
|
return AUTH_ERROR;
|
|
|
|
|
}
|
|
|
|
|
krb_get_int(msg_data.app_data, &cs, 4, 0);
|
2002-01-04 17:52:44 +08:00
|
|
|
|
if(cs - checksum != 1) {
|
|
|
|
|
Curl_failf(data, "Bad checksum returned from server");
|
2001-08-14 16:30:08 +08:00
|
|
|
|
return AUTH_ERROR;
|
|
|
|
|
}
|
|
|
|
|
return AUTH_OK;
|
2000-09-21 16:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-17 18:12:51 +08:00
|
|
|
|
struct Curl_sec_client_mech Curl_krb4_client_mech = {
|
2000-09-21 16:46:14 +08:00
|
|
|
|
"KERBEROS_V4",
|
|
|
|
|
sizeof(struct krb4_data),
|
|
|
|
|
NULL, /* init */
|
|
|
|
|
krb4_auth,
|
|
|
|
|
NULL, /* end */
|
|
|
|
|
krb4_check_prot,
|
|
|
|
|
krb4_overhead,
|
|
|
|
|
krb4_encode,
|
|
|
|
|
krb4_decode
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-18 16:00:37 +08:00
|
|
|
|
static enum protection_level
|
|
|
|
|
krb4_set_command_prot(struct connectdata *conn, enum protection_level level)
|
|
|
|
|
{
|
|
|
|
|
enum protection_level old = conn->command_prot;
|
2010-11-14 06:42:34 +08:00
|
|
|
|
DEBUGASSERT(level > PROT_NONE && level < PROT_LAST);
|
2010-10-18 16:00:37 +08:00
|
|
|
|
conn->command_prot = level;
|
|
|
|
|
return old;
|
|
|
|
|
}
|
|
|
|
|
|
2002-12-03 18:25:31 +08:00
|
|
|
|
CURLcode Curl_krb_kauth(struct connectdata *conn)
|
2000-09-21 16:46:14 +08:00
|
|
|
|
{
|
2001-08-14 16:30:08 +08:00
|
|
|
|
des_cblock key;
|
|
|
|
|
des_key_schedule schedule;
|
|
|
|
|
KTEXT_ST tkt, tktcopy;
|
|
|
|
|
char *name;
|
|
|
|
|
char *p;
|
|
|
|
|
char passwd[100];
|
2011-08-24 14:07:36 +08:00
|
|
|
|
size_t tmp = 0;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
ssize_t nread;
|
2010-11-14 04:01:33 +08:00
|
|
|
|
enum protection_level save;
|
2002-12-03 18:25:31 +08:00
|
|
|
|
CURLcode result;
|
2005-02-22 20:10:30 +08:00
|
|
|
|
unsigned char *ptr;
|
2011-08-24 14:07:36 +08:00
|
|
|
|
size_t base64_sz = 0;
|
2000-09-21 16:46:14 +08:00
|
|
|
|
|
2010-11-14 06:42:34 +08:00
|
|
|
|
save = krb4_set_command_prot(conn, PROT_PRIVATE);
|
2001-08-14 16:30:08 +08:00
|
|
|
|
|
2003-07-20 07:56:33 +08:00
|
|
|
|
result = Curl_ftpsendf(conn, "SITE KAUTH %s", conn->user);
|
2002-12-03 18:25:31 +08:00
|
|
|
|
|
|
|
|
|
if(result)
|
|
|
|
|
return result;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
|
2002-12-03 18:25:31 +08:00
|
|
|
|
result = Curl_GetFTPResponse(&nread, conn, NULL);
|
|
|
|
|
if(result)
|
|
|
|
|
return result;
|
2000-09-21 16:46:14 +08:00
|
|
|
|
|
2011-07-05 04:10:32 +08:00
|
|
|
|
if(conn->data->state.buffer[0] != '3') {
|
2010-10-18 16:00:37 +08:00
|
|
|
|
krb4_set_command_prot(conn, save);
|
2003-01-27 22:19:22 +08:00
|
|
|
|
return CURLE_FTP_WEIRD_SERVER_REPLY;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2001-08-31 06:59:58 +08:00
|
|
|
|
p = strstr(conn->data->state.buffer, "T=");
|
2001-08-14 16:30:08 +08:00
|
|
|
|
if(!p) {
|
2002-01-04 17:52:44 +08:00
|
|
|
|
Curl_failf(conn->data, "Bad reply from server");
|
2010-10-18 16:00:37 +08:00
|
|
|
|
krb4_set_command_prot(conn, save);
|
2002-12-03 18:25:31 +08:00
|
|
|
|
return CURLE_FTP_WEIRD_SERVER_REPLY;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p += 2;
|
2011-08-24 14:07:36 +08:00
|
|
|
|
result = Curl_base64_decode(p, &ptr, &tmp);
|
|
|
|
|
if(result) {
|
|
|
|
|
Curl_failf(conn->data, "base64-decoding: %s", curl_easy_strerror(result));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2005-02-22 20:20:30 +08:00
|
|
|
|
if(tmp >= sizeof(tkt.dat)) {
|
2005-02-22 20:10:30 +08:00
|
|
|
|
free(ptr);
|
2011-08-24 14:07:36 +08:00
|
|
|
|
ptr = NULL;
|
|
|
|
|
tmp = 0;
|
2005-02-22 20:10:30 +08:00
|
|
|
|
}
|
2005-02-22 20:20:30 +08:00
|
|
|
|
if(!tmp || !ptr) {
|
2008-01-16 07:19:02 +08:00
|
|
|
|
Curl_failf(conn->data, "Failed to decode base64 in reply");
|
2010-10-18 16:00:37 +08:00
|
|
|
|
krb4_set_command_prot(conn, save);
|
2002-12-03 18:25:31 +08:00
|
|
|
|
return CURLE_FTP_WEIRD_SERVER_REPLY;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
}
|
2005-02-22 20:10:30 +08:00
|
|
|
|
memcpy((char *)tkt.dat, ptr, tmp);
|
|
|
|
|
free(ptr);
|
2001-08-14 16:30:08 +08:00
|
|
|
|
tkt.length = tmp;
|
|
|
|
|
tktcopy.length = tkt.length;
|
2004-06-24 15:43:48 +08:00
|
|
|
|
|
2001-08-31 06:59:58 +08:00
|
|
|
|
p = strstr(conn->data->state.buffer, "P=");
|
2001-08-14 16:30:08 +08:00
|
|
|
|
if(!p) {
|
2002-01-04 17:52:44 +08:00
|
|
|
|
Curl_failf(conn->data, "Bad reply from server");
|
2010-10-18 16:00:37 +08:00
|
|
|
|
krb4_set_command_prot(conn, save);
|
2002-12-03 18:25:31 +08:00
|
|
|
|
return CURLE_FTP_WEIRD_SERVER_REPLY;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
}
|
|
|
|
|
name = p + 2;
|
|
|
|
|
for(; *p && *p != ' ' && *p != '\r' && *p != '\n'; p++);
|
|
|
|
|
*p = 0;
|
|
|
|
|
|
2003-07-21 17:19:48 +08:00
|
|
|
|
des_string_to_key (conn->passwd, &key);
|
2001-08-14 16:30:08 +08:00
|
|
|
|
des_key_sched(&key, schedule);
|
2004-06-24 15:43:48 +08:00
|
|
|
|
|
2003-01-27 22:19:22 +08:00
|
|
|
|
des_pcbc_encrypt((void *)tkt.dat, (void *)tktcopy.dat,
|
2001-08-14 16:30:08 +08:00
|
|
|
|
tkt.length,
|
|
|
|
|
schedule, &key, DES_DECRYPT);
|
2007-11-07 17:21:35 +08:00
|
|
|
|
if(strcmp ((char*)tktcopy.dat + 8,
|
2001-08-14 16:30:08 +08:00
|
|
|
|
KRB_TICKET_GRANTING_TICKET) != 0) {
|
2003-01-27 22:19:22 +08:00
|
|
|
|
afs_string_to_key(passwd,
|
2004-04-29 04:34:04 +08:00
|
|
|
|
krb_realmofhost(conn->host.name),
|
2003-01-27 22:19:22 +08:00
|
|
|
|
&key);
|
|
|
|
|
des_key_sched(&key, schedule);
|
|
|
|
|
des_pcbc_encrypt((void *)tkt.dat, (void *)tktcopy.dat,
|
2001-08-14 16:30:08 +08:00
|
|
|
|
tkt.length,
|
|
|
|
|
schedule, &key, DES_DECRYPT);
|
|
|
|
|
}
|
|
|
|
|
memset(key, 0, sizeof(key));
|
|
|
|
|
memset(schedule, 0, sizeof(schedule));
|
|
|
|
|
memset(passwd, 0, sizeof(passwd));
|
2011-08-24 14:07:36 +08:00
|
|
|
|
result = Curl_base64_encode(conn->data, (char *)tktcopy.dat, tktcopy.length,
|
2011-08-24 19:58:37 +08:00
|
|
|
|
&p, &base64_sz);
|
2011-08-24 14:07:36 +08:00
|
|
|
|
if(result) {
|
|
|
|
|
Curl_failf(conn->data, "base64-encoding: %s", curl_easy_strerror(result));
|
2010-10-18 16:00:37 +08:00
|
|
|
|
krb4_set_command_prot(conn, save);
|
2011-08-24 14:07:36 +08:00
|
|
|
|
return result;
|
2001-08-14 16:30:08 +08:00
|
|
|
|
}
|
|
|
|
|
memset (tktcopy.dat, 0, tktcopy.length);
|
|
|
|
|
|
2002-12-03 18:25:31 +08:00
|
|
|
|
result = Curl_ftpsendf(conn, "SITE KAUTH %s %s", name, p);
|
2001-08-14 16:30:08 +08:00
|
|
|
|
free(p);
|
2002-12-03 18:25:31 +08:00
|
|
|
|
if(result)
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
result = Curl_GetFTPResponse(&nread, conn, NULL);
|
|
|
|
|
if(result)
|
|
|
|
|
return result;
|
2010-10-18 16:00:37 +08:00
|
|
|
|
krb4_set_command_prot(conn, save);
|
2002-12-03 18:25:31 +08:00
|
|
|
|
|
|
|
|
|
return CURLE_OK;
|
2000-09-21 16:46:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2003-12-02 21:27:29 +08:00
|
|
|
|
#endif /* HAVE_KRB4 */
|
2002-06-11 19:13:01 +08:00
|
|
|
|
#endif /* CURL_DISABLE_FTP */
|