コード例 #1
0
ファイル: urename.c プロジェクト: taysom/tau
int main (int argc, char *argv[])
{
	int		rc;
	unsigned	i;
	unsigned	n = 1000;
	u64		l;

	punyopt(argc, argv, NULL, NULL);
	n = Option.iterations;
	make_names(Option.file);
	for (l = 0; l < Option.loops; l++) {
		startTimer();
		for (i = 0; i < n; ++i) {
			rc = rename(NameA, NameB);
			if (rc == -1) {
				perror("renameAB");
				exit(1);
			}
			rc = rename(NameB, NameC);
			if (rc == -1) {
				perror("renameBC");
				exit(1);
			}
			rc = rename(NameC, NameA);
			if (rc == -1) {
				perror("renameCA");
				exit(1);
			}
		}
		stopTimer();
		prTimer();
		printf("\n");
	}
	return 0;
}
コード例 #2
0
ファイル: cdate.c プロジェクト: mbrock/bigloo-llvm
/*---------------------------------------------------------------------*/
obj_t
bgl_month_aname( int month ) {
   static obj_t names = BNIL;
   
   if( names == BNIL ) names = make_names( 12, "%b" );

   return VECTOR_REF( names, month-1 );
}
コード例 #3
0
ファイル: cdate.c プロジェクト: mbrock/bigloo-llvm
/*---------------------------------------------------------------------*/
obj_t
bgl_day_aname( int day ) {
   static obj_t names = BNIL;
   
   if( names == BNIL ) names = make_names( 7, "%a" );

   return VECTOR_REF( names, day-1 );
}
コード例 #4
0
ファイル: tincd.c プロジェクト: Rumko/tinc
int main(int argc, char **argv) {
	program_name = argv[0];

	if(!parse_options(argc, argv))
		return 1;
	
	make_names();

	if(show_version) {
		printf("%s version %s (built %s %s, protocol %d)\n", PACKAGE,
			   VERSION, __DATE__, __TIME__, PROT_CURRENT);
		printf("Copyright (C) 1998-2010 Ivo Timmermans, Guus Sliepen and others.\n"
				"See the AUTHORS file for a complete list.\n\n"
				"tinc comes with ABSOLUTELY NO WARRANTY.  This is free software,\n"
				"and you are welcome to redistribute it under certain conditions;\n"
				"see the file COPYING for details.\n");

		return 0;
	}

	if(show_help) {
		usage(false);
		return 0;
	}

	if(kill_tincd)
		return !kill_other(kill_tincd);

	openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR);

	g_argv = argv;

	init_configuration(&config_tree);

	/* Slllluuuuuuurrrrp! */

	RAND_load_file("/dev/urandom", 1024);

	ENGINE_load_builtin_engines();
	ENGINE_register_all_complete();

	OpenSSL_add_all_algorithms();

	if(generate_keys) {
		read_server_config();
		return !keygen(generate_keys);
	}

	if(!read_server_config())
		return 1;

#ifdef HAVE_LZO
	if(lzo_init() != LZO_E_OK) {
		logger(LOG_ERR, "Error initializing LZO compressor!");
		return 1;
	}
#endif

