コード例 #1
0
ファイル: parser.c プロジェクト: khKhKhEtelKhKhkh/torsocks
static int handle_line(struct parsedfile *config, char *line, int lineno) {
    char *words[10];
    static char savedline[MAXLINE];
    int   nowords = 0, i;

    /* Save the input string */
    strncpy(savedline, line, MAXLINE - 1);
    savedline[MAXLINE - 1] = (char) 0;
    /* Tokenize the input string */
    nowords = tokenize(line, 10, words);

    /* Set the spare slots to an empty string to simplify */
    /* processing                                         */
    for (i = nowords; i < 10; i++)
        words[i] = NULL;

    if (nowords > 0) {
        /* Now this can either be a "path" block starter or */
        /* ender, otherwise it has to be a pair (<name> =   */
        /* <value>)                                         */
        if (!strcmp(words[0], "path")) {
            handle_path(config, lineno, nowords, words);
        } else if (!strcmp(words[0], "}")) {
            handle_endpath(config, lineno, nowords);
        } else {
            /* Has to be a pair */
            if ((nowords != 3) || (strcmp(words[1], "="))) {
                show_msg(MSGERR, "Malformed configuration pair "
                       "on line %d in configuration "
                       "file, \"%s\"\n", lineno, savedline);
            } else if (!strcmp(words[0], "reaches")) {
                handle_reaches(lineno, words[2]);
            } else if (!strcmp(words[0], "server")) {
                handle_server(config, lineno, words[2]);
            } else if (!strcmp(words[0], "server_port")) {
                handle_port(config, lineno, words[2]);
            } else if (!strcmp(words[0], "server_type")) {
                handle_type(config, lineno, words[2]);
            } else if (!strcmp(words[0], "default_user")) {
                handle_defuser(config, lineno, words[2]);
            } else if (!strcmp(words[0], "default_pass")) {
                handle_defpass(config, lineno, words[2]);
            } else if (!strcmp(words[0], "local")) {
                handle_local(config, lineno, words[2]);
            } else if (!strcmp(words[0], "tordns_enable")) {
                handle_tordns_enabled(config, lineno, words[2]);
            } else if (!strcmp(words[0], "tordns_deadpool_range")) {
                handle_tordns_deadpool_range(config, lineno, words[2]);
            } else if (!strcmp(words[0], "tordns_cache_size")) {
                handle_tordns_cache_size(config, words[2]);
            } else {
                show_msg(MSGERR, "Invalid pair type (%s) specified "
                       "on line %d in configuration file, "
                       "\"%s\"\n", words[0], lineno,
                       savedline);
            }
        }
    }

    return(0);
}
コード例 #2
0
ファイル: parser.c プロジェクト: khKhKhEtelKhKhkh/torsocks
int read_config (char *filename, struct parsedfile *config) {
    FILE *conf;
    char line[MAXLINE];
    int rc = 0;
    int lineno = 1;
    struct serverent *server;

   /* Clear out the structure */
   memset(config, 0x0, sizeof(*config));

   /* Initialization */
   currentcontext = &(config->defaultserver);

   /* Tordns defaults */
   config->tordns_cache_size = 256;
   config->tordns_enabled = 1;


    /* If a filename wasn't provided, use the default */
    if (filename == NULL) {
        strncpy(line, CONF_FILE, sizeof(line) - 1);
        /* Insure null termination */
        line[sizeof(line) - 1] = (char) 0;
        filename = line;
        show_msg(MSGWARN, "Configuration file not provided by TORSOCKS_CONF_FILE "
                "environment variable, attempting to use defaults in %s.\n", filename);
    }

    /* If there is no configuration file use reasonable defaults for Tor */
    if ((conf = fopen(filename, "r")) == NULL) {
        show_msg(MSGERR, "Could not open socks configuration file "
                "(%s) errno (%d), assuming sensible defaults for Tor.\n", filename, errno);
        memset(&(config->defaultserver), 0x0, sizeof(config->defaultserver));
        check_server(&(config->defaultserver));
        handle_local(config, 0, "127.0.0.0/255.0.0.0");
        handle_local(config, 0, "10.0.0.0/255.0.0.0");
        handle_local(config, 0, "192.168.0.0/255.255.0.0");
        handle_local(config, 0, "172.16.0.0/255.240.0.0");
        handle_local(config, 0, "169.254.0.0/255.255.0.0");
        rc = 1; /* Severe errors reading configuration */
    } else {
        memset(&(config->defaultserver), 0x0, sizeof(config->defaultserver));

        while (NULL != fgets(line, MAXLINE, conf)) {
            /* This line _SHOULD_ end in \n so we  */
            /* just chop off the \n and hand it on */
            if (strlen(line) > 0)
                line[strlen(line) - 1] = '\0';
            handle_line(config, line, lineno);
            lineno++;
        }
        fclose(conf);

        /* Always add the 127.0.0.1/255.0.0.0 subnet to local */
        handle_local(config, 0, "127.0.0.0/255.0.0.0");
        /* We always consider this local, because many users' dsl
          routers act as their DNS. */
        handle_local(config, 0, "10.0.0.0/255.0.0.0");
        handle_local(config, 0, "192.168.0.0/255.255.0.0");
        handle_local(config, 0, "172.16.0.0/255.240.0.0");
        handle_local(config, 0, "169.254.0.0/255.255.0.0");
        handle_local(config, 0, "192.168.0.0/255.255.0.0");

        /* Check default server */
        check_server(&(config->defaultserver));
        server = (config->paths);
        while (server != NULL) {
            check_server(server);
            server = server->next;
        }
    }

    /* Initialize tordns deadpool_range if not supplied */
    if(config->tordns_deadpool_range == NULL) {
        handle_tordns_deadpool_range(config, 0, "127.0.69.0/255.255.255.0");
    }

    return(rc);
}
コード例 #3
0
ファイル: parser.c プロジェクト: Shouqun/tsocks_for_mac
int read_config (char *filename, struct parsedfile *config) {
	FILE *conf;
	char line[MAXLINE];
	int rc = 0;
	int lineno = 1;
	struct serverent *server;

   /* Clear out the structure */
   memset(config, 0x0, sizeof(*config));

   /* Initialization */
   currentcontext = &(config->defaultserver);

   /* Tordns defaults */
   config->tordns_cache_size = 256;
   config->tordns_enabled = 1;

	/* If a filename wasn't provided, use the default */
	if (filename == NULL) {
		strncpy(line, CONF_FILE, sizeof(line) - 1);
		/* Insure null termination */
		line[sizeof(line) - 1] = (char) 0;
		filename = line;
	}

	/* Read the configuration file */
	if ((conf = fopen(filename, "r")) == NULL) {
		show_msg(MSGERR, "Could not open socks configuration file "
			   "(%s), assuming all networks local\n", filename);
        handle_local(config, 0, "0.0.0.0/0.0.0.0");
		rc = 1; /* Severe errors reading configuration */
	}	
	else {
      memset(&(config->defaultserver), 0x0, sizeof(config->defaultserver));

		while (NULL != fgets(line, MAXLINE, conf)) {
			/* This line _SHOULD_ end in \n so we  */
			/* just chop off the \n and hand it on */
			if (strlen(line) > 0)
				line[strlen(line) - 1] = '\0';
			handle_line(config, line, lineno);
			lineno++;
		} 
		fclose(conf);

		if (!config->localnets) {
                        /* Use 127.0.0.1/255.0.0.0 by default */
                        handle_local(config, 0, "127.0.0.0/255.0.0.0");
                }


		/* Check default server */
		check_server(&(config->defaultserver));
		server = (config->paths);
		while (server != NULL) {
			check_server(server);
			server = server->next;
		}
	}

    /* Initialize tordns deadpool_range if not supplied */
    if(config->tordns_deadpool_range == NULL) {
        handle_tordns_deadpool_range(config, 0, "127.0.69.0/255.255.255.0");
    }

	return(rc);
}