From: Roy Marples Date: Wed, 5 Oct 2016 11:03:32 +0000 (+0000) Subject: Auth should work on void rather than a type. X-Git-Tag: v7.0.0-beta1~151 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4595ab14ff539001ca3874cb798073a4c45bc56;p=thirdparty%2Fdhcpcd.git Auth should work on void rather than a type. --- diff --git a/auth.c b/auth.c index 4a6d7ea6..fb8cca73 100644 --- a/auth.c +++ b/auth.c @@ -104,9 +104,10 @@ dhcp_auth_reset(struct authstate *state) */ const struct token * dhcp_auth_validate(struct authstate *state, const struct auth *auth, - const uint8_t *m, size_t mlen, int mp, int mt, - const uint8_t *data, size_t dlen) + const void *vm, size_t mlen, int mp, int mt, + const void *vdata, size_t dlen) { + const uint8_t *m, *data; uint8_t protocol, algorithm, rdm, *mm, type; uint64_t replay; uint32_t secretid; @@ -121,6 +122,8 @@ dhcp_auth_validate(struct authstate *state, const struct auth *auth, return NULL; } + m = vm; + data = vdata; /* Ensure that d is inside m which *may* not be the case for DHPCPv4 */ if (data < m || data > m + mlen || data + dlen > m + mlen) { errno = ERANGE; @@ -473,13 +476,13 @@ get_next_rdm_monotonic(struct auth *auth) */ ssize_t dhcp_auth_encode(struct auth *auth, const struct token *t, - uint8_t *m, size_t mlen, int mp, int mt, - uint8_t *data, size_t dlen) + void *vm, size_t mlen, int mp, int mt, + void *vdata, size_t dlen) { uint64_t rdm; uint8_t hmac[HMAC_LENGTH]; time_t now; - uint8_t hops, *p, info; + uint8_t hops, *p, info, *m, *data; uint32_t giaddr, secretid; if (auth->protocol == 0 && t == NULL) { @@ -538,7 +541,7 @@ dhcp_auth_encode(struct auth *auth, const struct token *t, /* Work out the auth area size. * We only need to do this for DISCOVER messages */ - if (data == NULL) { + if (vdata == NULL) { dlen = 1 + 1 + 1 + 8; switch(auth->protocol) { case AUTH_PROTO_TOKEN: @@ -562,6 +565,8 @@ dhcp_auth_encode(struct auth *auth, const struct token *t, } /* Ensure that d is inside m which *may* not be the case for DHPCPv4 */ + m = vm; + data = vdata; if (data < m || data > m + mlen || data + dlen > m + mlen) { errno = ERANGE; return -1; diff --git a/auth.h b/auth.h index cfc17df8..21c1664f 100644 --- a/auth.h +++ b/auth.h @@ -83,10 +83,10 @@ void dhcp_auth_reset(struct authstate *); const struct token * dhcp_auth_validate(struct authstate *, const struct auth *, - const uint8_t *, size_t, int, int, - const uint8_t *, size_t); + const void *, size_t, int, int, + const void *, size_t); ssize_t dhcp_auth_encode(struct auth *, const struct token *, - uint8_t *, size_t, int, int, - uint8_t *, size_t); + void *, size_t, int, int, + void *, size_t); #endif diff --git a/dhcp-common.c b/dhcp-common.c index ac9b1cd7..790b7607 100644 --- a/dhcp-common.c +++ b/dhcp-common.c @@ -1058,7 +1058,7 @@ dhcp_zero_index(struct dhcp_opt *opt) } size_t -dhcp_read_lease_fd(int fd, uint8_t **lease) +dhcp_read_lease_fd(int fd, void **lease) { uint8_t *buf, *nbuf; size_t len, new_len; diff --git a/dhcp-common.h b/dhcp-common.h index 61eccf18..1bdc36e7 100644 --- a/dhcp-common.h +++ b/dhcp-common.h @@ -118,6 +118,6 @@ size_t dhcp_envoption(struct dhcpcd_ctx *, const uint8_t *, size_t, struct dhcp_opt **), const uint8_t *od, size_t ol); void dhcp_zero_index(struct dhcp_opt *); -size_t dhcp_read_lease_fd(int, uint8_t **); +size_t dhcp_read_lease_fd(int, void **); #endif diff --git a/dhcp.c b/dhcp.c index f6e1d163..191156d7 100644 --- a/dhcp.c +++ b/dhcp.c @@ -1134,7 +1134,7 @@ read_lease(struct interface *ifp, struct bootp **bootp) int fd; bool fd_opened; struct dhcp_state *state = D_STATE(ifp); - uint8_t *lease; + struct bootp *lease; size_t bytes; uint8_t type; #ifdef AUTH @@ -1164,7 +1164,7 @@ read_lease(struct interface *ifp, struct bootp **bootp) logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'", ifp->name, state->leasefile); - bytes = dhcp_read_lease_fd(fd, &lease); + bytes = dhcp_read_lease_fd(fd, (void **)&lease); if (fd_opened) close(fd); if (bytes == 0) { @@ -3082,14 +3082,14 @@ rapidcommit: dhcp_arp_bind(ifp); } -static size_t -get_udp_data(uint8_t **data, uint8_t *udp) +static void * +get_udp_data(uint8_t *udp, size_t *len) { struct udp_bootp_packet *p; p = (struct udp_bootp_packet *)udp; - *data = udp + offsetof(struct udp_bootp_packet, bootp); - return ntohs(p->ip.ip_len) - sizeof(p->ip) - sizeof(p->udp); + *len = ntohs(p->ip.ip_len) - sizeof(p->ip) - sizeof(p->udp); + return udp + offsetof(struct udp_bootp_packet, bootp); } static int @@ -3148,7 +3148,7 @@ valid_udp_packet(uint8_t *data, size_t data_len, struct in_addr *from, static void dhcp_handlepacket(struct interface *ifp, uint8_t *data, size_t len, int flags) { - uint8_t *bootp; + struct bootp *bootp; struct in_addr from; int i; size_t udp_len; @@ -3187,7 +3187,7 @@ dhcp_handlepacket(struct interface *ifp, uint8_t *data, size_t len, int flags) * However some servers send a truncated vendor area. * dhcpcd can work fine without the vendor area being sent. */ - udp_len = get_udp_data(&bootp, data); + bootp = get_udp_data(data, &udp_len); /* udp_len must be correct because the values are checked in * valid_udp_packet(). */ if (udp_len < offsetof(struct bootp, vend)) { @@ -3198,10 +3198,13 @@ dhcp_handlepacket(struct interface *ifp, uint8_t *data, size_t len, int flags) } /* To make our IS_DHCP macro easy, ensure the vendor * area has at least 4 octets. */ - while (udp_len < offsetof(struct bootp, vend) + 4) - bootp[udp_len++] = '\0'; + len = udp_len - offsetof(struct bootp, vend); + while (len < 4) { + bootp->vend[len++] = '\0'; + udp_len++; + } - dhcp_handledhcp(ifp, (struct bootp *)bootp, udp_len, &from); + dhcp_handledhcp(ifp, bootp, udp_len, &from); } static void diff --git a/dhcp6.c b/dhcp6.c index 6e35a9fc..c0a4cc12 100644 --- a/dhcp6.c +++ b/dhcp6.c @@ -996,7 +996,7 @@ dhcp6_update_auth(struct interface *ifp, struct dhcp6_message *m, size_t len) state = D6_STATE(ifp); return dhcp_auth_encode(&ifp->options->auth, state->auth.token, - (uint8_t *)state->send, state->send_len, + state->send, state->send_len, 6, state->send->type, D6_OPTION_DATA(o), ntohs(o->len)); } @@ -2237,7 +2237,6 @@ dhcp6_readlease(struct interface *ifp, int validate) struct dhcp6_state *state; struct stat st; int fd; - uint8_t *lease; struct timespec acquired; time_t now; int retval; @@ -2264,9 +2263,7 @@ dhcp6_readlease(struct interface *ifp, int validate) if (fd == -1) return -1; retval = -1; - lease = NULL; - state->new_len = dhcp_read_lease_fd(fd, &lease); - state->new = (struct dhcp6_message *)lease; + state->new_len = dhcp_read_lease_fd(fd, (void **)&state->new); if (fd_opened) close(fd); if (state->new_len == 0) @@ -2313,7 +2310,7 @@ auth: o = dhcp6_getmoption(D6_OPTION_AUTH, state->new, state->new_len); if (o) { if (dhcp_auth_validate(&state->auth, &ifp->options->auth, - (uint8_t *)state->new, state->new_len, 6, state->new->type, + state->new, state->new_len, 6, state->new->type, D6_COPTION_DATA(o), ntohs(o->len)) == NULL) { logger(ifp->ctx, LOG_DEBUG, @@ -2848,7 +2845,7 @@ dhcp6_handledata(void *arg) auth = dhcp6_getmoption(D6_OPTION_AUTH, r, len); if (auth) { if (dhcp_auth_validate(&state->auth, &ifo->auth, - (uint8_t *)r, len, 6, r->type, + r, len, 6, r->type, D6_COPTION_DATA(auth), ntohs(auth->len)) == NULL) { logger(ifp->ctx, LOG_DEBUG, "dhcp_auth_validate: %m");