diff options
Diffstat (limited to 'src/initconf.c')
| -rw-r--r-- | src/initconf.c | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/src/initconf.c b/src/initconf.c index 8944ab4..b900f7f 100644 --- a/src/initconf.c +++ b/src/initconf.c | |||
| @@ -25,38 +25,23 @@ | |||
| 25 | #include <gnutls/gnutls.h> | 25 | #include <gnutls/gnutls.h> |
| 26 | #include <gnutls/x509.h> | 26 | #include <gnutls/x509.h> |
| 27 | #include <glib.h> | 27 | #include <glib.h> |
| 28 | |||
| 28 | #include "userpref.h" | 29 | #include "userpref.h" |
| 30 | #include "lockdown.h" | ||
| 29 | 31 | ||
| 30 | int debug = 1; | 32 | int debug = 1; |
| 31 | 33 | ||
| 32 | int get_rand(int min, int max) { | 34 | /** Generates a 2048 byte key, split into a function so that it can be run in a |
| 33 | int retval = (rand() % (max - min)) + min; | 35 | * thread. |
| 34 | return retval; | 36 | * |
| 35 | } | 37 | * @param key The pointer to the desired location of the new key. |
| 36 | 38 | */ | |
| 37 | char *lockdownd_generate_hostid() { | ||
| 38 | char *hostid = (char*)malloc(sizeof(char) * 37); // HostID's are just UUID's, and UUID's are 36 characters long | ||
| 39 | const char *chars = "ABCDEF0123456789"; | ||
| 40 | srand(time(NULL)); | ||
| 41 | int i = 0; | ||
| 42 | |||
| 43 | for (i = 0; i < 36; i++) { | ||
| 44 | if (i == 8 || i == 13 || i == 18 || i == 23) { | ||
| 45 | hostid[i] = '-'; | ||
| 46 | continue; | ||
| 47 | } else { | ||
| 48 | hostid[i] = chars[get_rand(0,16)]; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | hostid[36] = '\0'; | ||
| 52 | return hostid; | ||
| 53 | } | ||
| 54 | |||
| 55 | void generate_key(gpointer key){ | 39 | void generate_key(gpointer key){ |
| 56 | gnutls_x509_privkey_generate(*((gnutls_x509_privkey_t*)key), GNUTLS_PK_RSA, 2048, 0); | 40 | gnutls_x509_privkey_generate(*((gnutls_x509_privkey_t*)key), GNUTLS_PK_RSA, 2048, 0); |
| 57 | g_thread_exit(0); | 41 | g_thread_exit(0); |
| 58 | } | 42 | } |
| 59 | 43 | /** Simple function that generates a spinner until the mutex is released. | |
| 44 | */ | ||
| 60 | void progress_bar(gpointer mutex){ | 45 | void progress_bar(gpointer mutex){ |
| 61 | const char *spinner = "|/-\\|/-\\"; | 46 | const char *spinner = "|/-\\|/-\\"; |
| 62 | int i = 0; | 47 | int i = 0; |