#ifdef HAVE_MINGW
	if(WSAStartup(MAKEWORD(2, 2), &wsa_state)) {
		logger(LOG_ERR, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError()));
		return 1;
	}

	if(!do_detach || !init_service())
		return main2(argc, argv);
	else
		return 1;
}
コード例 #5
0
ファイル: tincd.c プロジェクト: seehuhn/tinc
int main(int argc, char **argv) {
	logmode_t logmode;

	program_name = argv[0];

	if(!parse_options(argc, argv)) {
		return 1;
	}

	if(show_version) {
		printf("%s version %s\n", PACKAGE, VERSION);
		printf("Copyright (C) 1998-2018 Ivo Timmermans, Guus Sliepen and others.\n"
			   "See the AUTHORS file for a complete list.\n\n"
			   "tinc comes with ABSOLUTELY NO WARRANTY.  This is free software,\n"
			   "and you are welcome to redistribute it under certain conditions;\n"
			   "see the file COPYING for details.\n");

		return 0;
	}

	if(show_help) {
		usage(false);
		return 0;
	}

	make_names();

	if(kill_tincd) {
		return !kill_other(kill_tincd);
	}

	if(use_logfile) {
		logmode = LOGMODE_FILE;
	} else if(use_syslog) {
		logmode = LOGMODE_SYSLOG;
	} else {
		logmode = LOGMODE_STDERR;
	}
	openlogger("tinc", logmode);

	g_argv = argv;

	if(getenv("LISTEN_PID") && atoi(getenv("LISTEN_PID")) == getpid()) {
		do_detach = false;
	}

#ifdef HAVE_UNSETENV
	unsetenv("LISTEN_PID");
#endif

	init_configuration(&config_tree);

#ifndef OPENSSL_NO_ENGINE
	ENGINE_load_builtin_engines();
	ENGINE_register_all_complete();
#endif

#if OPENSSL_VERSION_NUMBER < 0x10100000L
	OpenSSL_add_all_algorithms();
#endif

	if(generate_keys) {
		read_server_config();
		return !keygen(generate_keys);
	}

	if(!read_server_config()) {
		return 1;
	}

#ifdef HAVE_LZO

	if(lzo_init() != LZO_E_OK) {
		logger(LOG_ERR, "Error initializing LZO compressor!");
		return 1;
	}

#endif

#ifdef HAVE_MINGW

	if(WSAStartup(MAKEWORD(2, 2), &wsa_state)) {
		logger(LOG_ERR, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError()));
		return 1;
	}

	if(!do_detach || !init_service()) {
		return main2(argc, argv);
	} else {
		return 1;
	}
}
コード例 #6
0
ファイル: bon_file.cpp プロジェクト: azat-archive/bonnie
int COpenTest::create(CPCCHAR dirname, BonTimer &timer, int num, int max_size
                    , int min_size, int num_directories, bool do_random)
{
  if(num_directories >= 100000)
  {
    fprintf(stderr, "Can't have more than 99,999 directories.\n");
    return -1;
  }

  m_number = num * DirectoryUnit;
  m_number_directories = num_directories;
  make_names(timer.random_source, do_random);
  m_max = max_size;
  m_min = min_size;
  m_size_range = m_max - m_min;
  m_dirname = new char[strlen(dirname) + 1];
  strcpy(m_dirname, dirname);

  if(num_directories >= 100000)
  {
    fprintf(stderr, "Can't have more than 99,999 directories.\n");
    return -1;
  }
  if(mkdir(dirname, S_IRWXU))
  {
    fprintf(stderr, "Can't make directory %s\n", dirname);
    return -1;
  }
  if(chdir(dirname))
  {
    fprintf(stderr, "Can't change to directory %s\n", dirname);
    return -1;
  }
  int i;
  if(m_sync)
    m_directoryHandles = new FILE_TYPE[num_directories];
  if(num_directories > 1)
  {
    for(i = 0; i < num_directories; i++)
    {
      sprintf(m_buf, "%05d", i);
      if(mkdir(m_buf, S_IRWXU))
      {
        fprintf(stderr, "Can't make directory %s\n", m_buf);
        return -1;
      }
      if(m_sync)
      {
        m_directoryHandles[i] = open(m_buf, O_RDONLY);
        if(m_directoryHandles[i] == -1)
        {
          fprintf(stderr, "Can't get directory handle.\n");
          return -1;
        }
      }
    }
  }
  else if(m_sync)
  {
    m_directoryHandles[0] = open(".", O_RDONLY);
    if(m_directoryHandles[0] == -1)
    {
      fprintf(stderr, "Can't get directory handle.\n");
      return -1;
    }
  }

  Duration dur;
  timer.start();
  for(i = 0; i < m_number; i++)
  {
    if(*m_exit)
    {
      if(m_number_directories != 1 && chdir(".."))
      {
        fprintf(stderr, "Can't change to directory ..\n");
        return -1;
      }
      return eCtrl_C;
    }
    dur.start();
    // m_max < 0 means link or sym-link
    if(m_max < 0)
    {
      if(i == 0)
      {
        if(create_a_file(m_file_names[0], m_buf, 0, m_dirIndex ? m_dirIndex[0] : 0))
          return -1;
      }
      else
      {
        // create_a_link() looks at m_max to see what to do
        if(create_a_link(m_file_names[0], m_file_names[i], m_dirIndex ? m_dirIndex[i] : 0))
          return -1;
      }
    }
    else
    {
      int size;
      if(m_size_range)
        size = m_min + (timer.random_source.getNum() % (m_size_range + 1));
      else
        size = m_max;
      if(create_a_file(m_file_names[i], m_buf, size, m_dirIndex ? m_dirIndex[i] : 0))
        return -1;
    }
    dur.stop();
  }
  sync();
  timer.stop_and_record(do_random ? CreateRand : CreateSeq);
  timer.add_latency(do_random ? CreateRand : CreateSeq, dur.getMax());
  return 0;
}
コード例 #7
0
ファイル: tincd.c プロジェクト: xentec/tinc
int main(int argc, char **argv) {
    program_name = argv[0];

    if(!parse_options(argc, argv))
        return 1;

    make_names(true);

    if(show_version) {
        printf("%s version %s (built %s %s, protocol %d.%d)\n", PACKAGE,
               BUILD_VERSION, BUILD_DATE, BUILD_TIME, PROT_MAJOR, PROT_MINOR);
        printf("Copyright (C) 1998-2015 Ivo Timmermans, Guus Sliepen and others.\n"
               "See the AUTHORS file for a complete list.\n\n"
               "tinc comes with ABSOLUTELY NO WARRANTY.  This is free software,\n"
               "and you are welcome to redistribute it under certain conditions;\n"
               "see the file COPYING for details.\n");

        return 0;
    }

    if(show_help) {
        usage(false);
        return 0;
    }

#ifdef HAVE_MINGW
    if(WSAStartup(MAKEWORD(2, 2), &wsa_state)) {
        logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "WSAStartup", winerror(GetLastError()));
        return 1;
    }
