1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

fixed picky compiler warnings, unused arguments, const at proper places and

I also indented the source code to fit curl "standard"
This commit is contained in:
Daniel Stenberg 2001-08-14 08:30:08 +00:00
parent 0c063f85fc
commit 3d4bb3be22

View File

@ -47,6 +47,10 @@
#include <string.h> #include <string.h>
#include <krb.h> #include <krb.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h> /* for getpid() */
#endif
#include "ftp.h" #include "ftp.h"
#include "sendf.h" #include "sendf.h"
@ -105,9 +109,10 @@ size_t strlcpy (char *dst, const char *src, size_t dst_sz);
static int static int
krb4_check_prot(void *app_data, int level) krb4_check_prot(void *app_data, int level)
{ {
if(level == prot_confidential) app_data = NULL; /* prevent compiler warning */
return -1; if(level == prot_confidential)
return 0; return -1;
return 0;
} }
static int static int
@ -137,7 +142,11 @@ krb4_decode(void *app_data, void *buf, int len, int level,
static int static int
krb4_overhead(void *app_data, int level, int len) krb4_overhead(void *app_data, int level, int len)
{ {
return 31; /* no arguments are used, just init them to prevent compiler warnings */
app_data = NULL;
level = 0;
len = 0;
return 31;
} }
static int static int
@ -249,7 +258,7 @@ struct sec_server_mech krb4_server_mech = {
static int static int
mk_auth(struct krb4_data *d, KTEXT adat, mk_auth(struct krb4_data *d, KTEXT adat,
char *service, char *host, int checksum) const char *service, char *host, int checksum)
{ {
int ret; int ret;
CREDENTIALS cred; CREDENTIALS cred;
@ -274,110 +283,108 @@ mk_auth(struct krb4_data *d, KTEXT adat,
static int static int
krb4_auth(void *app_data, struct connectdata *conn) krb4_auth(void *app_data, struct connectdata *conn)
{ {
int ret; int ret;
char *p; char *p;
int len; int len;
KTEXT_ST adat; KTEXT_ST adat;
MSG_DAT msg_data; MSG_DAT msg_data;
int checksum; int checksum;
u_int32_t cs; u_int32_t cs;
struct krb4_data *d = app_data; struct krb4_data *d = app_data;
struct sockaddr_in *localaddr = (struct sockaddr_in *)LOCAL_ADDR; struct sockaddr_in *localaddr = (struct sockaddr_in *)LOCAL_ADDR;
#if 0 #if 0
struct sockaddr_in *remoteaddr = (struct sockaddr_in *)REMOTE_ADDR; struct sockaddr_in *remoteaddr = (struct sockaddr_in *)REMOTE_ADDR;
#endif #endif
char *host = conn->hp->h_name; char *host = conn->hp->h_name;
size_t nread; ssize_t nread;
int l = sizeof(local_addr); int l = sizeof(local_addr);
if(getsockname(conn->firstsocket, if(getsockname(conn->firstsocket,
(struct sockaddr *)LOCAL_ADDR, &l) < 0) (struct sockaddr *)LOCAL_ADDR, &l) < 0)
perror("getsockname()"); 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){
printf("%s\n", krb_get_err_text(ret));
return AUTH_CONTINUE;
}
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) {
printf("%s\n", krb_get_err_text(ret));
return AUTH_CONTINUE;
}
#ifdef HAVE_KRB_GET_OUR_IP_FOR_REALM #ifdef HAVE_KRB_GET_OUR_IP_FOR_REALM
if (krb_get_config_bool("nat_in_use")) { if (krb_get_config_bool("nat_in_use")) {
struct in_addr natAddr; struct in_addr natAddr;
if (krb_get_our_ip_for_realm(krb_realmofhost(host), if (krb_get_our_ip_for_realm(krb_realmofhost(host),
&natAddr) != KSUCCESS &natAddr) != KSUCCESS
&& krb_get_our_ip_for_realm(NULL, &natAddr) != KSUCCESS) && krb_get_our_ip_for_realm(NULL, &natAddr) != KSUCCESS)
printf("Can't get address for realm %s\n", printf("Can't get address for realm %s\n",
krb_realmofhost(host)); krb_realmofhost(host));
else { else {
if (natAddr.s_addr != localaddr->sin_addr.s_addr) { if (natAddr.s_addr != localaddr->sin_addr.s_addr) {
printf("Using NAT IP address (%s) for kerberos 4\n", printf("Using NAT IP address (%s) for kerberos 4\n",
(char *)inet_ntoa(natAddr)); (char *)inet_ntoa(natAddr));
localaddr->sin_addr = natAddr; localaddr->sin_addr = natAddr;
/* /*
* This not the best place to do this, but it * This not the best place to do this, but it is here we know that
* is here we know that (probably) NAT is in * (probably) NAT is in use! */
* use!
*/
/*passivemode = 1;***/ /*passivemode = 1;***/
/*printf("Setting: Passive mode on.\n");***/ /*printf("Setting: Passive mode on.\n");***/
}
} }
} }
}
#endif #endif
/*printf("Local address is %s\n", inet_ntoa(localaddr->sin_addr));***/ /*printf("Local address is %s\n", inet_ntoa(localaddr->sin_addr));***/
/*printf("Remote address is %s\n", inet_ntoa(remoteaddr->sin_addr));***/ /*printf("Remote address is %s\n", inet_ntoa(remoteaddr->sin_addr));***/
if(Curl_base64_encode(adat.dat, adat.length, &p) < 0) { if(Curl_base64_encode(adat.dat, adat.length, &p) < 0) {
printf("Out of memory base64-encoding.\n"); printf("Out of memory base64-encoding.\n");
return AUTH_CONTINUE; return AUTH_CONTINUE;
} }
/*ret = command("ADAT %s", p)*/
Curl_ftpsendf(conn->firstsocket, conn, "ADAT %s", p);
/* wait for feedback */
nread = Curl_GetFTPResponse(conn->firstsocket,
conn->data->buffer, conn, NULL);
if(nread < 0)
return /*CURLE_OPERATION_TIMEOUTED*/-1;
free(p);
if(/*ret != COMPLETE*/conn->data->buffer[0] != '2'){ Curl_ftpsendf(conn->firstsocket, conn, "ADAT %s", p);
printf("Server didn't accept auth data.\n");
return AUTH_ERROR;
}
p = strstr(/*reply_string*/conn->data->buffer, "ADAT="); nread = Curl_GetFTPResponse(conn->firstsocket,
if(!p){ conn->data->buffer, conn, NULL);
printf("Remote host didn't send adat reply.\n"); if(nread < 0)
return AUTH_ERROR; return /*CURLE_OPERATION_TIMEOUTED*/-1;
} free(p);
p += 5;
len = Curl_base64_decode(p, adat.dat); if(/*ret != COMPLETE*/conn->data->buffer[0] != '2'){
if(len < 0){ printf("Server didn't accept auth data.\n");
printf("Failed to decode base64 from server.\n"); return AUTH_ERROR;
return AUTH_ERROR; }
}
adat.length = len; p = strstr(conn->data->buffer, "ADAT=");
ret = krb_rd_safe(adat.dat, adat.length, &d->key, if(!p){
(struct sockaddr_in *)hisctladdr, printf("Remote host didn't send adat reply.\n");
(struct sockaddr_in *)myctladdr, &msg_data); return AUTH_ERROR;
if(ret){ }
printf("Error reading reply from server: %s.\n", p += 5;
krb_get_err_text(ret)); len = Curl_base64_decode(p, adat.dat);
return AUTH_ERROR; if(len < 0){
} printf("Failed to decode base64 from server.\n");
krb_get_int(msg_data.app_data, &cs, 4, 0); return AUTH_ERROR;
if(cs - checksum != 1){ }
printf("Bad checksum returned from server.\n"); adat.length = len;
return AUTH_ERROR; ret = krb_rd_safe(adat.dat, adat.length, &d->key,
} (struct sockaddr_in *)hisctladdr,
return AUTH_OK; (struct sockaddr_in *)myctladdr, &msg_data);
if(ret){
printf("Error reading reply from server: %s.\n",
krb_get_err_text(ret));
return AUTH_ERROR;
}
krb_get_int(msg_data.app_data, &cs, 4, 0);
if(cs - checksum != 1){
printf("Bad checksum returned from server.\n");
return AUTH_ERROR;
}
return AUTH_OK;
} }
struct sec_client_mech krb4_client_mech = { struct sec_client_mech krb4_client_mech = {
@ -396,105 +403,95 @@ struct sec_client_mech krb4_client_mech = {
void krb_kauth(struct connectdata *conn) void krb_kauth(struct connectdata *conn)
{ {
des_cblock key; des_cblock key;
des_key_schedule schedule; des_key_schedule schedule;
KTEXT_ST tkt, tktcopy; KTEXT_ST tkt, tktcopy;
char *name; char *name;
char *p; char *p;
char passwd[100]; char passwd[100];
int tmp; int tmp;
size_t nread; ssize_t nread;
int save; int save;
save = set_command_prot(conn, prot_private); save = set_command_prot(conn, prot_private);
/*ret = command("SITE KAUTH %s", name);***/
Curl_ftpsendf(conn->firstsocket, conn,
"SITE KAUTH %s", conn->data->user);
/* wait for feedback */
nread = Curl_GetFTPResponse(conn->firstsocket, conn->data->buffer,
conn, NULL);
if(nread < 0)
return /*CURLE_OPERATION_TIMEOUTED*/;
if(/*ret != CONTINUE*/conn->data->buffer[0] != '3'){ Curl_ftpsendf(conn->firstsocket, conn,
set_command_prot(conn, save); "SITE KAUTH %s", conn->data->user);
/*code = -1;***/
return;
}
p = strstr(/*reply_string***/conn->data->buffer, "T=");
if(!p){
printf("Bad reply from server.\n");
set_command_prot(conn, save);
/*code = -1;***/
return;
}
p += 2;
tmp = Curl_base64_decode(p, &tkt.dat);
if(tmp < 0){
printf("Failed to decode base64 in reply.\n");
set_command_prot(conn, save);
/*code = -1;***/
return;
}
tkt.length = tmp;
tktcopy.length = tkt.length;
p = strstr(/*reply_string***/conn->data->buffer, "P=");
if(!p){
printf("Bad reply from server.\n");
set_command_prot(conn, save);
/*code = -1;***/
return;
}
name = p + 2;
for(; *p && *p != ' ' && *p != '\r' && *p != '\n'; p++);
*p = 0;
#if 0 nread = Curl_GetFTPResponse(conn->firstsocket, conn->data->buffer,
snprintf(buf, sizeof(buf), "Password for %s:", name); conn, NULL);
if (des_read_pw_string (passwd, sizeof(passwd)-1, buf, 0)) if(nread < 0)
*passwd = '\0'; return /*CURLE_OPERATION_TIMEOUTED*/;
des_string_to_key (passwd, &key);
#else
des_string_to_key (conn->data->passwd, &key);
#endif
des_key_sched(&key, schedule); if(/*ret != CONTINUE*/conn->data->buffer[0] != '3'){
des_pcbc_encrypt((des_cblock*)tkt.dat, (des_cblock*)tktcopy.dat,
tkt.length,
schedule, &key, DES_DECRYPT);
if (strcmp ((char*)tktcopy.dat + 8,
KRB_TICKET_GRANTING_TICKET) != 0) {
afs_string_to_key (passwd,
krb_realmofhost(/*hostname***/conn->hp->h_name),
&key);
des_key_sched (&key, schedule);
des_pcbc_encrypt((des_cblock*)tkt.dat, (des_cblock*)tktcopy.dat,
tkt.length,
schedule, &key, DES_DECRYPT);
}
memset(key, 0, sizeof(key));
memset(schedule, 0, sizeof(schedule));
memset(passwd, 0, sizeof(passwd));
if(Curl_base64_encode(tktcopy.dat, tktcopy.length, &p) < 0) {
failf(conn->data, "Out of memory base64-encoding.\n");
set_command_prot(conn, save);
/*code = -1;***/
return;
}
memset (tktcopy.dat, 0, tktcopy.length);
/*ret = command("SITE KAUTH %s %s", name, p);***/
Curl_ftpsendf(conn->firstsocket, conn,
"SITE KAUTH %s %s", name, p);
/* wait for feedback */
nread = Curl_GetFTPResponse(conn->firstsocket, conn->data->buffer,
conn, NULL);
if(nread < 0)
return /*CURLE_OPERATION_TIMEOUTED*/;
free(p);
set_command_prot(conn, save); set_command_prot(conn, save);
/*code = -1;***/
return;
}
p = strstr(conn->data->buffer, "T=");
if(!p) {
printf("Bad reply from server.\n");
set_command_prot(conn, save);
return;
}
p += 2;
tmp = Curl_base64_decode(p, &tkt.dat);
if(tmp < 0) {
printf("Failed to decode base64 in reply.\n");
set_command_prot(conn, save);
return;
}
tkt.length = tmp;
tktcopy.length = tkt.length;
p = strstr(conn->data->buffer, "P=");
if(!p) {
printf("Bad reply from server.\n");
set_command_prot(conn, save);
return;
}
name = p + 2;
for(; *p && *p != ' ' && *p != '\r' && *p != '\n'; p++);
*p = 0;
des_string_to_key (conn->data->passwd, &key);
des_key_sched(&key, schedule);
des_pcbc_encrypt((des_cblock*)tkt.dat, (des_cblock*)tktcopy.dat,
tkt.length,
schedule, &key, DES_DECRYPT);
if (strcmp ((char*)tktcopy.dat + 8,
KRB_TICKET_GRANTING_TICKET) != 0) {
afs_string_to_key (passwd,
krb_realmofhost(/*hostname*/conn->hp->h_name),
&key);
des_key_sched (&key, schedule);
des_pcbc_encrypt((des_cblock*)tkt.dat, (des_cblock*)tktcopy.dat,
tkt.length,
schedule, &key, DES_DECRYPT);
}
memset(key, 0, sizeof(key));
memset(schedule, 0, sizeof(schedule));
memset(passwd, 0, sizeof(passwd));
if(Curl_base64_encode(tktcopy.dat, tktcopy.length, &p) < 0) {
failf(conn->data, "Out of memory base64-encoding.\n");
set_command_prot(conn, save);
return;
}
memset (tktcopy.dat, 0, tktcopy.length);
Curl_ftpsendf(conn->firstsocket, conn,
"SITE KAUTH %s %s", name, p);
nread = Curl_GetFTPResponse(conn->firstsocket, conn->data->buffer,
conn, NULL);
if(nread < 0)
return /*CURLE_OPERATION_TIMEOUTED*/;
free(p);
set_command_prot(conn, save);
} }
#endif /* KRB4 */ #endif /* KRB4 */