diff-tree a30a4defe933ca15aea4986535664774520ec9fa (from f09c91543dc84206a7a82db62bab09b8a52da44a) Author: Michael Richardson Date: Fri Nov 25 14:18:37 2005 -0500 fixes for gcc 4.xx (cherry picked from bfbd2c3c96ffc17453427ea3ea62c70572be5cae commit) diff --git a/aaa.c b/aaa.c --- a/aaa.c +++ b/aaa.c @@ -23,11 +23,11 @@ extern void bufferDump (char *, int); /* FIXME: Accounting? */ -static struct addr_ent *uaddr[ADDR_HASH_SIZE]; +struct addr_ent *uaddr[ADDR_HASH_SIZE]; void init_addr () { int x; for (x = 0; x < ADDR_HASH_SIZE; x++) @@ -45,11 +45,11 @@ static int ip_used (unsigned int addr) tmp = tmp->next; } return 0; } -void mk_challenge (char *c, int length) +void mk_challenge (unsigned char *c, int length) { get_entropy(c, length); /* int x; int *s = (int *) c; @@ -131,11 +131,11 @@ unsigned int get_addr (struct iprange *i ipr = ipr->next; } return 0; } -int get_secret (char *us, char *them, char *secret, int size) +int get_secret (char *us, char *them, unsigned char *secret, int size) { FILE *f; char buf[STRLEN]; char *u, *t, *s; int num = 0; @@ -204,11 +204,11 @@ int get_secret (char *us, char *them, ch #ifdef DEBUG_AUTH l2tp_log (LOG_DEBUG, "%s: we are '%s', they are '%s', secret is '%s'\n", __FUNCTION__, u, t, s); #endif - strncpy (secret, s, size); + strncpy ((char *)secret, s, size); fclose(f); return -1; } } fclose(f); @@ -249,10 +249,11 @@ int handle_challenge (struct tunnel *t, if (t->lac->peername[0]) them = t->lac->peername; else them = t->hostname; } + if (!get_secret (us, them, chal->secret, sizeof (chal->secret))) { l2tp_log (LOG_DEBUG, "%s: no secret found for us='%s' and them='%s'\n", __FUNCTION__, us, them); return -1; @@ -270,11 +271,11 @@ int handle_challenge (struct tunnel *t, #endif memset (chal->response, 0, MD_SIG_SIZE); MD5Init (&chal->md5); MD5Update (&chal->md5, &chal->ss, 1); - MD5Update (&chal->md5, chal->secret, strlen (chal->secret)); + MD5Update (&chal->md5, chal->secret, strlen ((char *)chal->secret)); MD5Update (&chal->md5, chal->challenge, chal->chal_len); MD5Final (chal->response, &chal->md5); #ifdef DEBUG_AUTH l2tp_log (LOG_DEBUG, "response is %X%X%X%X to '%s' and %X%X%X%X, %d\n", *((int *) &chal->response[0]), @@ -366,11 +367,11 @@ void encrypt_avp (struct buffer *buf, _u struct avp_hdr *new_hdr = (struct avp_hdr *) (buf->start + buf->len - len); struct avp_hdr *old_hdr = (struct avp_hdr *) (buf->start + buf->len - len + 2); _u16 length, flags, attr; /* New length, old flags */ - char *ptr, *end; + unsigned char *ptr, *end; int cnt; unsigned char digest[MD_SIG_SIZE]; unsigned char *previous_segment; /* FIXME: Should I pad more randomly? Right now I pad to nearest 16 bytes */ @@ -390,17 +391,17 @@ void encrypt_avp (struct buffer *buf, _u /* Back to the beginning of real data, including the original length AVP */ MD5Init (&t->chal_them.md5); MD5Update (&t->chal_them.md5, (void *) &attr, 2); MD5Update (&t->chal_them.md5, t->chal_them.secret, - strlen (t->chal_them.secret)); + strlen ((char *)t->chal_them.secret)); MD5Update (&t->chal_them.md5, t->chal_them.vector, VECTOR_SIZE); MD5Final (digest, &t->chal_them.md5); /* Though not a "MUST" in the spec, our subformat length is always a multiple of 16 */ - ptr = ((char *) new_hdr) + sizeof (struct avp_hdr); - end = ((char *) new_hdr) + length; + ptr = ((unsigned char *) new_hdr) + sizeof (struct avp_hdr); + end = ((unsigned char *) new_hdr) + length; previous_segment = ptr; while (ptr < end) { #if DEBUG_HIDDEN l2tp_log (LOG_DEBUG, "%s: The digest to be XOR'ed\n", __FUNCTION__); @@ -418,11 +419,11 @@ void encrypt_avp (struct buffer *buf, _u #endif if (ptr < end) { MD5Init (&t->chal_them.md5); MD5Update (&t->chal_them.md5, t->chal_them.secret, - strlen (t->chal_them.secret)); + strlen ((char *)t->chal_them.secret)); MD5Update (&t->chal_them.md5, previous_segment, MD_SIG_SIZE); MD5Final (digest, &t->chal_them.md5); } previous_segment = ptr; } @@ -433,17 +434,17 @@ int decrypt_avp (char *buf, struct tunne /* Decrypts a hidden AVP pointed to by buf. The new header will be exptected to be two characters offset from the old */ int cnt = 0; int len, olen, flags; - char digest[MD_SIG_SIZE]; + unsigned char digest[MD_SIG_SIZE]; char *ptr, *end; _u16 attr; struct avp_hdr *old_hdr = (struct avp_hdr *) buf; struct avp_hdr *new_hdr = (struct avp_hdr *) (buf + 2); int saved_segment_len; /* maybe less 16; may be used if the cipher is longer than 16 octets */ - char saved_segment[MD_SIG_SIZE]; + unsigned char saved_segment[MD_SIG_SIZE]; ptr = ((char *) old_hdr) + sizeof (struct avp_hdr); olen = old_hdr->length & 0x0FFF; end = buf + olen; if (!t->chal_us.vector) { @@ -456,11 +457,11 @@ int decrypt_avp (char *buf, struct tunne have to be more careful than when encrypting */ attr = ntohs (old_hdr->attr); MD5Init (&t->chal_us.md5); MD5Update (&t->chal_us.md5, (void *) &attr, 2); MD5Update (&t->chal_us.md5, t->chal_us.secret, - strlen (t->chal_us.secret)); + strlen ((char *)t->chal_us.secret)); MD5Update (&t->chal_us.md5, t->chal_us.vector, t->chal_us.vector_len); MD5Final (digest, &t->chal_us.md5); #ifdef DEBUG_HIDDEN l2tp_log (LOG_DEBUG, "attribute is %d and challenge is: ", attr); print_challenge (&t->chal_us); @@ -471,11 +472,11 @@ int decrypt_avp (char *buf, struct tunne { if (cnt >= MD_SIG_SIZE) { MD5Init (&t->chal_us.md5); MD5Update (&t->chal_us.md5, t->chal_us.secret, - strlen (t->chal_us.secret)); + strlen ((char *)t->chal_us.secret)); MD5Update (&t->chal_us.md5, saved_segment, MD_SIG_SIZE); MD5Final (digest, &t->chal_us.md5); cnt = 0; } /* at the beginning of each segment, we save the current segment (16 octets or less) of cipher diff --git a/aaa.h b/aaa.h --- a/aaa.h +++ b/aaa.h @@ -50,7 +50,7 @@ extern struct lns *get_lns (struct tunne extern unsigned int get_addr (struct iprange *); extern void reserve_addr (unsigned int); extern void unreserve_addr (unsigned int); extern void init_addr (); extern int handle_challenge (struct tunnel *, struct challenge *); -extern void mk_challenge (char *, int); +extern void mk_challenge (unsigned char *, int); #endif diff --git a/avp.h b/avp.h --- a/avp.h +++ b/avp.h @@ -112,11 +112,11 @@ extern int ignore_avp (struct tunnel *, extern int seq_reqd_avp (struct tunnel *, struct call *, void *, int); extern int challenge_avp (struct tunnel *, struct call *, void *, int); extern int chalresp_avp (struct tunnel *, struct call *, void *, int); extern int rand_vector_avp (struct tunnel *, struct call *, void *, int); -extern int add_challenge_avp (struct buffer *, char *, int); +extern int add_challenge_avp (struct buffer *, unsigned char *, int); extern int add_avp_rws (struct buffer *, _u16); extern int add_tunnelid_avp (struct buffer *, _u16); extern int add_vendor_avp (struct buffer *); extern int add_hostname_avp (struct buffer *, const char *); extern int add_firmware_avp (struct buffer *); @@ -135,10 +135,10 @@ extern int add_callid_avp (struct buffer #else extern int add_callid_avp (struct buffer *, _u16); #endif extern int add_ppd_avp (struct buffer *, _u16); extern int add_seqreqd_avp (struct buffer *); -extern int add_chalresp_avp (struct buffer *, char *, int); -extern int add_randvect_avp (struct buffer *, char *, int); +extern int add_chalresp_avp (struct buffer *, unsigned char *, int); +extern int add_randvect_avp (struct buffer *, unsigned char *, int); extern int add_minbps_avp (struct buffer *buf, int speed); /* jz: needed for outgoing call */ extern int add_maxbps_avp (struct buffer *buf, int speed); /* jz: needed for outgoing call */ extern int add_number_avp (struct buffer *buf, char *no); /* jz: needed for outgoing call */ diff --git a/avpsend.c b/avpsend.c --- a/avpsend.c +++ b/avpsend.c @@ -125,27 +125,27 @@ int add_avp_rws (struct buffer *buf, _u1 ptr->s0 = htons (rws); buf->len += 0x8; return 0; } -int add_challenge_avp (struct buffer *buf, char *c, int len) +int add_challenge_avp (struct buffer *buf, unsigned char *c, int len) { add_header(buf, (0x6 + len), 0xB); memcpy((char *) (buf->start + buf->len + sizeof(struct avp_hdr)), c, len); buf->len += 0x6 + len; return 0; } -int add_chalresp_avp (struct buffer *buf, char *c, int len) +int add_chalresp_avp (struct buffer *buf, unsigned char *c, int len) { add_header(buf, (0x6 + len), 0xD); memcpy((char *) (buf->start + buf->len + sizeof(struct avp_hdr)), c, len); buf->len += 0x6 + len; return 0; } -int add_randvect_avp (struct buffer *buf, char *c, int len) +int add_randvect_avp (struct buffer *buf, unsigned char *c, int len) { add_header(buf, (0x6 + len), 0x24); memcpy((char *) (buf->start + buf->len + sizeof(struct avp_hdr)), c, len); buf->len += 0x6 + len; return 0; diff --git a/call.c b/call.c --- a/call.c +++ b/call.c @@ -502,11 +502,11 @@ void destroy_call (struct call *c) } struct call *new_call (struct tunnel *parent) { - char entropy_buf[2] = "\0"; + unsigned char entropy_buf[2] = "\0"; struct call *tmp = malloc (sizeof (struct call)); if (!tmp) return NULL; tmp->tx_pkts = 0; diff --git a/l2tp.h b/l2tp.h --- a/l2tp.h +++ b/l2tp.h @@ -214,11 +214,11 @@ extern void control_xmit (void *); extern int ppd; extern int switch_io; /* jz */ extern int control_fd; extern int start_pppd (struct call *c, struct ppp_opts *); extern void magic_lac_dial (void *); -extern int get_entropy (char *, int); +extern int get_entropy (unsigned char *, int); #ifndef MIN #define MIN(a,b) (((a)<(b)) ? (a) : (b)) #endif #endif diff --git a/l2tpd.c b/l2tpd.c --- a/l2tpd.c +++ b/l2tpd.c @@ -731,11 +731,11 @@ void lac_disconnect (int tid) } struct tunnel *new_tunnel () { struct tunnel *tmp = malloc (sizeof (struct tunnel)); - char entropy_buf[2] = "\0"; + unsigned char entropy_buf[2] = "\0"; if (!tmp) return NULL; tmp->control_seq_num = 0; tmp->control_rec_seq_num = 0; tmp->cLr = 0; diff --git a/misc.c b/misc.c --- a/misc.c +++ b/misc.c @@ -90,22 +90,22 @@ inline void recycle_buf (struct buffer * b->start = b->rstart; b->len = b->maxlen; } #define bufferDumpWIDTH 16 -void bufferDump (char *buf, int buflen) +void bufferDump (unsigned char *buf, int buflen) { int i = 0, j = 0; /* we need TWO characters to DISPLAY ONE byte */ - unsigned char line[2 * bufferDumpWIDTH + 1], *c; + char line[2 * bufferDumpWIDTH + 1], *c; for (i = 0; i < buflen / bufferDumpWIDTH; i++) { c = line; for (j = 0; j < bufferDumpWIDTH; j++) { - sprintf (c, "%02x ", (buf[i * bufferDumpWIDTH + j]) & 0xff); + sprintf (c, "%02x ", (buf[i * bufferDumpWIDTH + j]) & 0xff); c++; c++; /* again two characters to display ONE byte */ } *c = '\0'; l2tp_log (LOG_WARN, "%s: buflen=%d, buffer[%d]: *%s*\n", __FUNCTION__, @@ -242,11 +242,11 @@ void opt_destroy (struct ppp_opts *optio int get_egd_entropy(char *buf, int count) { return -1; } -int get_sys_entropy(char *buf, int count) +int get_sys_entropy(unsigned char *buf, int count) { /* * This way of filling buf with rand() generated data is really * fairly inefficient from a function call point of view...rand() * returns four bytes of data (on most systems, sizeof(int)) @@ -263,11 +263,11 @@ int get_sys_entropy(char *buf, int count bufferDump (buf, count); #endif return count; } -int get_dev_entropy(char *buf, int count) +int get_dev_entropy(unsigned char *buf, int count) { int devrandom; ssize_t entropy_amount; devrandom = open ("/dev/urandom", O_RDONLY | O_NONBLOCK); @@ -283,11 +283,11 @@ int get_dev_entropy(char *buf, int count entropy_amount = read(devrandom, buf, count); close(devrandom); return entropy_amount; } -int get_entropy (char *buf, int count) +int get_entropy (unsigned char *buf, int count) { if (rand_source == RAND_SYS) { return get_sys_entropy(buf, count); } diff --git a/network.c b/network.c --- a/network.c +++ b/network.c @@ -33,11 +33,11 @@ int kernel_support; /* Kerne int init_network (void) { long arg; - int length = sizeof (server); + unsigned int length = sizeof (server); gethostname (hostname, sizeof (hostname)); server.sin_family = AF_INET; server.sin_addr.s_addr = gconfig.listenaddr; server.sin_port = htons (gconfig.port); if ((server_socket = socket (PF_INET, SOCK_DGRAM, 0)) < 0) @@ -304,21 +304,25 @@ void network_thread () { /* * We loop forever waiting on either data from the ppp drivers or from * our network socket. Control handling is no longer done here. */ - int fromlen; /* Length of the address */ + unsigned int fromlen; /* Length of the address */ int tunnel, call; /* Tunnel and call */ int recvsize; /* Length of data received */ struct buffer *buf; /* Payload buffer */ struct call *c, *sc; /* Call to send this off to */ struct tunnel *st; /* Tunnel */ fd_set readfds; /* Descriptors to watch for reading */ int max; /* Highest fd */ struct timeval tv; /* Timeout for select */ /* This one buffer can be recycled for everything except control packets */ buf = new_buf (MAX_RECV_SIZE); + + tunnel = 0; + call = 0; + for (;;) { max = build_fdset (&readfds); tv.tv_sec = 1; tv.tv_usec = 0;