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