9
9
* "browse_callback", and parts of "main".
11
11
* Everything else is
12
* Copyright © 2007-2008 Teddy Hogeborn & Björn Påhlsson
12
* Copyright © 2008,2009 Teddy Hogeborn
13
* Copyright © 2008,2009 Björn Påhlsson
14
15
* This program is free software: you can redistribute it and/or
15
16
* modify it under the terms of the GNU General Public License as
102
103
#define BUFFER_SIZE 256
105
#define PATHDIR "/conf/conf.d/mandos"
108
105
#define PATHDIR "/conf/conf.d/mandos"
109
106
#define SECKEY "seckey.txt"
110
#define PUBKEY "pupkey.txt"
107
#define PUBKEY "pubkey.txt"
112
109
bool debug = false;
113
110
static const char mandos_protocol_version[] = "1";
114
const char *argp_program_version = "password-request 1.0";
111
const char *argp_program_version = "mandos-client " VERSION;
115
112
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
117
114
/* Used for passing in values through the Avahi callback functions */
171
168
gpgme_strsource(rc), gpgme_strerror(rc));
175
172
rc = gpgme_op_import(mc->ctx, pgp_data);
176
173
if (rc != GPG_ERR_NO_ERROR){
177
174
fprintf(stderr, "bad gpgme_op_import: %s: %s\n",
178
175
gpgme_strsource(rc), gpgme_strerror(rc));
182
179
ret = TEMP_FAILURE_RETRY(close(fd));
828
825
const char *pubkey = PATHDIR "/" PUBKEY;
830
827
mandos_context mc = { .simple_poll = NULL, .server = NULL,
831
.dh_bits = 1024, .priority = "SECURE256"};
828
.dh_bits = 1024, .priority = "SECURE256"
829
":!CTYPE-X.509:+CTYPE-OPENPGP" };
832
830
bool gnutls_initalized = false;
833
bool pgpme_initalized = false;
831
bool gpgme_initalized = false;
836
834
struct argp_option options[] = {
837
835
{ .name = "debug", .key = 128,
838
836
.doc = "Debug mode", .group = 3 },
839
837
{ .name = "connect", .key = 'c',
841
.doc = "Connect directly to a sepcified mandos server",
838
.arg = "ADDRESS:PORT",
839
.doc = "Connect directly to a specific Mandos server",
843
841
{ .name = "interface", .key = 'i',
845
.doc = "Interface that Avahi will conntect through",
843
.doc = "Interface that will be used to search for Mandos"
847
846
{ .name = "seckey", .key = 's',
849
.doc = "Secret openpgp key for gnutls authentication",
848
.doc = "OpenPGP secret key file base name",
851
850
{ .name = "pubkey", .key = 'p',
853
.doc = "Public openpgp key for gnutls authentication",
852
.doc = "OpenPGP public key file base name",
855
854
{ .name = "dh-bits", .key = 129,
857
.doc = "dh-bits to use in gnutls communication",
856
.doc = "Bit length of the prime number used in the"
857
" Diffie-Hellman key exchange",
859
859
{ .name = "priority", .key = 130,
861
.doc = "GNUTLS priority", .group = 1 },
861
.doc = "GnuTLS priority string for the TLS handshake",
866
866
error_t parse_opt (int key, char *arg,
867
867
struct argp_state *state) {
868
868
/* Get the INPUT argument from `argp_parse', which we know is
869
869
a pointer to our plugin list pointer. */
871
case 128: /* --debug */
874
case 'c': /* --connect */
875
875
connect_to = arg;
877
case 'i': /* --interface */
880
case 's': /* --seckey */
883
case 'p': /* --pubkey */
886
case 129: /* --dh-bits */
888
888
mc.dh_bits = (unsigned int) strtol(arg, NULL, 10);
907
907
struct argp argp = { .options = options, .parser = parse_opt,
909
909
.doc = "Mandos client -- Get and decrypt"
910
" passwords from mandos server" };
910
" passwords from a Mandos server" };
911
911
ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
912
912
if (ret == ARGP_ERR_UNKNOWN){
913
913
fprintf(stderr, "Unknown error while parsing arguments\n");
919
ret = init_gnutls_global(&mc, pubkey, seckey);
921
fprintf(stderr, "init_gnutls_global failed\n");
922
exitcode = EXIT_FAILURE;
925
gnutls_initalized = true;
928
if(mkdtemp(tempdir) == NULL){
934
if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
935
fprintf(stderr, "pgpme_initalized failed\n");
936
exitcode = EXIT_FAILURE;
939
pgpme_initalized = true;
942
919
/* If the interface is down, bring it up */
982
959
perror("setgid");
962
ret = init_gnutls_global(&mc, pubkey, seckey);
964
fprintf(stderr, "init_gnutls_global failed\n");
965
exitcode = EXIT_FAILURE;
968
gnutls_initalized = true;
971
if(mkdtemp(tempdir) == NULL){
977
if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
978
fprintf(stderr, "gpgme_initalized failed\n");
979
exitcode = EXIT_FAILURE;
982
gpgme_initalized = true;
985
985
if_index = (AvahiIfIndex) if_nametoindex(interface);
986
986
if(if_index == 0){
987
987
fprintf(stderr, "No such interface: \"%s\"\n", interface);
1039
1039
config.publish_addresses = 0;
1040
1040
config.publish_workstation = 0;
1041
1041
config.publish_domain = 0;
1043
1043
/* Allocate a new server */
1044
1044
mc.server = avahi_server_new(avahi_simple_poll_get
1045
1045
(mc.simple_poll), &config, NULL,
1048
1048
/* Free the Avahi configuration data */
1049
1049
avahi_server_config_free(&config);