Esempio n. 1
0
static char *input_string(const char *message)
{
	char *input;

	printf(_(message));
	for (;;) {
#ifdef HAVE_LIBREADLINE
		input = readline(">");
#else
		printf(">");
		input = str_fgets(stdin);
#endif
		if (input[0] != '\0') {
			break;
		}
	}
	printf("\n");

	return (input);
}
Esempio n. 2
0
char*
file_read_line (file_t *file)
{
  return str_fgets(file->handle);
}
Esempio n. 3
0
static void parse_file_list(FileData *file_data, int num_paths, const char *lsfile, const char *path_dir, AccessMethod method, int host)
{
	FileState *file_state = NULL;
	FILE *fp;
	char *path_file;
	char *temp;
	char *text;

	char *name;
	time_t time;
	off_t size;
	mode_t mode;
	int type;

	char *ssh_command;
	int num_files = 0;

	fp = fopen(lsfile, "r");
	if (fp == NULL) {
		perror("fopen");
		fprintf(stderr, _("Cannot open file `%s'.\n"), lsfile);
		fatal_error(host);
	}

	while ((text = str_fgets(fp)) != NULL) {
		if (strncmp(text, "total", 5) == 0) { /* skip */
			free(text);
			continue;
		}
		if (strncmp(text, "/bin/ls:", 8) == 0) {
			fprintf(stderr, _("Listing remote directory contents failed: %s\nThe directory doesn't exist or permission denied.\n"), path_dir);
			fatal_error(host);
		}

		switch (method) {
		case FTP:
			ftp_extract_file_status(text, &name, &size, &mode, &type, host);
			break;
		case SCP:
		case RSYNC:
			ssh_extract_file_status(text, &name, &time, &size, &mode, &type, host);
			break;
		default:
			internal_error(__FILE__, __LINE__);
		} 
		free(text);

		if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
			free(name);
			continue;
		}

		path_file = str_concat(path_dir, "/", name, NULL);

		if (type == 'l') { /* Check whether the symbolic link is directory or not. */
			switch (method) {
			case FTP:
				type = ftp_chdir(path_file) ? 'd' : '-';
				break;
			case SCP:
			case RSYNC:
				ssh_command = str_dup_printf("ssh %s@%s cd %s", config.login_name[host], config.host_name[host], path_file);
				type = (system(ssh_command) == 0) ? 'd' : '-';
				free(ssh_command);
				break;
			default:
				internal_error(__FILE__, __LINE__);
			}
		}

		if ((type == 'd' && is_match_dir(path_file, config.ignore_remote_dir[host], host)) ||
		    (type != 'd' && (is_match_file(path_file, path_dir, config.ignore_remote_file[host], host) ||
				     is_match_file(path_file, path_dir, config.ignore_file[host], host)))) {
			free(path_file);
			free(name);
			continue;
		}

		if (config.conv_to_lower[host]) {
			temp = str_tolower(name);
			free(name);
			name = temp;

			free(path_file);
			path_file = str_concat(path_dir, "/", name, NULL);
		}

		if (method == FTP) {
			if (type != 'd') {
				time = ftp_get_last_modification_time(path_file, host);
			} else {
				time = 0;
			}
		}

                file_state = str_realloc(file_state, (num_files + 1) * sizeof(FileState));
		file_state[num_files].name = name;
		file_state[num_files].time = time;
		file_state[num_files].size = size;
		file_state[num_files].mode = mode;
		file_state[num_files].isdir = (type == 'd');
		file_state[num_files].isremoved = FALSE;

		num_files++;

		free(path_file);
	}

	if (fclose(fp) != 0) {
		perror("fclose");
		fprintf(stderr, _("Cannot close file `%s'.\n"), lsfile);
		fatal_error(host);
        }

	sort_file_state(file_state, num_files);

	file_data->path_state[num_paths].num_files = num_files;
	file_data->path_state[num_paths].file_state = file_state;
}
Esempio n. 4
0
static void configure_host(int host_num, int hasdefault)
{
	char *input;
	char password[128];
	int i;

	struct {
		char *parameter_name;
		char **variable;
		char *message;
	} question_table[] = {
		{ "HostName",     config.host_name,
		  _("Enter remote host name or IP address. (e.g., ftp.myhost.org, 192.168.0.1)\n") },
		{ "LoginName",    config.login_name,
		  _("Enter login name of the account.\n"), },
		{ "Password",     config.password,
		  _("Enter password granting access to the account.\n"), },
		{ "LocalTopDir",  config.local_top_dir,
		  _("Enter local top directory. It must be specified as absolute path.\n(e.g., /home/foo/www)\n"), },
		{ "RemoteTopDir", config.remote_top_dir,
		  _("Enter remote top directory. It must be specified as absolute path.\n(e.g., /public_html)\n"), },
	};

	for (i = 0; i < sizeof(question_table) / sizeof(question_table[0]); i++) {
		printf(question_table[i].message);

		if (strcmp(question_table[i].parameter_name, "Password") == 0) {
			for (;;) {
				if (hasdefault == DEFAULT_EXIST) {
					printf(_("Just press enter to leave default. (default is: ********)\n"));
				}
				input = getpass(">");
				if (input[0] == '\0') {
					if (hasdefault == DEFAULT_EXIST) {
						printf(_("Not changed.\n"));
						break;
					}
					continue;
				}
				strcpy(password, input);
				printf(_("\nRetype password for confirmation.\n"));
				input = getpass(">");
				if (strcmp(password, input) != 0) {
					printf(_("\nPasswords do not match.\n\n"));
					printf(question_table[i].message);
					continue;
				}
				cfgStoreValue(config_table, question_table[i].parameter_name, input, CFG_INI, host_num);
				break;
			}
		} else {
			if (hasdefault == DEFAULT_EXIST) {
				printf(_("Just press enter to leave default. (default is: %s)\n"), question_table[i].variable[host_num]);
			}
			for (;;) {
#ifdef HAVE_LIBREADLINE
				input = readline(">");
#else
				printf(">");
				input = str_fgets(stdin);
#endif
				if (input[0] != '\0') {
					cfgStoreValue(config_table, question_table[i].parameter_name, input, CFG_INI, host_num);
					break;
				} else {
					free(input);
					if (hasdefault == DEFAULT_EXIST) {
						printf(_("Not changed.\n"));
						break;
					}
				}
			}
		}
		printf("\n");
	}
}