⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readconf.c

📁 OpenSSL Source code for SFTP, SSH, and many others
💻 C
📖 第 1 页 / 共 2 页
字号:
	case oGlobalKnownHostsFile2:		charptr = &options->system_hostfile2;		goto parse_string;	case oUserKnownHostsFile2:		charptr = &options->user_hostfile2;		goto parse_string;	case oHostName:		charptr = &options->hostname;		goto parse_string;	case oHostKeyAlias:		charptr = &options->host_key_alias;		goto parse_string;	case oPreferredAuthentications:		charptr = &options->preferred_authentications;		goto parse_string;	case oBindAddress:		charptr = &options->bind_address;		goto parse_string;	case oSmartcardDevice:		charptr = &options->smartcard_device;		goto parse_string;	case oProxyCommand:		charptr = &options->proxy_command;		string = xstrdup("");		while ((arg = strdelim(&s)) != NULL && *arg != '\0') {			string = xrealloc(string, strlen(string) + strlen(arg) + 2);			strcat(string, " ");			strcat(string, arg);		}		if (*activep && *charptr == NULL)			*charptr = string;		else			xfree(string);		return 0;	case oPort:		intptr = &options->port;parse_int:		arg = strdelim(&s);		if (!arg || *arg == '\0')			fatal("%.200s line %d: Missing argument.", filename, linenum);		if (arg[0] < '0' || arg[0] > '9')			fatal("%.200s line %d: Bad number.", filename, linenum);		/* Octal, decimal, or hex format? */		value = strtol(arg, &endofnumber, 0);		if (arg == endofnumber)			fatal("%.200s line %d: Bad number.", filename, linenum);		if (*activep && *intptr == -1)			*intptr = value;		break;	case oConnectionAttempts:		intptr = &options->connection_attempts;		goto parse_int;	case oCipher:		intptr = &options->cipher;		arg = strdelim(&s);		if (!arg || *arg == '\0')			fatal("%.200s line %d: Missing argument.", filename, linenum);		value = cipher_number(arg);		if (value == -1)			fatal("%.200s line %d: Bad cipher '%s'.",			    filename, linenum, arg ? arg : "<NONE>");		if (*activep && *intptr == -1)			*intptr = value;		break;	case oCiphers:		arg = strdelim(&s);		if (!arg || *arg == '\0')			fatal("%.200s line %d: Missing argument.", filename, linenum);		if (!ciphers_valid(arg))			fatal("%.200s line %d: Bad SSH2 cipher spec '%s'.",			    filename, linenum, arg ? arg : "<NONE>");		if (*activep && options->ciphers == NULL)			options->ciphers = xstrdup(arg);		break;	case oMacs:		arg = strdelim(&s);		if (!arg || *arg == '\0')			fatal("%.200s line %d: Missing argument.", filename, linenum);		if (!mac_valid(arg))			fatal("%.200s line %d: Bad SSH2 Mac spec '%s'.",			    filename, linenum, arg ? arg : "<NONE>");		if (*activep && options->macs == NULL)			options->macs = xstrdup(arg);		break;	case oHostKeyAlgorithms:		arg = strdelim(&s);		if (!arg || *arg == '\0')			fatal("%.200s line %d: Missing argument.", filename, linenum);		if (!key_names_valid2(arg))			fatal("%.200s line %d: Bad protocol 2 host key algorithms '%s'.",			    filename, linenum, arg ? arg : "<NONE>");		if (*activep && options->hostkeyalgorithms == NULL)			options->hostkeyalgorithms = xstrdup(arg);		break;	case oProtocol:		intptr = &options->protocol;		arg = strdelim(&s);		if (!arg || *arg == '\0')			fatal("%.200s line %d: Missing argument.", filename, linenum);		value = proto_spec(arg);		if (value == SSH_PROTO_UNKNOWN)			fatal("%.200s line %d: Bad protocol spec '%s'.",			    filename, linenum, arg ? arg : "<NONE>");		if (*activep && *intptr == SSH_PROTO_UNKNOWN)			*intptr = value;		break;	case oLogLevel:		intptr = (int *) &options->log_level;		arg = strdelim(&s);		value = log_level_number(arg);		if (value == SYSLOG_LEVEL_NOT_SET)			fatal("%.200s line %d: unsupported log level '%s'",			    filename, linenum, arg ? arg : "<NONE>");		if (*activep && (LogLevel) *intptr == SYSLOG_LEVEL_NOT_SET)			*intptr = (LogLevel) value;		break;	case oLocalForward:	case oRemoteForward:		arg = strdelim(&s);		if (!arg || *arg == '\0')			fatal("%.200s line %d: Missing port argument.",			    filename, linenum);		if ((fwd_port = a2port(arg)) == 0)			fatal("%.200s line %d: Bad listen port.",			    filename, linenum);		arg = strdelim(&s);		if (!arg || *arg == '\0')			fatal("%.200s line %d: Missing second argument.",			    filename, linenum);		if (sscanf(arg, "%255[^:]:%5[0-9]", buf, sfwd_host_port) != 2 &&		    sscanf(arg, "%255[^/]/%5[0-9]", buf, sfwd_host_port) != 2)			fatal("%.200s line %d: Bad forwarding specification.",			    filename, linenum);		if ((fwd_host_port = a2port(sfwd_host_port)) == 0)			fatal("%.200s line %d: Bad forwarding port.",			    filename, linenum);		if (*activep) {			if (opcode == oLocalForward)				add_local_forward(options, fwd_port, buf,				    fwd_host_port);			else if (opcode == oRemoteForward)				add_remote_forward(options, fwd_port, buf,				    fwd_host_port);		}		break;	case oDynamicForward:		arg = strdelim(&s);		if (!arg || *arg == '\0')			fatal("%.200s line %d: Missing port argument.",			    filename, linenum);		fwd_port = a2port(arg);		if (fwd_port == 0)			fatal("%.200s line %d: Badly formatted port number.",			    filename, linenum);		if (*activep)			add_local_forward(options, fwd_port, "socks4", 0);		break;	case oClearAllForwardings:		intptr = &options->clear_forwardings;		goto parse_flag;	case oHost:		*activep = 0;		while ((arg = strdelim(&s)) != NULL && *arg != '\0')			if (match_pattern(host, arg)) {				debug("Applying options for %.100s", arg);				*activep = 1;				break;			}		/* Avoid garbage check below, as strdelim is done. */		return 0;	case oEscapeChar:		intptr = &options->escape_char;		arg = strdelim(&s);		if (!arg || *arg == '\0')			fatal("%.200s line %d: Missing argument.", filename, linenum);		if (arg[0] == '^' && arg[2] == 0 &&		    (u_char) arg[1] >= 64 && (u_char) arg[1] < 128)			value = (u_char) arg[1] & 31;		else if (strlen(arg) == 1)			value = (u_char) arg[0];		else if (strcmp(arg, "none") == 0)			value = SSH_ESCAPECHAR_NONE;		else {			fatal("%.200s line %d: Bad escape character.",			    filename, linenum);			/* NOTREACHED */			value = 0;	/* Avoid compiler warning. */		}		if (*activep && *intptr == -1)			*intptr = value;		break;	case oDeprecated:		debug("%s line %d: Deprecated option \"%s\"",		    filename, linenum, keyword);		return 0;	default:		fatal("process_config_line: Unimplemented opcode %d", opcode);	}	/* Check that there is no garbage at end of line. */	if ((arg = strdelim(&s)) != NULL && *arg != '\0') {		fatal("%.200s line %d: garbage at end of line; \"%.200s\".",		     filename, linenum, arg);	}	return 0;}/* * Reads the config file and modifies the options accordingly.  Options * should already be initialized before this call.  This never returns if * there is an error.  If the file does not exist, this returns 0. */intread_config_file(const char *filename, const char *host, Options *options){	FILE *f;	char line[1024];	int active, linenum;	int bad_options = 0;	/* Open the file. */	f = fopen(filename, "r");	if (!f)		return 0;	debug("Reading configuration data %.200s", filename);	/*	 * Mark that we are now processing the options.  This flag is turned	 * on/off by Host specifications.	 */	active = 1;	linenum = 0;	while (fgets(line, sizeof(line), f)) {		/* Update line number counter. */		linenum++;		if (process_config_line(options, host, line, filename, linenum, &active) != 0)			bad_options++;	}	fclose(f);	if (bad_options > 0)		fatal("%s: terminating, %d bad configuration options",		    filename, bad_options);	return 1;}/* * Initializes options to special values that indicate that they have not yet * been set.  Read_config_file will only set options with this value. Options * are processed in the following order: command line, user config file, * system config file.  Last, fill_default_options is called. */voidinitialize_options(Options * options){	memset(options, 'X', sizeof(*options));	options->forward_agent = -1;	options->forward_x11 = -1;	options->xauth_location = NULL;	options->gateway_ports = -1;	options->use_privileged_port = -1;	options->rhosts_authentication = -1;	options->rsa_authentication = -1;	options->pubkey_authentication = -1;	options->challenge_response_authentication = -1;#if defined(KRB4) || defined(KRB5)	options->kerberos_authentication = -1;#endif#if defined(AFS) || defined(KRB5)	options->kerberos_tgt_passing = -1;#endif#ifdef AFS	options->afs_token_passing = -1;#endif	options->password_authentication = -1;	options->kbd_interactive_authentication = -1;	options->kbd_interactive_devices = NULL;	options->rhosts_rsa_authentication = -1;	options->hostbased_authentication = -1;	options->batch_mode = -1;	options->check_host_ip = -1;	options->strict_host_key_checking = -1;	options->compression = -1;	options->keepalives = -1;	options->compression_level = -1;	options->port = -1;	options->connection_attempts = -1;	options->number_of_password_prompts = -1;	options->cipher = -1;	options->ciphers = NULL;	options->macs = NULL;	options->hostkeyalgorithms = NULL;	options->protocol = SSH_PROTO_UNKNOWN;	options->num_identity_files = 0;	options->hostname = NULL;	options->host_key_alias = NULL;	options->proxy_command = NULL;	options->user = NULL;	options->escape_char = -1;	options->system_hostfile = NULL;	options->user_hostfile = NULL;	options->system_hostfile2 = NULL;	options->user_hostfile2 = NULL;	options->num_local_forwards = 0;	options->num_remote_forwards = 0;	options->clear_forwardings = -1;	options->log_level = SYSLOG_LEVEL_NOT_SET;	options->preferred_authentications = NULL;	options->bind_address = NULL;	options->smartcard_device = NULL;	options->no_host_authentication_for_localhost = - 1;}/* * Called after processing other sources of option data, this fills those * options for which no value has been specified with their default values. */voidfill_default_options(Options * options){	int len;	if (options->forward_agent == -1)		options->forward_agent = 0;	if (options->forward_x11 == -1)		options->forward_x11 = 0;	if (options->xauth_location == NULL)		options->xauth_location = _PATH_XAUTH;	if (options->gateway_ports == -1)		options->gateway_ports = 0;	if (options->use_privileged_port == -1)		options->use_privileged_port = 0;	if (options->rhosts_authentication == -1)		options->rhosts_authentication = 0;	if (options->rsa_authentication == -1)		options->rsa_authentication = 1;	if (options->pubkey_authentication == -1)		options->pubkey_authentication = 1;	if (options->challenge_response_authentication == -1)		options->challenge_response_authentication = 1;#if defined(KRB4) || defined(KRB5)	if (options->kerberos_authentication == -1)		options->kerberos_authentication = 1;#endif#if defined(AFS) || defined(KRB5)	if (options->kerberos_tgt_passing == -1)		options->kerberos_tgt_passing = 1;#endif#ifdef AFS	if (options->afs_token_passing == -1)		options->afs_token_passing = 1;#endif	if (options->password_authentication == -1)		options->password_authentication = 1;	if (options->kbd_interactive_authentication == -1)		options->kbd_interactive_authentication = 1;	if (options->rhosts_rsa_authentication == -1)		options->rhosts_rsa_authentication = 0;	if (options->hostbased_authentication == -1)		options->hostbased_authentication = 0;	if (options->batch_mode == -1)		options->batch_mode = 0;	if (options->check_host_ip == -1)		options->check_host_ip = 1;	if (options->strict_host_key_checking == -1)		options->strict_host_key_checking = 2;	/* 2 is default */	if (options->compression == -1)		options->compression = 0;	if (options->keepalives == -1)		options->keepalives = 1;	if (options->compression_level == -1)		options->compression_level = 6;	if (options->port == -1)		options->port = 0;	/* Filled in ssh_connect. */	if (options->connection_attempts == -1)		options->connection_attempts = 1;	if (options->number_of_password_prompts == -1)		options->number_of_password_prompts = 3;	/* Selected in ssh_login(). */	if (options->cipher == -1)		options->cipher = SSH_CIPHER_NOT_SET;	/* options->ciphers, default set in myproposals.h */	/* options->macs, default set in myproposals.h */	/* options->hostkeyalgorithms, default set in myproposals.h */	if (options->protocol == SSH_PROTO_UNKNOWN)		options->protocol = SSH_PROTO_1|SSH_PROTO_2;	if (options->num_identity_files == 0) {		if (options->protocol & SSH_PROTO_1) {			len = 2 + strlen(_PATH_SSH_CLIENT_IDENTITY) + 1;			options->identity_files[options->num_identity_files] =			    xmalloc(len);			snprintf(options->identity_files[options->num_identity_files++],			    len, "~/%.100s", _PATH_SSH_CLIENT_IDENTITY);		}		if (options->protocol & SSH_PROTO_2) {			len = 2 + strlen(_PATH_SSH_CLIENT_ID_RSA) + 1;			options->identity_files[options->num_identity_files] =			    xmalloc(len);			snprintf(options->identity_files[options->num_identity_files++],			    len, "~/%.100s", _PATH_SSH_CLIENT_ID_RSA);			len = 2 + strlen(_PATH_SSH_CLIENT_ID_DSA) + 1;			options->identity_files[options->num_identity_files] =			    xmalloc(len);			snprintf(options->identity_files[options->num_identity_files++],			    len, "~/%.100s", _PATH_SSH_CLIENT_ID_DSA);		}	}	if (options->escape_char == -1)		options->escape_char = '~';	if (options->system_hostfile == NULL)		options->system_hostfile = _PATH_SSH_SYSTEM_HOSTFILE;	if (options->user_hostfile == NULL)		options->user_hostfile = _PATH_SSH_USER_HOSTFILE;	if (options->system_hostfile2 == NULL)		options->system_hostfile2 = _PATH_SSH_SYSTEM_HOSTFILE2;	if (options->user_hostfile2 == NULL)		options->user_hostfile2 = _PATH_SSH_USER_HOSTFILE2;	if (options->log_level == SYSLOG_LEVEL_NOT_SET)		options->log_level = SYSLOG_LEVEL_INFO;	if (options->clear_forwardings == 1)		clear_forwardings(options);	if (options->no_host_authentication_for_localhost == - 1)		options->no_host_authentication_for_localhost = 0;	/* options->proxy_command should not be set by default */	/* options->user will be set in the main program if appropriate */	/* options->hostname will be set in the main program if appropriate */	/* options->host_key_alias should not be set by default */	/* options->preferred_authentications will be set in ssh */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -