.It Va Name Li = Ar name Bq required
This is the name which identifies this tinc daemon.
It must be unique for the virtual private network this daemon will connect to.
+The Name may only consist of alphanumeric and underscore characters.
+
+If
+.Va Name
+starts with a
+.Li $ ,
+then the contents of the environment variable that follows will be used.
+In that case, invalid characters will be converted to underscores.
+If
+.Va Name
+is
+.Li $HOST ,
+but no such environment variable exist, the hostname will be read using the gethostnname() system call.
.It Va PingInterval Li = Ar seconds Pq 60
The number of seconds of inactivity that
This is a symbolic name for this connection.
The name should consist only of alfanumeric and underscore characters (a-z, A-Z, 0-9 and _).
+If Name starts with a $, then the contents of the environment variable that follows will be used.
+In that case, invalid characters will be converted to underscores.
+If Name is $HOST, but no such environment variable exist,
+the hostname will be read using the gethostnname() system call.
+
@cindex PingInterval
@item PingInterval = <@var{seconds}> (60)
The number of seconds of inactivity that tinc will wait before sending a
extern void send_packet(const struct node_t *, vpn_packet_t *);
extern void receive_tcppacket(struct connection_t *, const char *, int);
extern void broadcast_packet(const struct node_t *, vpn_packet_t *);
+extern char *get_name(void);
extern bool setup_network(void);
extern void setup_outgoing_connection(struct outgoing_t *);
extern void try_outgoing_connections(void);
closedir(dir);
}
+char *get_name(void) {
+ char *name = NULL;
+
+ get_config_string(lookup_config(config_tree, "Name"), &name);
+
+ if(!name)
+ return NULL;
+
+ if(*name == '$') {
+ char *envname = getenv(name + 1);
+ if(!envname) {
+ if(strcmp(name + 1, "HOST")) {
+ fprintf(stderr, "Invalid Name: environment variable %s does not exist\n", name + 1);
+ return false;
+ }
+ envname = alloca(32);
+ if(gethostname(envname, 32)) {
+ fprintf(stderr, "Could not get hostname: %s\n", strerror(errno));
+ return false;
+ }
+ envname[31] = 0;
+ }
+ free(name);
+ name = xstrdup(envname);
+ for(char *c = name; *c; c++)
+ if(!isalnum(*c))
+ *c = '_';
+ }
+
+ if(!check_id(name)) {
+ logger(LOG_ERR, "Invalid name for myself!");
+ free(name);
+ return false;
+ }
+
+ return name;
+}
+
/*
Configure node_t myself and set up the local sockets (listen only)
*/
myself->connection->options = 0;
myself->connection->protocol_version = PROT_CURRENT;
- if(!get_config_string(lookup_config(config_tree, "Name"), &name)) { /* Not acceptable */
+ if(!(name = get_name())) {
logger(LOG_ERR, "Name for tinc daemon required!");
return false;
}
- if(!check_id(name)) {
- logger(LOG_ERR, "Invalid name for myself!");
- free(name);
- return false;
- }
-
myself->name = name;
myself->connection->name = xstrdup(name);
xasprintf(&fname, "%s/hosts/%s", confbase, name);
static bool keygen(int bits) {
RSA *rsa_key;
FILE *f;
- char *name = NULL;
+ char *name = get_name();
char *filename;
- get_config_string(lookup_config(config_tree, "Name"), &name);
-
- if(name && !check_id(name)) {
- fprintf(stderr, "Invalid name for myself!\n");
- return false;
- }
-
fprintf(stderr, "Generating %d bits keys:\n", bits);
rsa_key = RSA_generate_key(bits, 0x10001, indicator, NULL);
PEM_write_RSAPublicKey(f, rsa_key);
fclose(f);
free(filename);
- if(name)
- free(name);
+ free(name);
return true;
}