/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/mandos-client.c

  • Committer: Teddy Hogeborn
  • Date: 2008-09-30 07:23:39 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080930072339-jn15gyrtfpdk2dhx
* .bzrignore: Added "man" directory (created by "make install-html").

* Makefile: Add "common.ent" dependency to all manual pages.
  (htmldir, version, SED): New variables.
  (CFLAGS): Add -D option to define VERSION to $(version).
  (MANPOST, HTMLPOST): Use $(SED).
  (PROGS): Use $(CPROGS)
  (CPROGS): New; C-only programs.
  (objects): Use $(CPROGS).
  (common.ent, mandos, mandos-keygen): New targets; update version
                                       number to $(version).
  (clean): Use $(CPROGS).
  (check): Depend on "all".
  (install-html): Install to $(htmldir).

* common.ent: New file with "version" entity.

* mandos-clients.conf.xml: Use "common.ent".
* mandos-keygen.xml: - '' -
* mandos.conf.xml: - '' -
* mandos.xml: - '' -
* plugin-runner.xml: - '' -
* plugins.d/mandos-client.xml: - '' -
* plugins.d/password-prompt.xml: - '' -

* plugin-runner.c (argp_program_version): Use VERSION.
* plugins.d/mandos-client.c (argp_program_version): - '' -
* plugins.d/password-prompt.c (argp_program_version): - '' -

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
 * "browse_callback", and parts of "main".
10
10
 * 
11
11
 * Everything else is
12
 
 * Copyright © 2007-2008 Teddy Hogeborn & Björn Påhlsson
 
12
 * Copyright © 2008 Teddy Hogeborn & Björn Påhlsson
13
13
 * 
14
14
 * This program is free software: you can redistribute it and/or
15
15
 * modify it under the terms of the GNU General Public License as
101
101
 
102
102
#define BUFFER_SIZE 256
103
103
 
104
 
/*
105
 
  #define PATHDIR "/conf/conf.d/mandos"
106
 
*/
107
 
 
108
104
#define PATHDIR "/conf/conf.d/mandos"
109
105
#define SECKEY "seckey.txt"
110
 
#define PUBKEY "pupkey.txt"
 
106
#define PUBKEY "pubkey.txt"
111
107
 
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>";
116
112
 
117
113
/* Used for passing in values through the Avahi callback functions */
150
146
  int ret;
151
147
  gpgme_error_t rc;
152
148
  gpgme_engine_info_t engine_info;
153
 
 
 
149
  
154
150
  
155
151
  /*
156
152
   * Helper function to insert pub and seckey to the enigne keyring.
171
167
              gpgme_strsource(rc), gpgme_strerror(rc));
172
168
      return false;
173
169
    }
174
 
 
 
170
    
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));
179
175
      return false;
180
176
    }
181
 
 
 
177
    
182
178
    ret = TEMP_FAILURE_RETRY(close(fd));
183
179
    if(ret == -1){
184
180
      perror("close");
190
186
  if (debug){
191
187
    fprintf(stderr, "Initialize gpgme\n");
192
188
  }
193
 
 
 
189
  
194
190
  /* Init GPGME */
195
191
  gpgme_check_version(NULL);
196
192
  rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
199
195
            gpgme_strsource(rc), gpgme_strerror(rc));
200
196
    return false;
201
197
  }
202
 
 
 
198
  
203
199
    /* Set GPGME home directory for the OpenPGP engine only */
204
200
  rc = gpgme_get_engine_info (&engine_info);
205
201
  if (rc != GPG_ERR_NO_ERROR){
219
215
    fprintf(stderr, "Could not set GPGME home dir to %s\n", tempdir);
220
216
    return false;
221
217
  }
222
 
 
 
218
  
223
219
  /* Create new GPGME "context" */
224
220
  rc = gpgme_new(&(mc->ctx));
225
221
  if (rc != GPG_ERR_NO_ERROR){
919
915
      }
920
916
    }
921
917
    
922
 
    ret = init_gnutls_global(&mc, pubkey, seckey);
923
 
    if (ret == -1){
924
 
      fprintf(stderr, "init_gnutls_global failed\n");
925
 
      exitcode = EXIT_FAILURE;
926
 
      goto end;
927
 
    } else {
928
 
      gnutls_initalized = true;
929
 
    }
930
 
 
931
 
    if(mkdtemp(tempdir) == NULL){
932
 
      perror("mkdtemp");
933
 
      tempdir[0] = '\0';
934
 
      goto end;
935
 
    }
936
 
    
937
 
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
938
 
      fprintf(stderr, "gpgme_initalized failed\n");
939
 
      exitcode = EXIT_FAILURE;
940
 
      goto end;
941
 
    } else {
942
 
      gpgme_initalized = true;
943
 
    }
944
 
    
945
918
    /* If the interface is down, bring it up */
946
919
    {
947
920
      sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
985
958
      perror("setgid");
986
959
    }
987
960
    
 
961
    ret = init_gnutls_global(&mc, pubkey, seckey);
 
962
    if (ret == -1){
 
963
      fprintf(stderr, "init_gnutls_global failed\n");
 
964
      exitcode = EXIT_FAILURE;
 
965
      goto end;
 
966
    } else {
 
967
      gnutls_initalized = true;
 
968
    }
 
969
    
 
970
    if(mkdtemp(tempdir) == NULL){
 
971
      perror("mkdtemp");
 
972
      tempdir[0] = '\0';
 
973
      goto end;
 
974
    }
 
975
    
 
976
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
 
977
      fprintf(stderr, "gpgme_initalized failed\n");
 
978
      exitcode = EXIT_FAILURE;
 
979
      goto end;
 
980
    } else {
 
981
      gpgme_initalized = true;
 
982
    }
 
983
    
988
984
    if_index = (AvahiIfIndex) if_nametoindex(interface);
989
985
    if(if_index == 0){
990
986
      fprintf(stderr, "No such interface: \"%s\"\n", interface);
1101
1097
      gnutls_global_deinit ();
1102
1098
      gnutls_dh_params_deinit(mc.dh_params);
1103
1099
    }
1104
 
 
 
1100
    
1105
1101
    if(gpgme_initalized){
1106
1102
      gpgme_release(mc.ctx);
1107
1103
    }
1108
 
 
 
1104
    
1109
1105
    /* Removes the temp directory used by GPGME */
1110
1106
    if(tempdir[0] != '\0'){
1111
1107
      DIR *d;