#else
    // Check if we got an umbilical fd from the process that started us
    char *umbstr = getenv("TINC_UMBILICAL");
    if(umbstr) {
        umbilical = atoi(umbstr);
        if(fcntl(umbilical, F_GETFL) < 0)
            umbilical = 0;
#ifdef FD_CLOEXEC
        if(umbilical)
            fcntl(umbilical, F_SETFD, FD_CLOEXEC);
#endif
    }
#endif

    openlogger("tinc", use_logfile?LOGMODE_FILE:LOGMODE_STDERR);

    g_argv = argv;

    if(getenv("LISTEN_PID") && atoi(getenv("LISTEN_PID")) == getpid())
        do_detach = false;
#ifdef HAVE_UNSETENV
    unsetenv("LISTEN_PID");
#endif

    init_configuration(&config_tree);

    /* Slllluuuuuuurrrrp! */

    gettimeofday(&now, NULL);
    srand(now.tv_sec + now.tv_usec);
    crypto_init();

    if(!read_server_config())
        return 1;

#ifdef HAVE_MINGW
    io_add_event(&stop_io, stop_handler, NULL, WSACreateEvent());
    if (stop_io.event == FALSE)
        abort();

    int result;
    if(!do_detach || !init_service()) {
        SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
        result = main2(argc, argv);
    } else
        result = 1;

    if (WSACloseEvent(stop_io.event) == FALSE)
        abort();
    io_del(&stop_io);
    return result;
}
コード例 #8
0
ファイル: names.c プロジェクト: Xolgrim/server
static const char *ghoul_name(const unit * u)
{
    static int num_postfix, num_name, num_prefix;
    return make_names("ghoul", &num_postfix, 5, &num_name, &num_prefix, 4);
}
コード例 #9
0
ファイル: names.c プロジェクト: Xolgrim/server
static const char *zombie_name(const unit * u)
{
    static int num_postfix, num_name, num_prefix;
    return make_names("zombie", &num_postfix, 5, &num_name, &num_prefix, 2);
}
コード例 #10
0
ファイル: names.c プロジェクト: Xolgrim/server
static const char *skeleton_name(const unit * u)
{
    static int num_postfix, num_name, num_prefix;
    return make_names("skeleton", &num_postfix, 5, &num_name, &num_prefix, 2);
}
コード例 #11
0
ファイル: names.c プロジェクト: Xolgrim/server
static const char *undead_name(const unit * u)
{
    static int num_postfix, num_name, num_prefix;
    return make_names("undead", &num_postfix, 2, &num_name, &num_prefix, 2);
}
コード例 #12
0
ファイル: invitation.c プロジェクト: xentec/tinc
static bool finalize_join(void) {
	char *name = xstrdup(get_value(data, "Name"));
	if(!name) {
		fprintf(stderr, "No Name found in invitation!\n");
		return false;
	}

	if(!check_id(name)) {
		fprintf(stderr, "Invalid Name found in invitation: %s!\n", name);
		return false;
	}

	if(!netname)
		netname = grep(data, "NetName");

	bool ask_netname = false;
	char temp_netname[32];

make_names:
	if(!confbasegiven) {
		free(confbase);
		confbase = NULL;
	}

	make_names(false);

	free(tinc_conf);
	free(hosts_dir);

	xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase);
	xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase);

	if(!access(tinc_conf, F_OK)) {
		fprintf(stderr, "Configuration file %s already exists!\n", tinc_conf);
		if(confbasegiven)
			return false;

		// Generate a random netname, ask for a better one later.
		ask_netname = true;
		snprintf(temp_netname, sizeof temp_netname, "join_%x", rand());
		netname = temp_netname;
		goto make_names;
	}	

	if(mkdir(confbase, 0777) && errno != EEXIST) {
		fprintf(stderr, "Could not create directory %s: %s\n", confbase, strerror(errno));
		return false;
	}

	if(mkdir(hosts_dir, 0777) && errno != EEXIST) {
		fprintf(stderr, "Could not create directory %s: %s\n", hosts_dir, strerror(errno));
		return false;
	}

	FILE *f = fopen(tinc_conf, "w");
	if(!f) {
		fprintf(stderr, "Could not create file %s: %s\n", tinc_conf, strerror(errno));
		return false;
	}

	fprintf(f, "Name = %s\n", name);

	char filename[PATH_MAX];
	snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, name);
	FILE *fh = fopen(filename, "w");
	if(!fh) {
		fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
		fclose(f);
		return false;
	}

	// Filter first chunk on approved keywords, split between tinc.conf and hosts/Name
	// Other chunks go unfiltered to their respective host config files
	const char *p = data;
	char *l, *value;

	while((l = get_line(&p))) {
		// Ignore comments
		if(*l == '#')
			continue;

		// Split line into variable and value
		int len = strcspn(l, "\t =");
		value = l + len;
		value += strspn(value, "\t ");
		if(*value == '=') {
			value++;
			value += strspn(value, "\t ");
		}
		l[len] = 0;

		// Is it a Name?
		if(!strcasecmp(l, "Name"))
			if(strcmp(value, name))
				break;
			else
				continue;
		else if(!strcasecmp(l, "NetName"))
			continue;

		// Check the list of known variables
		bool found = false;
		int i;
		for(i = 0; variables[i].name; i++) {
			if(strcasecmp(l, variables[i].name))
				continue;
			found = true;
			break;
		}

		// Ignore unknown and unsafe variables
		if(!found) {
			fprintf(stderr, "Ignoring unknown variable '%s' in invitation.\n", l);
			continue;
		} else if(!(variables[i].type & VAR_SAFE)) {
			fprintf(stderr, "Ignoring unsafe variable '%s' in invitation.\n", l);
			continue;
		}

		// Copy the safe variable to the right config file
		fprintf(variables[i].type & VAR_HOST ? fh : f, "%s = %s\n", l, value);
	}

	fclose(f);

	while(l && !strcasecmp(l, "Name")) {
		if(!check_id(value)) {
			fprintf(stderr, "Invalid Name found in invitation.\n");
			return false;
		}

		if(!strcmp(value, name)) {
			fprintf(stderr, "Secondary chunk would overwrite our own host config file.\n");
			return false;
		}

		snprintf(filename, sizeof filename, "%s" SLASH "%s", hosts_dir, value);
		f = fopen(filename, "w");

		if(!f) {
			fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
			return false;
		}

		while((l = get_line(&p))) {
			if(!strcmp(l, "#---------------------------------------------------------------#"))
				continue;
			int len = strcspn(l, "\t =");
			if(len == 4 && !strncasecmp(l, "Name", 4)) {
				value = l + len;
				value += strspn(value, "\t ");
				if(*value == '=') {
					value++;
					value += strspn(value, "\t ");
				}
				l[len] = 0;
				break;
			}

			fputs(l, f);
			fputc('\n', f);
		}

		fclose(f);
	}

	// Generate our key and send a copy to the server
	ecdsa_t *key = ecdsa_generate();
	if(!key)
		return false;

	char *b64key = ecdsa_get_base64_public_key(key);
	if(!b64key)
		return false;

	snprintf(filename, sizeof filename, "%s" SLASH "ed25519_key.priv", confbase);
	f = fopenmask(filename, "w", 0600);
	if(!f)
		return false;

	if(!ecdsa_write_pem_private_key(key, f)) {
		fprintf(stderr, "Error writing private key!\n");
		ecdsa_free(key);
		fclose(f);
		return false;
	}

	fclose(f);

	fprintf(fh, "Ed25519PublicKey = %s\n", b64key);

	sptps_send_record(&sptps, 1, b64key, strlen(b64key));
	free(b64key);
	ecdsa_free(key);

	check_port(name);

ask_netname:
	if(ask_netname && tty) {
		fprintf(stderr, "Enter a new netname: ");
		if(!fgets(line, sizeof line, stdin)) {
			fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
			return false;
		}
		if(!*line || *line == '\n')
			goto ask_netname;

		line[strlen(line) - 1] = 0;

		char newbase[PATH_MAX];
		snprintf(newbase, sizeof newbase, CONFDIR SLASH "tinc" SLASH "%s", line);
		if(rename(confbase, newbase)) {
			fprintf(stderr, "Error trying to rename %s to %s: %s\n", confbase, newbase, strerror(errno));
			goto ask_netname;
		}

		netname = line;
		make_names(false);
	}

	fprintf(stderr, "Configuration stored in: %s\n", confbase);

	return true;
}