Example #1
0
int lock_type_unlock(int type)
{
	char *name;
	char *device;
	int	i;
	int   size;

	lock_init_locknames();

	if (!(device = rindex(setup.modem.device, '/')))
		device = setup.modem.device;
	else
		device++;
	
	i = 0;
	
	while (TRUE)
	{
		if (locks[i].file == NULL)
		{
			log(L_WARN, "Lock setup for type %d not found.\n", type);

			returnerror();
		}

		if (locks[i].type == type) break;

		i++;
	}

	size = (strlen(locks[i].file) + strlen(device) + 2);
	
	if ((name = (char *)malloc(size)))
	{
		printstring(name, locks[i].file, device);

		log(L_DEBUG, "Unlocking %s (%s)...\n", locks[i].desc, name);

		if (*(locks[i].fd) != -1)
		{
			lock_unlocking(*(locks[i].fd), 5);

			close(*(locks[i].fd));

			*(locks[i].fd) = -1;
		}

		if (unlink(name) != 0)
		{
			log(L_WARN, "Can't remove lock \"%s\".\n", name);
		}

		free(name);

		returnok();
	}
	else log(L_FATAL, "Not enough memory to allocate lockname.\n");
				
	returnerror();
}
Example #2
0
int cLibVBOX::vboxd_test_response(const char *response)
{
	if (strlen(vboxd_message) > (strlen(response) + 1))
	{
		if (strncmp(response, vboxd_message, strlen(response)) == 0)
		{
			if (vboxd_message[strlen(response)] == ' ') returnok();
		}
	}

	returnerror();
}
Example #3
0
static int lock_unlocking(int fd, int trys)
{
	while (trys > 0)
	{
		if (flock(fd, LOCK_UN) == 0) returnok();
            
		xpause(1000);
                  
		trys--;
	}

	returnerror();
}
Example #4
0
static int voice_set_compression(short c)
{
	char command[64];

	if ((c >= 2) && (c <= 6) && (c != 5))
	{
		printstring(command, "AT+VSM=%d+VLS=2", c);

		log(L_DEBUG, "Setting voice compression \"%s\"...\n", compressions[c]);

		return(modem_command(command, "OK|VCON"));
	}

	log(L_FATAL, "Unknown compression %d - can't set.\n", c);
	
	returnerror();
}
Example #5
0
int lock_type_lock(int type)
{
	char *name;
	char	temp[32];
	char *device;
	int	i;
	int   size;

	lock_init_locknames();

	if (!(device = rindex(setup.modem.device, '/')))
		device = setup.modem.device;
	else
		device++;
	
	i = 0;
	
	while (TRUE)
	{
		if (locks[i].file == NULL)
		{
			log(L_WARN, "Lock setup for type %d not found.\n", type);

			returnerror();
		}

		if (locks[i].type == type) break;

		i++;
	}

	size = (strlen(locks[i].file) + strlen(device) + 2);
	
	if ((name = (char *)malloc(size)))
	{
		printstring(name, locks[i].file, device);

		log(L_DEBUG, "Locking %s (%s)...\n", locks[i].desc, name);

		if (*(locks[i].fd) == -1)
		{
			if ((*(locks[i].fd) = open(name, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != -1)
			{
				if (lock_locking(*(locks[i].fd), 5))
				{
					printstring(temp, "%d\n", getpid());

					write(*(locks[i].fd), temp, strlen(temp));

						/*
						 * Set permissions but make the locks readable to
						 * all (overrides umask).
						 */

					permissions_set(name, setup.users.uid, setup.users.gid, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH, (setup.users.umask & ~(S_IRUSR|S_IRGRP|S_IROTH)));

					free(name);
					returnok();
				}
				else log(L_FATAL, "Can't lock \"%s\".\n", name);
			}
			else log(L_FATAL, "Can't create \"%s\".\n", name);
		}
		else
		{
			log(L_WARN, "Use existing lock for \"%s\" (%d).\n", name, *(locks[i].fd));
					
			free(name);
			returnok();
		}
	}
	else log(L_FATAL, "Not enough memory to allocate lockname.\n");
				
	returnerror();
}
Example #6
0
int init_program(char *device, char *gettyrc)
{
	struct passwd *passwd;

	setup.modem.device	= device;
	setup.vboxrc			= NULL;
	setup.vboxrcname[0]	= '\0';
	setup.vboxctrl[0]		= '\0';
	setup.spool[0]			= '\0';
	setup.freespace		= 0;

	/* 
	 * Initialize the log and start the session. The name of the log
	 * is stored into the global setup.
	 */

	if (!log_init()) returnerror();

	log(L_INFO, "-----------------------[Begin session]----------------------\n");
	log(L_INFO, "Running vbox version %s...\n", VERSION);

	/*
	 * Check the version of the tcl interpreter. On bad version only
	 * a warning is displayed.
	 */

	script_check_interpreter();

	/*
	 * Parse vboxgetty.conf. This function will init the most fields
	 * in the global structure.
	 */

	if (!getty_get_settings(gettyrc)) returnerror();

	/*
	 * If the UID or GID is 0 (no user is set) return with error and
	 * exit.
	 */

	if ((setup.users.uid == 0) || (setup.users.gid == 0))
	{
		log(L_FATAL, "You *must* set a user/group (not root)!\n");

		returnerror();
	}

	/*
	 * Get the user settings from /etc/passwd. The name and the home
	 * directory are stored into the global structure.
	 */

	if (!(passwd = getpwuid(setup.users.uid)))
	{
		log(L_FATAL, "Can't get passwd entry for userid %d.\n", setup.users.uid);

		returnerror();
	}

	xstrncpy(setup.users.name, passwd->pw_name, USER_MAX_NAME);
	xstrncpy(setup.users.home, passwd->pw_dir , USER_MAX_HOME);

	if (!*setup.spool)
	{
		xstrncpy(setup.spool, SPOOLDIR		  , SETUP_MAX_SPOOLNAME);
		xstrncat(setup.spool, "/"				  , SETUP_MAX_SPOOLNAME);
		xstrncat(setup.spool, setup.users.name, SETUP_MAX_SPOOLNAME);
	}

	if (!*setup.vboxrcname)
	{
		xstrncpy(setup.vboxrcname, setup.spool , SETUP_MAX_VBOXRC);
		xstrncat(setup.vboxrcname, "/vbox.conf", SETUP_MAX_VBOXRC);
	}

	log(L_INFO, "User %s's messagebox is \"%s\"...\n", setup.users.name, setup.spool);
	log(L_INFO, "User %s's vbox.conf is \"%s\"...\n", setup.users.name, setup.vboxrcname);

	/*
	 * Create the spool directory and set the permissions to the current
	 * user (with umask).
	 */

	if ((mkdir(setup.spool, S_IRWXU) == -1) && (errno != EEXIST))
	{
		log(L_FATAL, "Can't create \"%s\" (%s).\n", setup.spool, strerror(errno));

		returnerror();
	}

	if (!permissions_set(setup.spool, setup.users.uid, setup.users.gid, S_IRWXU|S_IRWXG|S_IRWXO, setup.users.umask))
	{
		returnerror();
	}

	/*
	 * Now we check if 'vboxctrl-stop' exists. If true, loop and watch
	 * if the files is deleted.
	 */

	if (ctrl_ishere(setup.spool, CTRL_NAME_STOP))
	{
		log(L_INFO, "Control file \"%s\" exists - waiting...\n", CTRL_NAME_STOP);

		while (ctrl_ishere(setup.spool, CTRL_NAME_STOP))
		{
			log(L_JUNK, "Control file \"%s\" exists - waiting...\n", CTRL_NAME_STOP);

			xpause(5000);
		}

		log(L_INFO, "Control file deleted - back in business...\n");
	}

	if (ctrl_ishere(setup.spool, CTRL_NAME_ANSWERNOW))
	{
		if (!ctrl_remove(setup.spool, CTRL_NAME_ANSWERNOW))
		{
			log(L_WARN, "Can't remove control file \"%s\"!\n", CTRL_NAME_ANSWERNOW);
		}
	}

	if (ctrl_ishere(setup.spool, CTRL_NAME_REJECT))
	{
		if (!ctrl_remove(setup.spool, CTRL_NAME_REJECT))
		{
			log(L_WARN, "Can't remove control file \"%s\"!\n", CTRL_NAME_REJECT);
		}
	}

	/*
	 * Open the modem device - this *must* done under the rights of
	 * the root user!
	 */

	if (!modem_open_port()) returnerror();

	/*
	 * Lock the modem port and create the pid file. After this the
	 * filepermissions will set to the user, so he can delete this
	 * files if the getty quit.
	 */

	if (!lock_type_lock(LCK_PID  )) returnerror();
	if (!lock_type_lock(LCK_MODEM)) returnerror();

	/*
	 * Drop root privilegs to the current user and set the correct
	 * umask.
	 */

	if (!permissions_drop(setup.users.uid, setup.users.gid, setup.users.name, setup.users.home))
	{
		returnerror();
	}

	umask(setup.users.umask);

	/*
	 * Load vbox's configuration into memory and initialize the voice
	 * defaults.
	 */

	if (!(setup.vboxrc = streamio_open(setup.vboxrcname)))
	{
		log(L_FATAL, "Can't open \"%s\".\n", setup.vboxrcname);

		returnerror();
	}

	voice_init_section();

	/*
	 * Now the complete global setup structure is filled and can be
	 * used.
	 */

	returnok();
}