diff options
author | Jean-Baptiste Queru <jbq@google.com> | 2009-07-25 17:48:02 -0700 |
---|---|---|
committer | Jean-Baptiste Queru <jbq@google.com> | 2009-07-25 17:48:02 -0700 |
commit | 85670599ee696a13af3253a4ad26a0ef88261a44 (patch) | |
tree | 29b4651c28b97e655c2fb951685a00e04313a9c3 | |
parent | 09d1d0ff1548e08e6b4c182c0adb193ed475fc47 (diff) | |
parent | dffa18062629fab18e536d21fe5f8b8f07c7e991 (diff) | |
download | ppp-85670599ee696a13af3253a4ad26a0ef88261a44.tar.gz |
Merge korg/donut into korg/master
-rw-r--r-- | pppd/Android.mk | 14 | ||||
-rw-r--r-- | pppd/chap-new.c | 6 | ||||
-rw-r--r-- | pppd/chap_ms.c | 9 | ||||
-rw-r--r-- | pppd/ipcp.c | 2 | ||||
-rw-r--r-- | pppd/main.c | 41 | ||||
-rw-r--r-- | pppd/openssl-hash.c | 41 | ||||
-rw-r--r-- | pppd/openssl-hash.h | 55 | ||||
-rw-r--r-- | pppd/options.c | 3 | ||||
-rw-r--r-- | pppd/pppcrypt.c | 2 | ||||
-rw-r--r-- | pppd/pppcrypt.h | 4 | ||||
-rw-r--r-- | pppd/pppox.c | 67 | ||||
-rw-r--r-- | pppd/utils.c | 50 |
12 files changed, 255 insertions, 39 deletions
diff --git a/pppd/Android.mk b/pppd/Android.mk index 01928b1..dcd5f8d 100644 --- a/pppd/Android.mk +++ b/pppd/Android.mk @@ -11,31 +11,29 @@ LOCAL_SRC_FILES:= \ ipcp.c \ upap.c \ chap-new.c \ - md5.c \ ccp.c \ ecp.c \ - ipxcp.c \ auth.c \ options.c \ sys-linux.c \ - md4.c \ chap_ms.c \ demand.c \ utils.c \ tty.c \ eap.c \ - chap-md5.c + chap-md5.c \ + pppcrypt.c \ + openssl-hash.c \ + pppox.c LOCAL_SHARED_LIBRARIES := \ - libcutils + libcutils libcrypto LOCAL_C_INCLUDES := \ $(LOCAL_PATH)/include -LOCAL_CFLAGS := -DANDROID_CHANGES +LOCAL_CFLAGS := -DANDROID_CHANGES -DCHAPMS=1 -DMPPE=1 -Iexternal/openssl/include -LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) -LOCAL_MODULE_TAGS := eng LOCAL_MODULE:= pppd include $(BUILD_EXECUTABLE) diff --git a/pppd/chap-new.c b/pppd/chap-new.c index b09fa3e..7d1aecd 100644 --- a/pppd/chap-new.c +++ b/pppd/chap-new.c @@ -35,6 +35,9 @@ #include "pppd.h" #include "chap-new.h" #include "chap-md5.h" +#ifdef ANDROID_CHANGES +#include "openssl-hash.h" +#endif #ifdef CHAPMS #include "chap_ms.h" @@ -141,6 +144,9 @@ chap_init(int unit) memset(&client, 0, sizeof(client)); memset(&server, 0, sizeof(server)); +#ifdef ANDROID_CHANGES + openssl_hash_init(); +#endif chap_md5_init(); #ifdef CHAPMS chapms_init(); diff --git a/pppd/chap_ms.c b/pppd/chap_ms.c index fb65d56..5f2c0e2 100644 --- a/pppd/chap_ms.c +++ b/pppd/chap_ms.c @@ -89,8 +89,12 @@ #include "pppd.h" #include "chap-new.h" #include "chap_ms.h" +#ifdef ANDROID_CHANGES +#include "openssl-hash.h" +#else #include "md4.h" #include "sha1.h" +#endif #include "pppcrypt.h" #include "magic.h" @@ -514,12 +518,17 @@ ascii2unicode(char ascii[], int ascii_len, u_char unicode[]) static void NTPasswordHash(char *secret, int secret_len, u_char hash[MD4_SIGNATURE_SIZE]) { +#ifdef ANDROID_CHANGES + /* We link with MD4 routines in openssl, we have to take bytes instead */ + int mdlen = secret_len; +#else #ifdef __NetBSD__ /* NetBSD uses the libc md4 routines which take bytes instead of bits */ int mdlen = secret_len; #else int mdlen = secret_len * 8; #endif +#endif MD4_CTX md4Context; MD4Init(&md4Context); diff --git a/pppd/ipcp.c b/pppd/ipcp.c index 52eb3ca..09aebe3 100644 --- a/pppd/ipcp.c +++ b/pppd/ipcp.c @@ -1996,9 +1996,9 @@ static void create_resolv(peerdns1, peerdns2) u_int32_t peerdns1, peerdns2; { +#ifndef ANDROID_CHANGES FILE *f; -#if 0 /* resolv.conf has no meaning for ANDROIDS */ f = fopen(_PATH_RESOLV, "w"); if (f == NULL) { error("Failed to create %s: %m", _PATH_RESOLV); diff --git a/pppd/main.c b/pppd/main.c index d37d781..adb57f1 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -360,13 +360,21 @@ main(argc, argv) */ tty_init(); +#ifdef ANDROID_CHANGES + { + extern void pppox_init(); + pppox_init(); + privileged = 1; + } +#endif + progname = *argv; /* * Parse, in order, the system options file, the user's options file, * and the command line arguments. */ -#ifdef ANDROID +#ifdef ANDROID_CHANGES /* Android: only take options from commandline */ if (!parse_args(argc-1, argv+1)) exit(EXIT_OPTION_ERROR); @@ -391,6 +399,7 @@ main(argc, argv) if (debug) setlogmask(LOG_UPTO(LOG_DEBUG)); +#ifndef ANDROID_CHANGES /* * Check that we are running as root. */ @@ -399,6 +408,7 @@ main(argc, argv) argv[0]); exit(EXIT_NOT_ROOT); } +#endif if (!ppp_available()) { option_error("%s", no_ppp_msg); @@ -805,8 +815,10 @@ detach() void reopen_log() { +#ifndef ANDROID_CHANGES openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP); setlogmask(LOG_UPTO(LOG_INFO)); +#endif } /* @@ -816,6 +828,7 @@ static void create_pidfile(pid) int pid; { +#ifndef ANDROID_CHANGES FILE *pidfile; slprintf(pidfilename, sizeof(pidfilename), "%s%s.pid", @@ -827,12 +840,14 @@ create_pidfile(pid) error("Failed to create pid file %s: %m", pidfilename); pidfilename[0] = 0; } +#endif } void create_linkpidfile(pid) int pid; { +#ifndef ANDROID_CHANGES FILE *pidfile; if (linkname[0] == 0) @@ -849,6 +864,7 @@ create_linkpidfile(pid) error("Failed to create pid file %s: %m", linkpidfile); linkpidfile[0] = 0; } +#endif } /* @@ -856,12 +872,14 @@ create_linkpidfile(pid) */ void remove_pidfiles() { +#ifndef ANDROID_CHANGES if (pidfilename[0] != 0 && unlink(pidfilename) < 0 && errno != ENOENT) warn("unable to delete pid file %s: %m", pidfilename); pidfilename[0] = 0; if (linkpidfile[0] != 0 && unlink(linkpidfile) < 0 && errno != ENOENT) warn("unable to delete pid file %s: %m", linkpidfile); linkpidfile[0] = 0; +#endif } /* @@ -1518,7 +1536,9 @@ safe_fork(int infd, int outfd, int errfd) if (errfd != 2) dup2(errfd, 2); +#ifndef ANDROID_CHANGES closelog(); +#endif if (log_to_fd > 2) close(log_to_fd); if (the_channel->close) @@ -1625,6 +1645,21 @@ run_program(prog, args, must_exist, done, arg) int pid; struct stat sbuf; +#ifdef ANDROID_CHANGES + /* Originally linkname is used to create named pid files, which is + * meaningless to android. Here we use it as a suffix of program names, + * so different users can run their own program by specifying it. For + * example, "/etc/ppp/ip-up-vpn" will be executed when IPCP is up and + * linkname is "vpn". Note that "/" is not allowed for security reasons. */ + char file[MAXPATHLEN]; + + if (linkname[0] && !strchr(linkname, '/')) { + snprintf(file, MAXPATHLEN, "%s-%s", prog, linkname); + file[MAXPATHLEN - 1] = '\0'; + prog = file; + } +#endif + /* * First check if the file exists and is executable. * We don't use access() because that would use the @@ -1667,11 +1702,15 @@ run_program(prog, args, must_exist, done, arg) /* run the program */ execve(prog, args, script_env); if (must_exist || errno != ENOENT) { +#ifndef ANDROID_CHANGES /* have to reopen the log, there's nowhere else for the message to go. */ reopen_log(); syslog(LOG_ERR, "Can't execute %s: %m", prog); closelog(); +#else + error("Can't execute %s: %m", prog); +#endif } _exit(-1); } diff --git a/pppd/openssl-hash.c b/pppd/openssl-hash.c new file mode 100644 index 0000000..840a68c --- /dev/null +++ b/pppd/openssl-hash.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <openssl/evp.h> + +const EVP_MD *sha1_md; +const EVP_MD *md4_md; +const EVP_MD *md5_md; + +void openssl_hash_init() { + /* Use the SHA1 functions in openssl to save the flash space.*/ + OpenSSL_add_all_digests(); + sha1_md = EVP_get_digestbyname("sha1"); + if (!sha1_md) { + dbglog("Error Unknown message digest SHA1\n"); + exit(1); + } + md4_md = EVP_get_digestbyname("md4"); + if (!md4_md) { + dbglog("Error Unknown message digest MD4\n"); + exit(1); + } + md5_md = EVP_get_digestbyname("md5"); + if (!md5_md) { + dbglog("Error Unknown message digest MD5\n"); + exit(1); + } +} diff --git a/pppd/openssl-hash.h b/pppd/openssl-hash.h new file mode 100644 index 0000000..a2a5abe --- /dev/null +++ b/pppd/openssl-hash.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __OPENSSL_HASH__ +#define __OPENSSL_HASH__ + +#include <openssl/evp.h> + +extern const EVP_MD *sha1_md; +#define SHA1_SIGNATURE_SIZE 20 +#define SHA1_CTX EVP_MD_CTX +#define SHA1_Init(ctx) { \ + EVP_MD_CTX_init(ctx); \ + EVP_DigestInit_ex(ctx, sha1_md, NULL); \ +} +#define SHA1_Update EVP_DigestUpdate +#define SHA1_Final(digest, ctx) { \ + int md_len; \ + EVP_DigestFinal_ex(ctx, digest, &md_len); \ +} + +extern const EVP_MD *md4_md; +#define MD4_CTX EVP_MD_CTX +#define MD4Init(ctx) { \ + EVP_MD_CTX_init(ctx); \ + EVP_DigestInit_ex(ctx, md4_md, NULL); \ +} +#define MD4Update EVP_DigestUpdate +#define MD4Final SHA1_Final + +extern const EVP_MD *md5_md; +#define MD5_CTX EVP_MD_CTX +#define MD5_Init(ctx) { \ + EVP_MD_CTX_init(ctx); \ + EVP_DigestInit_ex(ctx, md5_md, NULL); \ +} +#define MD5_Update EVP_DigestUpdate +#define MD5_Final SHA1_Final + +extern void openssl_hash_init(); + +#endif diff --git a/pppd/options.c b/pppd/options.c index 5375bf3..f8a836b 100644 --- a/pppd/options.c +++ b/pppd/options.c @@ -1065,8 +1065,9 @@ option_error __V((char *fmt, ...)) va_end(args); if (phase == PHASE_INITIALIZE) fprintf(stderr, "%s: %s\n", progname, buf); +#ifndef ANDROID_CHANGES syslog(LOG_ERR, "%s", buf); -#ifdef ANDROID_CHANGES +#else error("%s", buf); #endif } diff --git a/pppd/pppcrypt.c b/pppd/pppcrypt.c index 8b85b13..1302c83 100644 --- a/pppd/pppcrypt.c +++ b/pppd/pppcrypt.c @@ -171,7 +171,7 @@ u_char *key; } bool -DesEncrypt(clear, key, cipher) +DesEncrypt(clear, cipher) u_char *clear; /* IN 8 octets */ u_char *cipher; /* OUT 8 octets */ { diff --git a/pppd/pppcrypt.h b/pppd/pppcrypt.h index adcdcbc..33b956d 100644 --- a/pppd/pppcrypt.h +++ b/pppd/pppcrypt.h @@ -38,8 +38,12 @@ #endif #ifndef USE_CRYPT +#ifdef ANDROID_CHANGES +#include <openssl/des.h> +#else #include <des.h> #endif +#endif extern bool DesSetkey __P((u_char *)); extern bool DesEncrypt __P((u_char *, u_char *)); diff --git a/pppd/pppox.c b/pppd/pppox.c new file mode 100644 index 0000000..9604fba --- /dev/null +++ b/pppd/pppox.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <unistd.h> +#include "pppd.h" + +static int pppox_set(char **); +static int pppox_connect(); +static void pppox_disconnect(); + +static option_t pppox_options[] = { + {"pppox", o_special, pppox_set, "PPPoX socket", OPT_DEVNAM}, + {NULL}, +}; + +static struct channel pppox_channel = { + .options = pppox_options, + .process_extra_options = NULL, + .check_options = NULL, + .connect = pppox_connect, + .disconnect = pppox_disconnect, + .establish_ppp = generic_establish_ppp, + .disestablish_ppp = generic_disestablish_ppp, + .send_config = NULL, + .recv_config = NULL, + .cleanup = NULL, + .close = NULL, +}; + +static int pppox = -1; + +static int pppox_set(char **argv) { + if (!int_option(*argv, &pppox)) { + return 0; + } + info("Using PPPoX (socket = %d)", pppox); + the_channel = &pppox_channel; + return 1; +} + +static int pppox_connect() { + return pppox; +} + +static void pppox_disconnect() { + if (pppox != -1) { + close(pppox); + pppox = -1; + } +} + +void pppox_init() { + add_options(pppox_options); +} diff --git a/pppd/utils.c b/pppd/utils.c index 6f668b8..1ef4b3b 100644 --- a/pppd/utils.c +++ b/pppd/utils.c @@ -665,11 +665,31 @@ logit(level, fmt, args) log_write(level, buf); } +#ifdef ANDROID_CHANGES + +#if LOG_PRIMASK != 7 +#error Syslog.h has been changed! Please fix this table! +#endif + +static int syslog_to_android[] = { + [LOG_EMERG] = ANDROID_LOG_FATAL, + [LOG_ALERT] = ANDROID_LOG_FATAL, + [LOG_CRIT] = ANDROID_LOG_FATAL, + [LOG_ERR] = ANDROID_LOG_ERROR, + [LOG_WARNING] = ANDROID_LOG_WARN, + [LOG_NOTICE] = ANDROID_LOG_INFO, + [LOG_INFO] = ANDROID_LOG_INFO, + [LOG_DEBUG] = ANDROID_LOG_DEBUG, +}; + +#endif + static void log_write(level, buf) int level; char *buf; { +#ifndef ANDROID_CHANGES syslog(level, "%s", buf); fprintf(stderr, buf); @@ -683,6 +703,9 @@ log_write(level, buf) || write(log_to_fd, "\n", 1) != 1) log_to_fd = -1; } +#else + __android_log_write(syslog_to_android[level], LOG_TAG, buf); +#endif } /* @@ -701,11 +724,7 @@ fatal __V((char *fmt, ...)) fmt = va_arg(pvar, char *); #endif -#ifdef ANDROID_CHANGES - __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, fmt, pvar); -#else logit(LOG_ERR, fmt, pvar); -#endif va_end(pvar); die(1); /* as promised */ @@ -727,12 +746,7 @@ error __V((char *fmt, ...)) fmt = va_arg(pvar, char *); #endif -#ifdef ANDROID_CHANGES - __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, fmt, pvar); -#else logit(LOG_ERR, fmt, pvar); -#endif - va_end(pvar); ++error_count; } @@ -753,12 +767,7 @@ warn __V((char *fmt, ...)) fmt = va_arg(pvar, char *); #endif -#ifdef ANDROID_CHANGES - __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, fmt, pvar); -#else logit(LOG_WARNING, fmt, pvar); -#endif - va_end(pvar); } @@ -778,11 +787,7 @@ notice __V((char *fmt, ...)) fmt = va_arg(pvar, char *); #endif -#ifdef ANDROID_CHANGES - __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, fmt, pvar); -#else logit(LOG_NOTICE, fmt, pvar); -#endif va_end(pvar); } @@ -802,12 +807,7 @@ info __V((char *fmt, ...)) fmt = va_arg(pvar, char *); #endif -#ifdef ANDROID_CHANGES - __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, fmt, pvar); -#else logit(LOG_INFO, fmt, pvar); -#endif - va_end(pvar); } @@ -827,11 +827,7 @@ dbglog __V((char *fmt, ...)) fmt = va_arg(pvar, char *); #endif -#ifdef ANDROID_CHANGES - __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, fmt, pvar); -#else logit(LOG_DEBUG, fmt, pvar); -#endif va_end(pvar); } |