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