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