108
108
#define PATHDIR "/conf/conf.d/mandos"
109
109
#define SECKEY "seckey.txt"
110
#define PUBKEY "pubkey.txt"
110
#define PUBKEY "pupkey.txt"
112
112
bool debug = false;
113
113
static const char mandos_protocol_version[] = "1";
114
const char *argp_program_version = "mandos-client 1.0";
114
const char *argp_program_version = "password-request 1.0";
115
115
const char *argp_program_bug_address = "<mandos@fukt.bsnet.se>";
117
117
/* Used for passing in values through the Avahi callback functions */
171
171
gpgme_strsource(rc), gpgme_strerror(rc));
175
175
rc = gpgme_op_import(mc->ctx, pgp_data);
176
176
if (rc != GPG_ERR_NO_ERROR){
177
177
fprintf(stderr, "bad gpgme_op_import: %s: %s\n",
178
178
gpgme_strsource(rc), gpgme_strerror(rc));
182
182
ret = TEMP_FAILURE_RETRY(close(fd));
828
828
const char *pubkey = PATHDIR "/" PUBKEY;
830
830
mandos_context mc = { .simple_poll = NULL, .server = NULL,
831
.dh_bits = 1024, .priority = "SECURE256"
832
":!CTYPE-X.509:+CTYPE-OPENPGP" };
831
.dh_bits = 1024, .priority = "SECURE256"};
833
832
bool gnutls_initalized = false;
834
bool gpgme_initalized = false;
833
bool pgpme_initalized = false;
837
836
struct argp_option options[] = {
838
837
{ .name = "debug", .key = 128,
839
838
.doc = "Debug mode", .group = 3 },
840
839
{ .name = "connect", .key = 'c',
841
.arg = "ADDRESS:PORT",
842
.doc = "Connect directly to a specific Mandos server",
841
.doc = "Connect directly to a sepcified mandos server",
844
843
{ .name = "interface", .key = 'i',
846
.doc = "Interface that will be used to search for Mandos"
845
.doc = "Interface that Avahi will conntect through",
849
847
{ .name = "seckey", .key = 's',
851
.doc = "OpenPGP secret key file base name",
849
.doc = "Secret openpgp key for gnutls authentication",
853
851
{ .name = "pubkey", .key = 'p',
855
.doc = "OpenPGP public key file base name",
853
.doc = "Public openpgp key for gnutls authentication",
857
855
{ .name = "dh-bits", .key = 129,
859
.doc = "Bit length of the prime number used in the"
860
" Diffie-Hellman key exchange",
857
.doc = "dh-bits to use in gnutls communication",
862
859
{ .name = "priority", .key = 130,
864
.doc = "GnuTLS priority string for the TLS handshake",
861
.doc = "GNUTLS priority", .group = 1 },
869
866
error_t parse_opt (int key, char *arg,
870
867
struct argp_state *state) {
871
868
/* Get the INPUT argument from `argp_parse', which we know is
872
869
a pointer to our plugin list pointer. */
874
case 128: /* --debug */
877
case 'c': /* --connect */
878
875
connect_to = arg;
880
case 'i': /* --interface */
883
case 's': /* --seckey */
886
case 'p': /* --pubkey */
889
case 129: /* --dh-bits */
891
888
mc.dh_bits = (unsigned int) strtol(arg, NULL, 10);
910
907
struct argp argp = { .options = options, .parser = parse_opt,
912
909
.doc = "Mandos client -- Get and decrypt"
913
" passwords from a Mandos server" };
910
" passwords from mandos server" };
914
911
ret = argp_parse (&argp, argc, argv, 0, 0, NULL);
915
912
if (ret == ARGP_ERR_UNKNOWN){
916
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;
922
942
/* If the interface is down, bring it up */
962
982
perror("setgid");
965
ret = init_gnutls_global(&mc, pubkey, seckey);
967
fprintf(stderr, "init_gnutls_global failed\n");
968
exitcode = EXIT_FAILURE;
971
gnutls_initalized = true;
974
if(mkdtemp(tempdir) == NULL){
980
if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
981
fprintf(stderr, "gpgme_initalized failed\n");
982
exitcode = EXIT_FAILURE;
985
gpgme_initalized = true;
988
985
if_index = (AvahiIfIndex) if_nametoindex(interface);
989
986
if(if_index == 0){
990
987
fprintf(stderr, "No such interface: \"%s\"\n", interface);
1042
1039
config.publish_addresses = 0;
1043
1040
config.publish_workstation = 0;
1044
1041
config.publish_domain = 0;
1046
1043
/* Allocate a new server */
1047
1044
mc.server = avahi_server_new(avahi_simple_poll_get
1048
1045
(mc.simple_poll), &config, NULL,
1051
1048
/* Free the Avahi configuration data */
1052
1049
avahi_server_config_free(&config);