-rw-r--r-- | noncore/settings/networksettings/ppp/modem.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp index 2da9b14..d23fee4 100644 --- a/noncore/settings/networksettings/ppp/modem.cpp +++ b/noncore/settings/networksettings/ppp/modem.cpp | |||
@@ -607,417 +607,417 @@ if ((fd = openLockfile(QFile::encodeName(lockfile), O_RDONLY)) >= 0) { | |||
607 | if (match < 1 || oldpid <= 0) | 607 | if (match < 1 || oldpid <= 0) |
608 | return 1; | 608 | return 1; |
609 | 609 | ||
610 | // check if process exists | 610 | // check if process exists |
611 | if (kill((pid_t)oldpid, 0) == 0 || errno != ESRCH) | 611 | if (kill((pid_t)oldpid, 0) == 0 || errno != ESRCH) |
612 | return 1; | 612 | return 1; |
613 | 613 | ||
614 | qDebug( "lockfile is stale" ); | 614 | qDebug( "lockfile is stale" ); |
615 | } | 615 | } |
616 | } | 616 | } |
617 | 617 | ||
618 | fd = openLockfile(_pppdata->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT); | 618 | fd = openLockfile(_pppdata->modemDevice(),O_WRONLY|O_TRUNC|O_CREAT); |
619 | if(fd >= 0) { | 619 | if(fd >= 0) { |
620 | sprintf(newlock,"%010d\n", getpid()); | 620 | sprintf(newlock,"%010d\n", getpid()); |
621 | qDebug("Locking Device: %s", newlock); | 621 | qDebug("Locking Device: %s", newlock); |
622 | 622 | ||
623 | write(fd, newlock, strlen(newlock)); | 623 | write(fd, newlock, strlen(newlock)); |
624 | close(fd); | 624 | close(fd); |
625 | modem_is_locked=true; | 625 | modem_is_locked=true; |
626 | 626 | ||
627 | return 0; | 627 | return 0; |
628 | } | 628 | } |
629 | 629 | ||
630 | return -1; | 630 | return -1; |
631 | 631 | ||
632 | } | 632 | } |
633 | 633 | ||
634 | 634 | ||
635 | // UnLock modem device | 635 | // UnLock modem device |
636 | void Modem::unlockdevice() { | 636 | void Modem::unlockdevice() { |
637 | if (modem_is_locked) { | 637 | if (modem_is_locked) { |
638 | qDebug( "UnLocking Modem Device" ); | 638 | qDebug( "UnLocking Modem Device" ); |
639 | close(modemfd); | 639 | close(modemfd); |
640 | modemfd = -1; | 640 | modemfd = -1; |
641 | unlink(lockfile); | 641 | unlink(lockfile); |
642 | lockfile[0] = '\0'; | 642 | lockfile[0] = '\0'; |
643 | modem_is_locked=false; | 643 | modem_is_locked=false; |
644 | } | 644 | } |
645 | } | 645 | } |
646 | 646 | ||
647 | int Modem::openLockfile( QString lockfile, int flags) | 647 | int Modem::openLockfile( QString lockfile, int flags) |
648 | { | 648 | { |
649 | int fd; | 649 | int fd; |
650 | int mode; | 650 | int mode; |
651 | flags = O_RDONLY; | 651 | flags = O_RDONLY; |
652 | if(flags == O_WRONLY|O_TRUNC|O_CREAT) | 652 | if(flags == O_WRONLY|O_TRUNC|O_CREAT) |
653 | mode = 0644; | 653 | mode = 0644; |
654 | else | 654 | else |
655 | mode = 0; | 655 | mode = 0; |
656 | 656 | ||
657 | lockfile = LOCK_DIR; | 657 | lockfile = LOCK_DIR; |
658 | lockfile += "/LCK.."; | 658 | lockfile += "/LCK.."; |
659 | lockfile += device.right( device.length() - device.findRev("/") -1 ); | 659 | lockfile += device.right( device.length() - device.findRev("/") -1 ); |
660 | qDebug("lockfile >%s<",lockfile.latin1()); | 660 | qDebug("lockfile >%s<",lockfile.latin1()); |
661 | // TODO: | 661 | // TODO: |
662 | // struct stat st; | 662 | // struct stat st; |
663 | // if(stat(lockfile.data(), &st) == -1) { | 663 | // if(stat(lockfile.data(), &st) == -1) { |
664 | // if(errno == EBADF) | 664 | // if(errno == EBADF) |
665 | // return -1; | 665 | // return -1; |
666 | // } else { | 666 | // } else { |
667 | // // make sure that this is a regular file | 667 | // // make sure that this is a regular file |
668 | // if(!S_ISREG(st.st_mode)) | 668 | // if(!S_ISREG(st.st_mode)) |
669 | // return -1; | 669 | // return -1; |
670 | // } | 670 | // } |
671 | if ((fd = open(lockfile, flags, mode)) == -1) { | 671 | if ((fd = open(lockfile, flags, mode)) == -1) { |
672 | qDebug("error opening lockfile!"); | 672 | qDebug("error opening lockfile!"); |
673 | lockfile = QString::null; | 673 | lockfile = QString::null; |
674 | fd = open(DEVNULL, O_RDONLY); | 674 | fd = open(DEVNULL, O_RDONLY); |
675 | } else | 675 | } else |
676 | fchown(fd, 0, 0); | 676 | fchown(fd, 0, 0); |
677 | return fd; | 677 | return fd; |
678 | } | 678 | } |
679 | 679 | ||
680 | 680 | ||
681 | 681 | ||
682 | void alarm_handler(int) { | 682 | void alarm_handler(int) { |
683 | // fprintf(stderr, "alarm_handler(): Received SIGALRM\n"); | 683 | // fprintf(stderr, "alarm_handler(): Received SIGALRM\n"); |
684 | 684 | ||
685 | // jump | 685 | // jump |
686 | siglongjmp(jmp_buffer, 1); | 686 | siglongjmp(jmp_buffer, 1); |
687 | } | 687 | } |
688 | 688 | ||
689 | 689 | ||
690 | const char* Modem::authFile(Auth method, int version) { | 690 | const char* Modem::authFile(Auth method, int version) { |
691 | switch(method|version) { | 691 | switch(method|version) { |
692 | case PAP|Original: | 692 | case PAP|Original: |
693 | return PAP_AUTH_FILE; | 693 | return PAP_AUTH_FILE; |
694 | break; | 694 | break; |
695 | case PAP|New: | 695 | case PAP|New: |
696 | return PAP_AUTH_FILE".new"; | 696 | return PAP_AUTH_FILE".new"; |
697 | break; | 697 | break; |
698 | case PAP|Old: | 698 | case PAP|Old: |
699 | return PAP_AUTH_FILE".old"; | 699 | return PAP_AUTH_FILE".old"; |
700 | break; | 700 | break; |
701 | case CHAP|Original: | 701 | case CHAP|Original: |
702 | return CHAP_AUTH_FILE; | 702 | return CHAP_AUTH_FILE; |
703 | break; | 703 | break; |
704 | case CHAP|New: | 704 | case CHAP|New: |
705 | return CHAP_AUTH_FILE".new"; | 705 | return CHAP_AUTH_FILE".new"; |
706 | break; | 706 | break; |
707 | case CHAP|Old: | 707 | case CHAP|Old: |
708 | return CHAP_AUTH_FILE".old"; | 708 | return CHAP_AUTH_FILE".old"; |
709 | break; | 709 | break; |
710 | default: | 710 | default: |
711 | return 0L; | 711 | return 0L; |
712 | } | 712 | } |
713 | } | 713 | } |
714 | 714 | ||
715 | 715 | ||
716 | bool Modem::createAuthFile(Auth method, const char *username, const char *password) { | 716 | bool Modem::createAuthFile(Auth method, const char *username, const char *password) { |
717 | const char *authfile, *oldName, *newName; | 717 | const char *authfile, *oldName, *newName; |
718 | char line[100]; | 718 | char line[100]; |
719 | char regexp[2*MaxStrLen+30]; | 719 | char regexp[2*MaxStrLen+30]; |
720 | regex_t preg; | 720 | regex_t preg; |
721 | 721 | ||
722 | if(!(authfile = authFile(method))) | 722 | if(!(authfile = authFile(method))) |
723 | return false; | 723 | return false; |
724 | 724 | ||
725 | if(!(newName = authFile(method, New))) | 725 | if(!(newName = authFile(method, New))) |
726 | return false; | 726 | return false; |
727 | 727 | ||
728 | // look for username, "username" or 'username' | 728 | // look for username, "username" or 'username' |
729 | // if you modify this RE you have to adapt regexp's size above | 729 | // if you modify this RE you have to adapt regexp's size above |
730 | snprintf(regexp, sizeof(regexp), "^[ \t]*%s[ \t]\\|^[ \t]*[\"\']%s[\"\']", | 730 | snprintf(regexp, sizeof(regexp), "^[ \t]*%s[ \t]\\|^[ \t]*[\"\']%s[\"\']", |
731 | username,username); | 731 | username,username); |
732 | MY_ASSERT(regcomp(&preg, regexp, 0) == 0); | 732 | MY_ASSERT(regcomp(&preg, regexp, 0) == 0); |
733 | 733 | ||
734 | // copy to new file pap- or chap-secrets | 734 | // copy to new file pap- or chap-secrets |
735 | int old_umask = umask(0077); | 735 | int old_umask = umask(0077); |
736 | FILE *fout = fopen(newName, "w"); | 736 | FILE *fout = fopen(newName, "w"); |
737 | if(fout) { | 737 | if(fout) { |
738 | // copy old file | 738 | // copy old file |
739 | FILE *fin = fopen(authfile, "r"); | 739 | FILE *fin = fopen(authfile, "r"); |
740 | if(fin) { | 740 | if(fin) { |
741 | while(fgets(line, sizeof(line), fin)) { | 741 | while(fgets(line, sizeof(line), fin)) { |
742 | if(regexec(&preg, line, 0, 0L, 0) == 0) | 742 | if(regexec(&preg, line, 0, 0L, 0) == 0) |
743 | continue; | 743 | continue; |
744 | fputs(line, fout); | 744 | fputs(line, fout); |
745 | } | 745 | } |
746 | fclose(fin); | 746 | fclose(fin); |
747 | } | 747 | } |
748 | 748 | ||
749 | // append user/pass pair | 749 | // append user/pass pair |
750 | fprintf(fout, "\"%s\"\t*\t\"%s\"\n", username, password); | 750 | fprintf(fout, "\"%s\"\t*\t\"%s\"\n", username, password); |
751 | fclose(fout); | 751 | fclose(fout); |
752 | } | 752 | } |
753 | 753 | ||
754 | // restore umask | 754 | // restore umask |
755 | umask(old_umask); | 755 | umask(old_umask); |
756 | 756 | ||
757 | // free memory allocated by regcomp | 757 | // free memory allocated by regcomp |
758 | regfree(&preg); | 758 | regfree(&preg); |
759 | 759 | ||
760 | if(!(oldName = authFile(method, Old))) | 760 | if(!(oldName = authFile(method, Old))) |
761 | return false; | 761 | return false; |
762 | 762 | ||
763 | // delete old file if any | 763 | // delete old file if any |
764 | unlink(oldName); | 764 | unlink(oldName); |
765 | 765 | ||
766 | rename(authfile, oldName); | 766 | rename(authfile, oldName); |
767 | rename(newName, authfile); | 767 | rename(newName, authfile); |
768 | 768 | ||
769 | return true; | 769 | return true; |
770 | } | 770 | } |
771 | 771 | ||
772 | 772 | ||
773 | bool Modem::removeAuthFile(Auth method) { | 773 | bool Modem::removeAuthFile(Auth method) { |
774 | const char *authfile, *oldName; | 774 | const char *authfile, *oldName; |
775 | 775 | ||
776 | if(!(authfile = authFile(method))) | 776 | if(!(authfile = authFile(method))) |
777 | return false; | 777 | return false; |
778 | if(!(oldName = authFile(method, Old))) | 778 | if(!(oldName = authFile(method, Old))) |
779 | return false; | 779 | return false; |
780 | 780 | ||
781 | if(access(oldName, F_OK) == 0) { | 781 | if(access(oldName, F_OK) == 0) { |
782 | unlink(authfile); | 782 | unlink(authfile); |
783 | return (rename(oldName, authfile) == 0); | 783 | return (rename(oldName, authfile) == 0); |
784 | } else | 784 | } else |
785 | return false; | 785 | return false; |
786 | } | 786 | } |
787 | 787 | ||
788 | 788 | ||
789 | bool Modem::setSecret(int method, const char* name, const char* password) | 789 | bool Modem::setSecret(int method, const char* name, const char* password) |
790 | { | 790 | { |
791 | 791 | ||
792 | Auth auth; | 792 | Auth auth; |
793 | if(method == AUTH_PAPCHAP) | 793 | if(method == AUTH_PAPCHAP) |
794 | return setSecret(AUTH_PAP, name, password) && | 794 | return setSecret(AUTH_PAP, name, password) && |
795 | setSecret(AUTH_CHAP, name, password); | 795 | setSecret(AUTH_CHAP, name, password); |
796 | 796 | ||
797 | switch(method) { | 797 | switch(method) { |
798 | case AUTH_PAP: | 798 | case AUTH_PAP: |
799 | auth = Modem::PAP; | 799 | auth = Modem::PAP; |
800 | break; | 800 | break; |
801 | case AUTH_CHAP: | 801 | case AUTH_CHAP: |
802 | auth = Modem::CHAP; | 802 | auth = Modem::CHAP; |
803 | break; | 803 | break; |
804 | default: | 804 | default: |
805 | return false; | 805 | return false; |
806 | } | 806 | } |
807 | 807 | ||
808 | return createAuthFile(auth, name, password); | 808 | return createAuthFile(auth, name, password); |
809 | 809 | ||
810 | } | 810 | } |
811 | 811 | ||
812 | bool Modem::removeSecret(int method) | 812 | bool Modem::removeSecret(int method) |
813 | { | 813 | { |
814 | Auth auth; | 814 | Auth auth; |
815 | 815 | ||
816 | switch(method) { | 816 | switch(method) { |
817 | case AUTH_PAP: | 817 | case AUTH_PAP: |
818 | auth = Modem::PAP; | 818 | auth = Modem::PAP; |
819 | break; | 819 | break; |
820 | case AUTH_CHAP: | 820 | case AUTH_CHAP: |
821 | auth = Modem::CHAP; | 821 | auth = Modem::CHAP; |
822 | break; | 822 | break; |
823 | default: | 823 | default: |
824 | return false; | 824 | return false; |
825 | } | 825 | } |
826 | return removeAuthFile( auth ); | 826 | return removeAuthFile( auth ); |
827 | } | 827 | } |
828 | 828 | ||
829 | int checkForInterface() | 829 | int checkForInterface() |
830 | { | 830 | { |
831 | // I don't know if Linux needs more initialization to get the ioctl to | 831 | // I don't know if Linux needs more initialization to get the ioctl to |
832 | // work, pppd seems to hint it does. But BSD doesn't, and the following | 832 | // work, pppd seems to hint it does. But BSD doesn't, and the following |
833 | // code should compile. | 833 | // code should compile. |
834 | #if (defined(HAVE_NET_IF_PPP_H) || defined(HAVE_LINUX_IF_PPP_H)) && !defined(__svr4__) | 834 | #if (defined(HAVE_NET_IF_PPP_H) || defined(HAVE_LINUX_IF_PPP_H)) && !defined(__svr4__) |
835 | int s, ok; | 835 | int s, ok; |
836 | struct ifreq ifr; | 836 | struct ifreq ifr; |
837 | // extern char *no_ppp_msg; | 837 | // extern char *no_ppp_msg; |
838 | 838 | ||
839 | if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) | 839 | if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) |
840 | return 1; /* can't tell */ | 840 | return 1; /* can't tell */ |
841 | 841 | ||
842 | strlcpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name)); | 842 | strlcpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name)); |
843 | ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0; | 843 | ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0; |
844 | close(s); | 844 | close(s); |
845 | 845 | ||
846 | if (ok == -1) { | 846 | if (ok == -1) { |
847 | // This is ifdef'd FreeBSD, because FreeBSD is the only BSD that supports | 847 | // This is ifdef'd FreeBSD, because FreeBSD is the only BSD that supports |
848 | // KLDs, the old LKM interface couldn't handle loading devices | 848 | // KLDs, the old LKM interface couldn't handle loading devices |
849 | // dynamically, and thus can't load ppp support on the fly | 849 | // dynamically, and thus can't load ppp support on the fly |
850 | #ifdef __FreeBSD__ | 850 | #ifdef __FreeBSD__ |
851 | // If we failed to load ppp support and don't have it already. | 851 | // If we failed to load ppp support and don't have it already. |
852 | if (kldload("if_ppp") == -1) { | 852 | if (kldload("if_ppp") == -1) { |
853 | return -1; | 853 | return -1; |
854 | } | 854 | } |
855 | return 0; | 855 | return 0; |
856 | #else | 856 | #else |
857 | return -1; | 857 | return -1; |
858 | #endif | 858 | #endif |
859 | } | 859 | } |
860 | return 0; | 860 | return 0; |
861 | #else | 861 | #else |
862 | // We attempt to use the SunOS/SysVr4 method and stat /dev/ppp | 862 | // We attempt to use the SunOS/SysVr4 method and stat /dev/ppp |
863 | struct stat buf; | 863 | struct stat buf; |
864 | 864 | ||
865 | memset(&buf, 0, sizeof(buf)); | 865 | memset(&buf, 0, sizeof(buf)); |
866 | return stat("/dev/ppp", &buf); | 866 | return stat("/dev/ppp", &buf); |
867 | #endif | 867 | #endif |
868 | } | 868 | } |
869 | 869 | ||
870 | bool Modem::execpppd(const char *arguments) { | 870 | bool Modem::execpppd(const char *arguments) { |
871 | char buf[MAX_CMDLEN]; | 871 | char buf[MAX_CMDLEN]; |
872 | char *args[MaxArgs]; | 872 | char *args[MaxArgs]; |
873 | pid_t pgrpid; | 873 | pid_t pgrpid; |
874 | 874 | ||
875 | if(modemfd<0) | 875 | if(modemfd<0) |
876 | return false; | 876 | return false; |
877 | 877 | ||
878 | _pppdExitStatus = -1; | 878 | _pppdExitStatus = -1; |
879 | 879 | ||
880 | switch(pppdPid = fork()) | 880 | switch(pppdPid = fork()) |
881 | { | 881 | { |
882 | case -1: | 882 | case -1: |
883 | fprintf(stderr,"In parent: fork() failed\n"); | 883 | fprintf(stderr,"In parent: fork() failed\n"); |
884 | return false; | 884 | return false; |
885 | break; | 885 | break; |
886 | 886 | ||
887 | case 0: | 887 | case 0: |
888 | // let's parse the arguments the user supplied into UNIX suitable form | 888 | // let's parse the arguments the user supplied into UNIX suitable form |
889 | // that is a list of pointers each pointing to exactly one word | 889 | // that is a list of pointers each pointing to exactly one word |
890 | strlcpy(buf, arguments); | 890 | strlcpy(buf, arguments); |
891 | parseargs(buf, args); | 891 | parseargs(buf, args); |
892 | // become a session leader and let /dev/ttySx | 892 | // become a session leader and let /dev/ttySx |
893 | // be the controlling terminal. | 893 | // be the controlling terminal. |
894 | pgrpid = setsid(); | 894 | pgrpid = setsid(); |
895 | #ifdef TIOCSCTTY | 895 | #ifdef TIOCSCTTY |
896 | if(ioctl(modemfd, TIOCSCTTY, 0)<0) | 896 | if(ioctl(modemfd, TIOCSCTTY, 0)<0) |
897 | fprintf(stderr, "ioctl() failed.\n"); | 897 | fprintf(stderr, "ioctl() failed.\n"); |
898 | #elif defined (TIOCSPGRP) | 898 | #elif defined (TIOCSPGRP) |
899 | if(ioctl(modemfd, TIOCSPGRP, &pgrpid)<0) | 899 | if(ioctl(modemfd, TIOCSPGRP, &pgrpid)<0) |
900 | fprintf(stderr, "ioctl() failed.\n"); | 900 | fprintf(stderr, "ioctl() failed.\n"); |
901 | #endif | 901 | #endif |
902 | if(tcsetpgrp(modemfd, pgrpid)<0) | 902 | if(tcsetpgrp(modemfd, pgrpid)<0) |
903 | fprintf(stderr, "tcsetpgrp() failed.\n"); | 903 | fprintf(stderr, "tcsetpgrp() failed.\n"); |
904 | 904 | ||
905 | dup2(modemfd, 0); | 905 | dup2(modemfd, 0); |
906 | dup2(modemfd, 1); | 906 | dup2(modemfd, 1); |
907 | 907 | ||
908 | switch (checkForInterface()) { | 908 | switch (checkForInterface()) { |
909 | case 1: | 909 | case 1: |
910 | fprintf(stderr, "Cannot determine if kernel supports ppp.\n"); | 910 | fprintf(stderr, "Cannot determine if kernel supports ppp.\n"); |
911 | break; | 911 | break; |
912 | case -1: | 912 | case -1: |
913 | fprintf(stderr, "Kernel does not support ppp, oops.\n"); | 913 | fprintf(stderr, "Kernel does not support ppp, oops.\n"); |
914 | break; | 914 | break; |
915 | case 0: | 915 | case 0: |
916 | fprintf(stderr, "Kernel supports ppp alright.\n"); | 916 | fprintf(stderr, "Kernel supports ppp alright.\n"); |
917 | break; | 917 | break; |
918 | } | 918 | } |
919 | 919 | ||
920 | execve(pppdPath(), args, 0L); | 920 | execve(pppdPath(), args, 0L); |
921 | _exit(0); | 921 | _exit(0); |
922 | break; | 922 | break; |
923 | 923 | ||
924 | default: | 924 | default: |
925 | qDebug("In parent: pppd pid %d\n",pppdPid); | 925 | qDebug("In parent: pppd pid %d\n",pppdPid); |
926 | close(modemfd); | 926 | close(modemfd); |
927 | modemfd = -1; | 927 | modemfd = -1; |
928 | return true; | 928 | return true; |
929 | break; | 929 | break; |
930 | } | 930 | } |
931 | } | 931 | } |
932 | 932 | ||
933 | 933 | ||
934 | bool Modem::killpppd() { | 934 | bool Modem::killpppd() { |
935 | if(pppdPid > 0) { | 935 | if(pppdPid > 0) { |
936 | qDebug("In killpppd(): Sending SIGTERM to %d\n", pppdPid); | 936 | qDebug("In killpppd(): Sending SIGTERM to %d\n", pppdPid); |
937 | if(kill(pppdPid, SIGTERM) < 0) { | 937 | if(kill(pppdPid, SIGTERM) < 0) { |
938 | qDebug("Error terminating %d. Sending SIGKILL\n", pppdPid); | 938 | qDebug("Error terminating %d. Sending SIGKILL\n", pppdPid); |
939 | if(kill(pppdPid, SIGKILL) < 0) { | 939 | if(kill(pppdPid, SIGKILL) < 0) { |
940 | qDebug("Error killing %d\n", pppdPid); | 940 | qDebug("Error killing %d\n", pppdPid); |
941 | return false; | 941 | return false; |
942 | } | 942 | } |
943 | } | 943 | } |
944 | } | 944 | } |
945 | return true; | 945 | return true; |
946 | } | 946 | } |
947 | 947 | ||
948 | 948 | ||
949 | void Modem::parseargs(char* buf, char** args) { | 949 | void Modem::parseargs(char* buf, char** args) { |
950 | int nargs = 0; | 950 | int nargs = 0; |
951 | int quotes; | 951 | int quotes; |
952 | 952 | ||
953 | while(nargs < MaxArgs-1 && *buf != '\0') { | 953 | while(nargs < MaxArgs-1 && *buf != '\0') { |
954 | 954 | ||
955 | quotes = 0; | 955 | quotes = 0; |
956 | 956 | ||
957 | // Strip whitespace. Use nulls, so that the previous argument is | 957 | // Strip whitespace. Use nulls, so that the previous argument is |
958 | // terminated automatically. | 958 | // terminated automatically. |
959 | 959 | ||
960 | while ((*buf == ' ' ) || (*buf == '\t' ) || (*buf == '\n' ) ) | 960 | while ((*buf == ' ' ) || (*buf == '\t' ) || (*buf == '\n' ) ) |
961 | *buf++ = '\0'; | 961 | *buf++ = '\0'; |
962 | 962 | ||
963 | // detect begin of quoted argument | 963 | // detect begin of quoted argument |
964 | if (*buf == '"' || *buf == '\'') { | 964 | if (*buf == '"' || *buf == '\'') { |
965 | quotes = *buf; | 965 | quotes = *buf; |
966 | *buf++ = '\0'; | 966 | *buf++ = '\0'; |
967 | } | 967 | } |
968 | 968 | ||
969 | // save the argument | 969 | // save the argument |
970 | if(*buf != '\0') { | 970 | if(*buf != '\0') { |
971 | *args++ = buf; | 971 | *args++ = buf; |
972 | nargs++; | 972 | nargs++; |
973 | } | 973 | } |
974 | 974 | ||
975 | if (!quotes) | 975 | if (!quotes) |
976 | while ((*buf != '\0') && (*buf != '\n') && | 976 | while ((*buf != '\0') && (*buf != '\n') && |
977 | (*buf != '\t') && (*buf != ' ')) | 977 | (*buf != '\t') && (*buf != ' ')) |
978 | buf++; | 978 | buf++; |
979 | else { | 979 | else { |
980 | while ((*buf != '\0') && (*buf != quotes)) | 980 | while ((*buf != '\0') && (*buf != quotes)) |
981 | buf++; | 981 | buf++; |
982 | *buf++ = '\0'; | 982 | *buf++ = '\0'; |
983 | } | 983 | } |
984 | } | 984 | } |
985 | 985 | ||
986 | *args = 0L; | 986 | *args = 0L; |
987 | } | 987 | } |
988 | 988 | ||
989 | bool Modem::execPPPDaemon(const QString & arguments) | 989 | bool Modem::execPPPDaemon(const QString & arguments) |
990 | { | 990 | { |
991 | if(execpppd(arguments)==0) { | 991 | if(execpppd(arguments)) { |
992 | _pppdata->setpppdRunning(true); | 992 | _pppdata->setpppdRunning(true); |
993 | return true; | 993 | return true; |
994 | } else | 994 | } else |
995 | return false; | 995 | return false; |
996 | } | 996 | } |
997 | 997 | ||
998 | void Modem::killPPPDaemon() | 998 | void Modem::killPPPDaemon() |
999 | { | 999 | { |
1000 | _pppdata->setpppdRunning(false); | 1000 | _pppdata->setpppdRunning(false); |
1001 | killpppd(); | 1001 | killpppd(); |
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | int Modem::pppdExitStatus() | 1004 | int Modem::pppdExitStatus() |
1005 | { | 1005 | { |
1006 | return _pppdExitStatus; | 1006 | return _pppdExitStatus; |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | int Modem::openResolv(int flags) | 1009 | int Modem::openResolv(int flags) |
1010 | { | 1010 | { |
1011 | int fd; | 1011 | int fd; |
1012 | if ((fd = open(_PATH_RESCONF, flags)) == -1) { | 1012 | if ((fd = open(_PATH_RESCONF, flags)) == -1) { |
1013 | qDebug("error opening resolv.conf!"); | 1013 | qDebug("error opening resolv.conf!"); |
1014 | fd = open(DEVNULL, O_RDONLY); | 1014 | fd = open(DEVNULL, O_RDONLY); |
1015 | } | 1015 | } |
1016 | return fd; | 1016 | return fd; |
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | bool Modem::setHostname(const QString & name) | 1019 | bool Modem::setHostname(const QString & name) |
1020 | { | 1020 | { |
1021 | return sethostname(name, name.length()) == 0; | 1021 | return sethostname(name, name.length()) == 0; |
1022 | } | 1022 | } |
1023 | 1023 | ||