diff options
author | Denis Kenzior <denkenz@gmail.com> | 2010-04-13 14:16:29 -0500 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2010-04-13 14:21:16 -0500 |
commit | 18e5e26acb7f9e9f8bd90f755fc432bd5a9667ca (patch) | |
tree | bdc8a449510e9674fba149b2e6f9399ab8b62f14 | |
parent | 42f6e8ec6ecbf3c4ff74aa52f77cf5e39c4682eb (diff) | |
download | ofono-18e5e26acb7f9e9f8bd90f755fc432bd5a9667ca.tar.bz2 |
ppp: Remove auth_ functions from ppp_auth.c
These really serve no purpose right now as we use only CHAP. So they
only take up space and make the code harder to read. If we implement
1-3 auth protocols, then they're easier handled inside gatppp.c. If we
have more, then a proper auth driver framework is required.
-rw-r--r-- | gatchat/ppp.h | 23 | ||||
-rw-r--r-- | gatchat/ppp_auth.c | 120 |
2 files changed, 33 insertions, 110 deletions
diff --git a/gatchat/ppp.h b/gatchat/ppp.h index 565a9fa0..32542c91 100644 --- a/gatchat/ppp.h +++ b/gatchat/ppp.h @@ -34,6 +34,8 @@ enum ppp_phase { PPP_PHASE_TERMINATION, /* LCP Terminate phase */ }; +struct ppp_chap; + struct ppp_header { guint16 proto; guint8 info[0]; @@ -71,15 +73,6 @@ static inline guint16 __get_unaligned_short(const void *p) #define ppp_proto(packet) \ (get_host_short(packet + 2)) -struct auth_data { - guint16 proto; - gpointer proto_data; - void (*process_packet)(struct auth_data *data, guint8 *packet); - char *username; - char *password; - GAtPPP *ppp; -}; - struct ppp_net_data { GAtPPP *ppp; char *if_name; @@ -101,12 +94,6 @@ gboolean ppp_get_acfc(GAtPPP *ppp); struct pppcp_data * lcp_new(GAtPPP *ppp); void lcp_free(struct pppcp_data *lcp); void lcp_protocol_reject(struct pppcp_data *lcp, guint8 *packet, gsize len); -void auth_process_packet(struct auth_data *data, guint8 *new_packet); -void auth_set_credentials(struct auth_data *data, const char *username, - const char *passwd); -void auth_set_proto(struct auth_data *data, guint16 proto, guint8 method); -struct auth_data *auth_new(GAtPPP *ppp); -void auth_free(struct auth_data *auth); struct ppp_net_data *ppp_net_new(GAtPPP *ppp); void ppp_net_open(struct ppp_net_data *data); void ppp_net_process_packet(struct ppp_net_data *data, guint8 *packet); @@ -116,3 +103,9 @@ struct pppcp_data *ipcp_new(GAtPPP *ppp); void ipcp_free(struct pppcp_data *data); void ppp_connect_cb(GAtPPP *ppp, GAtPPPConnectStatus success, const char *ip, const char *dns1, const char *dns2); + +/* CHAP related functions */ +struct ppp_chap *ppp_chap_new(GAtPPP *ppp, guint8 method); +void ppp_chap_free(struct ppp_chap *chap); +void ppp_chap_process_packet(struct ppp_chap *chap, guint8 *new_packet); + diff --git a/gatchat/ppp_auth.c b/gatchat/ppp_auth.c index 3f69fa37..e794ad67 100644 --- a/gatchat/ppp_auth.c +++ b/gatchat/ppp_auth.c @@ -44,9 +44,9 @@ struct chap_header { guint8 data[0]; } __attribute__((packed)); -struct chap_data { +struct ppp_chap { guint8 method; - struct auth_data *auth; + GAtPPP *ppp; }; enum chap_code { @@ -56,37 +56,26 @@ enum chap_code { FAILURE }; -void auth_set_credentials(struct auth_data *data, const char *username, - const char *password) -{ - if (data == NULL) - return; - - g_free(data->username); - data->username = g_strdup(username); - - g_free(data->password); - data->password = g_strdup(password); -} - -static void chap_process_challenge(struct auth_data *auth, guint8 *packet) +static void chap_process_challenge(struct ppp_chap *chap, guint8 *packet) { struct chap_header *header = (struct chap_header *) packet; struct chap_header *response; - struct chap_data *data = auth->proto_data; GChecksum *checksum; - gchar *secret = data->auth->password; + const char *secret = g_at_ppp_get_password(chap->ppp); guint16 response_length; struct ppp_header *ppp_packet; gsize digest_len; /* create a checksum over id, secret, and challenge */ - checksum = g_checksum_new(data->method); + checksum = g_checksum_new(chap->method); if (!checksum) return; + g_checksum_update(checksum, &header->identifier, 1); + if (secret) g_checksum_update(checksum, (guchar *) secret, strlen(secret)); + g_checksum_update(checksum, &header->data[1], header->data[0]); /* transmit a response packet */ @@ -94,7 +83,7 @@ static void chap_process_challenge(struct auth_data *auth, guint8 *packet) * allocate space for the header, the checksum, and the ppp header, * and the value size byte */ - digest_len = g_checksum_type_get_length(data->method); + digest_len = g_checksum_type_get_length(chap->method); response_length = digest_len + sizeof(*header) + 1; ppp_packet = g_try_malloc0(response_length + 2); if (!ppp_packet) @@ -114,115 +103,56 @@ static void chap_process_challenge(struct auth_data *auth, guint8 *packet) } /* transmit the packet */ - ppp_transmit(auth->ppp, (guint8 *) ppp_packet, response_length); + ppp_transmit(chap->ppp, (guint8 *) ppp_packet, response_length); g_free(ppp_packet); challenge_out: g_checksum_free(checksum); } -static void chap_process_success(struct auth_data *data, guint8 *packet) -{ - ppp_generate_event(data->ppp, PPP_SUCCESS); -} - -static void chap_process_failure(struct auth_data *data, guint8 *packet) -{ - struct chap_header *header = (struct chap_header *) packet; - - ppp_generate_event(data->ppp, PPP_FAIL); - g_printerr("Failed to authenticate, message %s\n", header->data); -} - /* * parse the packet */ -static void chap_process_packet(struct auth_data *data, guint8 *new_packet) +void ppp_chap_process_packet(struct ppp_chap *chap, guint8 *new_packet) { guint8 code = new_packet[0]; switch (code) { case CHALLENGE: - g_print("chap: challenge\n"); - chap_process_challenge(data, new_packet); + chap_process_challenge(chap, new_packet); break; case RESPONSE: g_print("chap: response (not implemented)\n"); break; case SUCCESS: - g_print("chap: success\n"); - chap_process_success(data, new_packet); + ppp_auth_notify(chap->ppp, TRUE); break; case FAILURE: - g_print("chap: failure\n"); - chap_process_failure(data, new_packet); + ppp_auth_notify(chap->ppp, FALSE); break; default: - g_print("chap: unknown auth code\n"); break; } } -static void chap_free(struct auth_data *auth) +void ppp_chap_free(struct ppp_chap *chap) { - g_free(auth->proto_data); + g_free(chap); } -static struct chap_data *chap_new(struct auth_data *auth, guint8 method) +struct ppp_chap *ppp_chap_new(GAtPPP *ppp, guint8 method) { - struct chap_data *data; + struct ppp_chap *chap; - data = g_try_malloc0(sizeof(*data)); - if (!data) + if (method != MD5) return NULL; - data->auth = auth; - switch (method) { - case MD5: - data->method = G_CHECKSUM_MD5; - break; - default: - g_print("Unknown method\n"); - break; - } - - return data; -} - -void auth_set_proto(struct auth_data *data, guint16 proto, guint8 method) -{ - if (data == NULL) - return; - - switch (proto) { - case CHAP_PROTOCOL: - data->proto = proto; - data->proto_data = chap_new(data, method); - data->process_packet = chap_process_packet; - break; - default: - g_print("Unknown auth protocol 0x%x\n", proto); - break; - } -} - -void auth_free(struct auth_data *data) -{ - if (data == NULL) - return; - - chap_free(data); - g_free(data); -} - -struct auth_data *auth_new(GAtPPP *ppp) -{ - struct auth_data *data; - - data = g_try_malloc0(sizeof(*data)); - if (!data) + chap = g_try_new0(struct ppp_chap, 1); + if (!chap) return NULL; - data->ppp = ppp; - return data; + chap->ppp = ppp; + chap->method = G_CHECKSUM_MD5; + + return chap; } |