void quit_program(int rc) { set_process_permissions(0, 0, xstrtoo(VBOX_ROOT_UMASK, 0)); modem_hangup(&vboxmodem); log_line(LOG_D, "Closing modem device (%d)...\n", vboxmodem.fd); if (vboxmodem_close(&vboxmodem) != 0) { log_line(LOG_E, "%s (%s)\n", vboxmodem_error(), strerror(errno)); } if (isdnttyname) { printstring(temppathname, "%s/LCK..%s", LOCKDIR, isdnttyname); lock_remove(temppathname); printstring(temppathname, "%s/vboxgetty-%s.pid", PIDDIR, isdnttyname); pid_remove(temppathname); } scr_remove_interpreter(); rc_free(rc_getty_c); breaklist_clear(); log_close(); exit(rc); }
void check_duplicate_key (word keyno) { // int fd; activation_key (); if (registered && serial_no == keyno) { status_line ("!Duplicate key detected"); modem_hangup (); /* memset (config, 0, sizeof (struct _configuration)); fd = open (config_file, O_WRONLY|O_BINARY); write (fd, config, sizeof (struct _configuration)); close (fd); fclose (logf); logf = fopen ("SECURITY.CHK", "at"); status_line ("!Security breach"); fclose (logf); _dos_setfileattr ("SECURITY.CHK", _A_RDONLY|_A_HIDDEN|_A_SYSTEM); */ } }
void main(int argc, char **argv) { char *stop; int opts; char *debugstr; int debuglvl; int i; int modemstate; int modeminits; breaklist_init(); progbasename = argv[0]; if ((stop = rindex(argv[0], '/'))) progbasename = ++stop; /* Die Argumente des Programms einlesen und den Debuglevel */ /* setzen. */ debugstr = NULL; isdnttyname = NULL; while ((opts = getopt_long(argc, argv, "vhx:d:", arguments, (int *)0)) != EOF) { switch (opts) { case 'x': debugstr = optarg; break; case 'd': isdnttyname = optarg; break; case 'v': show_usage(200, 0); break; case 'h': default: show_usage(200, 1); break; } } if (debugstr) { if (strcasecmp(debugstr, "FULL") != 0) { debuglvl = LOG_E; for (i = 0; i < strlen(debugstr); i++) { switch (debugstr[i]) { case 'W': case 'w': debuglvl |= LOG_W; break; case 'I': debuglvl |= LOG_I; break; case 'A': debuglvl |= LOG_A; break; case 'D': debuglvl |= LOG_D; break; } } } else debuglvl = LOG_X; log_set_debuglevel(debuglvl); } umask(xstrtoo(VBOX_ROOT_UMASK, 0)); /* Pfadangaben vom Devicenamen abschneiden und überprüfen ob */ /* das Device vom Benutzer gelesen und beschrieben werden */ /* kann (eigentlich nicht nötig, da nur unter Rootrechten ge- */ /* startet werden kann. */ if (isdnttyname) { if ((stop = rindex(isdnttyname, '/'))) isdnttyname = ++stop; printstring(savettydname, "%s" , isdnttyname); printstring(temppathname, "/dev/%s", isdnttyname); if (access(temppathname, F_OK|R_OK|W_OK) != 0) { fprintf(stderr, "\n%s: error: \"%s\" doesn't exist or is not accessible!\n\n", progbasename, temppathname); quit_program(100); } } else { fprintf(stderr, "\n%s: error: isdn tty name is required!\n", progbasename); show_usage(100, 1); } /* Prüfen ob das Programm unter Rootrechten gestartet wurde. Die */ /* Rechte werden später auf die des jeweiligen Benutzers geän- */ /* dert, zum Start sind aber Rootrechte nötig. */ if (getuid() != 0) { fprintf(stderr, "\n%s: error: need root privilegs to start!\n\n", progbasename); quit_program(100); } /* Jetzt wird der Log geöffnet. Der Name des aktuellen Devices */ /* wird an das Ende angehängt. */ printstring(temppathname, "%s/vboxgetty-%s.log", LOGDIR, isdnttyname); log_open(temppathname); /* Tcl-Interpreter starten. Für die momentanen Funktionen wird */ /* Version 8 oder höher benötigt. */ if (scr_create_interpreter() == -1) { log_line(LOG_E, "Can't create/initialize the tcl interpreter!\n"); quit_program(100); } log_line(LOG_I, "Running vbox version %s (with tcl version %s).\n", VERSION, scr_tcl_version()); /* Konfiguration des getty's abarbeiten. Zuerst wird die globale, */ /* dann die des jeweiligen tty's eingelesen. */ if (vboxgettyrc_parse(isdnttyname) == -1) { log_line(LOG_E, "Unable to read/parse configuration!\n"); quit_program(100); } /* Modem Device öffnen und die interne Initialisierung */ /* ausführen (nicht der normale Modeminit). */ printstring(temppathname, "/dev/%s", isdnttyname); log_line(LOG_D, "Opening modem device \"%s\" (38400, CTS/RTS)...\n", temppathname); if (vboxmodem_open(&vboxmodem, temppathname) == -1) { log_line(LOG_E, "Can't open/setup modem device (%s).\n", vboxmodem_error()); quit_program(100); } /* Lock- und PID-Datei für den getty und das entsprechende */ /* Device erzeugen. */ printstring(temppathname, "%s/LCK..%s", LOCKDIR, isdnttyname); if (lock_create(temppathname) == -1) quit_program(100); printstring(temppathname, "%s/vboxgetty-%s.pid", PIDDIR, isdnttyname); pid_create(temppathname); /* Signalhändler installieren. Alle möglichen Signale werden */ /* auf quit_program() umgelenkt. */ signal(SIGINT , quit_program); signal(SIGTERM, quit_program); signal(SIGHUP , quit_program); /* Hauptloop: Der Loop wird nur verlassen, wenn während der */ /* Abarbeitung ein Fehler aufgetreten ist. Das Programm be- */ /* endet sich danach! */ modemstate = VBOXMODEM_STAT_INIT; modeminits = 0; while (modemstate != VBOXMODEM_STAT_EXIT) { switch (modemstate) { case VBOXMODEM_STAT_INIT: if (run_modem_init() == -1) { if ((i = (int)xstrtol(rc_get_entry(rc_getty_c, "badinitsexit"), 10)) > 0) { modeminits++; if (modeminits >= i) { modemstate = VBOXMODEM_STAT_EXIT; modeminits = 0; log_line(LOG_E, "Exit program while bad init limit are reached.\n"); } else log_line(LOG_W, "Bad initialization - Program will exist on %d trys!\n", (i - modeminits)); } } else { modemstate = VBOXMODEM_STAT_WAIT; modeminits = 0; } break; case VBOXMODEM_STAT_WAIT: modem_flush(&vboxmodem, 0); if (modem_wait(&vboxmodem) == 0) { modemstate = VBOXMODEM_STAT_RING; modeminits = 0; } else modemstate = VBOXMODEM_STAT_TEST; break; case VBOXMODEM_STAT_TEST: log_line(LOG_D, "Checking if modem is still alive...\n"); if (modem_command(&vboxmodem, "AT", "OK") > 0) { modemstate = VBOXMODEM_STAT_WAIT; modeminits = 0; } else modemstate = VBOXMODEM_STAT_INIT; break; case VBOXMODEM_STAT_RING: modem_set_nocarrier(&vboxmodem, 0); process_incoming_call(); modem_hangup(&vboxmodem); if (set_process_permissions(0, 0, xstrtoo(VBOX_ROOT_UMASK, 0)) != 0) modemstate = VBOXMODEM_STAT_EXIT; else modemstate = VBOXMODEM_STAT_INIT; break; default: log_line(LOG_E, "Unknown modem status %d!\n", modemstate); modemstate = VBOXMODEM_STAT_INIT; break; } } quit_program(0); }