From: Saverio Proto Date: Wed, 2 Apr 2014 12:10:10 +0000 (+0200) Subject: First draft of tinc setup function X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=4d1de7e2f6e014675fd3404686b524a3afa3cee8;p=meshlink First draft of tinc setup function --- diff --git a/src/libmeshlink.c b/src/libmeshlink.c index 1631fb1a..04e31415 100644 --- a/src/libmeshlink.c +++ b/src/libmeshlink.c @@ -20,12 +20,50 @@ #include "libmeshlink.h" //tinc_setup() should basically do what cmd_init() from src/tincctl.c does, except it doesn't have to generate a tinc-up script. -bool tinc_setup(const char* path) { +bool tinc_setup(const char* tinc_conf, const char* name) { + if(!access(tinc_conf, F_OK)) { + fprintf(stderr, "Configuration file %s already exists!\n", tinc_conf); + return false; + } -init_configuration(&config_tree); + if(!check_id(name)) { + fprintf(stderr, "Invalid Name! Only a-z, A-Z, 0-9 and _ are allowed characters.\n"); + return false; + } + + if(!confbase_given && mkdir(confdir, 0755) && errno != EEXIST) { + fprintf(stderr, "Could not create directory %s: %s\n", confdir, strerror(errno)); + return false; + } + + 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 1; + } + + fprintf(f, "Name = %s\n", name); + fclose(f); + + if(!rsa_keygen(2048, false) || !ecdsa_keygen(false)) + return false; + + check_port(name); + + return true; + +} -return true; -}; bool tinc_start(const char* path); diff --git a/src/libmeshlink.h b/src/libmeshlink.h index d5263c9c..f97050b5 100644 --- a/src/libmeshlink.h +++ b/src/libmeshlink.h @@ -19,11 +19,13 @@ #include "system.h" #include "node.h" +#include "names.h" +#include "tincctl.h" /* OLD: tinc_configuration_t provides all information required to setup "/etc/tinc" I think tinc_setup() should basically do what cmd_init() from src/tincctl.c does, except it doesn't have to generate a tinc-up script. */ -bool tinc_setup(const char* path); +bool tinc_setup(const char* tinc_conf, const char* name); bool tinc_start(const char* path);