/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/password-request.c

  • Committer: Teddy Hogeborn
  • Date: 2008-09-04 14:04:09 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080904140409-anr3hckg8ew7q60e
* plugin-runner.xml (BUGS): Document the non-recursiveness of the
                            "--config-file" option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
107
107
 
108
108
#define PATHDIR "/conf/conf.d/mandos"
109
109
#define SECKEY "seckey.txt"
110
 
#define PUBKEY "pubkey.txt"
 
110
#define PUBKEY "pupkey.txt"
111
111
 
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>";
116
116
 
117
117
/* Used for passing in values through the Avahi callback functions */
150
150
  int ret;
151
151
  gpgme_error_t rc;
152
152
  gpgme_engine_info_t engine_info;
153
 
  
 
153
 
154
154
  
155
155
  /*
156
156
   * Helper function to insert pub and seckey to the enigne keyring.
171
171
              gpgme_strsource(rc), gpgme_strerror(rc));
172
172
      return false;
173
173
    }
174
 
    
 
174
 
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));
179
179
      return false;
180
180
    }
181
 
    
 
181
 
182
182
    ret = TEMP_FAILURE_RETRY(close(fd));
183
183
    if(ret == -1){
184
184
      perror("close");
190
190
  if (debug){
191
191
    fprintf(stderr, "Initialize gpgme\n");
192
192
  }
193
 
  
 
193
 
194
194
  /* Init GPGME */
195
195
  gpgme_check_version(NULL);
196
196
  rc = gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP);
199
199
            gpgme_strsource(rc), gpgme_strerror(rc));
200
200
    return false;
201
201
  }
202
 
  
 
202
 
203
203
    /* Set GPGME home directory for the OpenPGP engine only */
204
204
  rc = gpgme_get_engine_info (&engine_info);
205
205
  if (rc != GPG_ERR_NO_ERROR){
219
219
    fprintf(stderr, "Could not set GPGME home dir to %s\n", tempdir);
220
220
    return false;
221
221
  }
222
 
  
 
222
 
223
223
  /* Create new GPGME "context" */
224
224
  rc = gpgme_new(&(mc->ctx));
225
225
  if (rc != GPG_ERR_NO_ERROR){
918
918
      }
919
919
    }
920
920
    
 
921
    ret = init_gnutls_global(&mc, pubkey, seckey);
 
922
    if (ret == -1){
 
923
      fprintf(stderr, "init_gnutls_global failed\n");
 
924
      exitcode = EXIT_FAILURE;
 
925
      goto end;
 
926
    } else {
 
927
      gnutls_initalized = true;
 
928
    }
 
929
 
 
930
    if(mkdtemp(tempdir) == NULL){
 
931
      perror("mkdtemp");
 
932
      tempdir[0] = '\0';
 
933
      goto end;
 
934
    }
 
935
    
 
936
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
 
937
      fprintf(stderr, "pgpme_initalized failed\n");
 
938
      exitcode = EXIT_FAILURE;
 
939
      goto end;
 
940
    } else {
 
941
      pgpme_initalized = true;
 
942
    }
 
943
    
921
944
    /* If the interface is down, bring it up */
922
945
    {
923
946
      sd = socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP);
961
984
      perror("setgid");
962
985
    }
963
986
    
964
 
    ret = init_gnutls_global(&mc, pubkey, seckey);
965
 
    if (ret == -1){
966
 
      fprintf(stderr, "init_gnutls_global failed\n");
967
 
      exitcode = EXIT_FAILURE;
968
 
      goto end;
969
 
    } else {
970
 
      gnutls_initalized = true;
971
 
    }
972
 
    
973
 
    if(mkdtemp(tempdir) == NULL){
974
 
      perror("mkdtemp");
975
 
      tempdir[0] = '\0';
976
 
      goto end;
977
 
    }
978
 
    
979
 
    if(not init_gpgme(&mc, pubkey, seckey, tempdir)){
980
 
      fprintf(stderr, "pgpme_initalized failed\n");
981
 
      exitcode = EXIT_FAILURE;
982
 
      goto end;
983
 
    } else {
984
 
      pgpme_initalized = true;
985
 
    }
986
 
    
987
987
    if_index = (AvahiIfIndex) if_nametoindex(interface);
988
988
    if(if_index == 0){
989
989
      fprintf(stderr, "No such interface: \"%s\"\n", interface);
1099
1099
      gnutls_certificate_free_credentials(mc.cred);
1100
1100
      gnutls_global_deinit ();
1101
1101
    }
1102
 
    
 
1102
 
1103
1103
    if(pgpme_initalized){
1104
1104
      gpgme_release(mc.ctx);
1105
1105
    }
1106
 
    
 
1106
 
1107
1107
    /* Removes the temp directory used by GPGME */
1108
1108
    if(tempdir[0] != '\0'){
1109
1109
      DIR *d;