author | tille <tille> | 2003-05-23 19:43:46 (UTC) |
---|---|---|
committer | tille <tille> | 2003-05-23 19:43:46 (UTC) |
commit | 9b6b21112f38181f49b07e973bfe00c0d83a6900 (patch) (side-by-side diff) | |
tree | c2fa45a93ac5c26fe98558f28bb0a166b14ad065 /noncore/settings/networksettings/ppp/modem.cpp | |
parent | 34b9974063032242e5de65fa56d4c2cb5e1ce565 (diff) | |
download | opie-9b6b21112f38181f49b07e973bfe00c0d83a6900.zip opie-9b6b21112f38181f49b07e973bfe00c0d83a6900.tar.gz opie-9b6b21112f38181f49b07e973bfe00c0d83a6900.tar.bz2 |
configure dialog basicly working
more kppp stuff... ;)
Diffstat (limited to 'noncore/settings/networksettings/ppp/modem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/modem.cpp | 192 |
1 files changed, 165 insertions, 27 deletions
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp index e9e3f06..a2f77c5 100644 --- a/noncore/settings/networksettings/ppp/modem.cpp +++ b/noncore/settings/networksettings/ppp/modem.cpp @@ -21,55 +21,83 @@ * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <errno.h> #include <stdlib.h> #include <fcntl.h> #include <signal.h> #include <sys/ioctl.h> #include <setjmp.h> +#include <regex.h> #include <qregexp.h> #include <assert.h> +#include "auth.h" #include "modem.h" #include "pppdata.h" -//#include "requester.h" //#include <klocale.h> #define i18n QObject::tr #define qError qDebug //#include <kdebug.h> //#include <config.h> #define MY_ASSERT(x) if (!(x)) { \ qFatal( "ASSERT: \"%s\" in %s (%d)\n",#x,__FILE__,__LINE__); \ exit(1); } static sigjmp_buf jmp_buffer; Modem *Modem::modem = 0; -Modem::Modem() : - modemfd(-1), - sn(0L), - data_mode(false), - modem_is_locked(false) + +const char* pppdPath() { + // wasting a few bytes + static char buffer[sizeof(PPPDSEARCHPATH)+sizeof(PPPDNAME)]; + static char *pppdPath = 0L; + char *p; + + if(pppdPath == 0L) { + const char *c = PPPDSEARCHPATH; + while(*c != '\0') { + while(*c == ':') + c++; + p = buffer; + while(*c != '\0' && *c != ':') + *p++ = *c++; + *p = '\0'; + strcat(p, "/"); + strcat(p, PPPDNAME); + if(access(buffer, F_OK) == 0) + return (pppdPath = buffer); + } + } + + return pppdPath; +} + + +Modem::Modem() { + if (Modem::modem != 0) return; //CORRECT? + modemfd = -1; + sn = 0L; + data_mode = false; + modem_is_locked = false; lockfile[0] = '\0'; device = "/dev/modem"; - assert(modem==0); - modem = this; + modem = this; } Modem::~Modem() { modem = 0; } speed_t Modem::modemspeed() { // convert the string modem speed int the gpppdata object to a t_speed type // to set the modem. The constants here should all be ifdef'd because // other systems may not have them @@ -635,37 +663,147 @@ int Modem::openLockfile( QString lockfile, int flags) } void alarm_handler(int) { // fprintf(stderr, "alarm_handler(): Received SIGALRM\n"); // jump siglongjmp(jmp_buffer, 1); } +const char* Modem::authFile(Auth method, int version) { + switch(method|version) { + case PAP|Original: + return PAP_AUTH_FILE; + break; + case PAP|New: + return PAP_AUTH_FILE".new"; + break; + case PAP|Old: + return PAP_AUTH_FILE".old"; + break; + case CHAP|Original: + return CHAP_AUTH_FILE; + break; + case CHAP|New: + return CHAP_AUTH_FILE".new"; + break; + case CHAP|Old: + return CHAP_AUTH_FILE".old"; + break; + default: + return 0L; + } +} -const char* pppdPath() { - // wasting a few bytes - static char buffer[sizeof(PPPDSEARCHPATH)+sizeof(PPPDNAME)]; - static char *pppdPath = 0L; - char *p; - if(pppdPath == 0L) { - const char *c = PPPDSEARCHPATH; - while(*c != '\0') { - while(*c == ':') - c++; - p = buffer; - while(*c != '\0' && *c != ':') - *p++ = *c++; - *p = '\0'; - strcat(p, "/"); - strcat(p, PPPDNAME); - if(access(buffer, F_OK) == 0) - return (pppdPath = buffer); +bool Modem::createAuthFile(Auth method, const char *username, const char *password) { + const char *authfile, *oldName, *newName; + char line[100]; + char regexp[2*MaxStrLen+30]; + regex_t preg; + + if(!(authfile = authFile(method))) + return false; + + if(!(newName = authFile(method, New))) + return false; + + // look for username, "username" or 'username' + // if you modify this RE you have to adapt regexp's size above + snprintf(regexp, sizeof(regexp), "^[ \t]*%s[ \t]\\|^[ \t]*[\"\']%s[\"\']", + username,username); + MY_ASSERT(regcomp(&preg, regexp, 0) == 0); + + // copy to new file pap- or chap-secrets + int old_umask = umask(0077); + FILE *fout = fopen(newName, "w"); + if(fout) { + // copy old file + FILE *fin = fopen(authfile, "r"); + if(fin) { + while(fgets(line, sizeof(line), fin)) { + if(regexec(&preg, line, 0, 0L, 0) == 0) + continue; + fputs(line, fout); + } + fclose(fin); } + + // append user/pass pair + fprintf(fout, "\"%s\"\t*\t\"%s\"\n", username, password); + fclose(fout); } - return pppdPath; + // restore umask + umask(old_umask); + + // free memory allocated by regcomp + regfree(&preg); + + if(!(oldName = authFile(method, Old))) + return false; + + // delete old file if any + unlink(oldName); + + rename(authfile, oldName); + rename(newName, authfile); + + return true; +} + + +bool Modem::setSecret(int method, const char* name, const char* password) +{ + + Auth auth; + if(method == AUTH_PAPCHAP) + return setSecret(AUTH_PAP, name, password) && + setSecret(AUTH_CHAP, name, password); + + switch(method) { + case AUTH_PAP: + auth = Modem::PAP; + break; + case AUTH_CHAP: + auth = Modem::CHAP; + break; + default: + return false; + } + + return createAuthFile(auth, name, password); + +} + +bool Modem::removeSecret(int) +{ + return true; +} + +void Modem::killPPPDaemon() +{ +} + +int Modem::pppdExitStatus() +{ + return -1; } + +bool Modem::execPPPDaemon(const QString & arguments) +{ + return true; +} + +int Modem::openResolv(int flags) +{ + return -1; +} + +bool Modem::setHostname(const QString & name) +{ + return true; +} + |