/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: 2009-04-01 03:37:45 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090401033745-c89k6bij5opdm1rk
* mandos (ClientDBus.__del__): Bug fix: Correct mispasted code, and do
                               not try to call
                               dbus.service.Object.__del__() if it
                               does not exist.
  (ClientDBus.start_checker): Simplify logic.

Show diffs side-by-side

added added

removed removed

Lines of Context:
309
309
        }
310
310
        gpgme_recipient_t recipient;
311
311
        recipient = result->recipients;
312
 
        while(recipient != NULL){
313
 
          fprintf(stderr, "Public key algorithm: %s\n",
314
 
                  gpgme_pubkey_algo_name(recipient->pubkey_algo));
315
 
          fprintf(stderr, "Key ID: %s\n", recipient->keyid);
316
 
          fprintf(stderr, "Secret key available: %s\n",
317
 
                  recipient->status == GPG_ERR_NO_SECKEY
318
 
                  ? "No" : "Yes");
319
 
          recipient = recipient->next;
 
312
        if(recipient){
 
313
          while(recipient != NULL){
 
314
            fprintf(stderr, "Public key algorithm: %s\n",
 
315
                    gpgme_pubkey_algo_name(recipient->pubkey_algo));
 
316
            fprintf(stderr, "Key ID: %s\n", recipient->keyid);
 
317
            fprintf(stderr, "Secret key available: %s\n",
 
318
                    recipient->status == GPG_ERR_NO_SECKEY
 
319
                    ? "No" : "Yes");
 
320
            recipient = recipient->next;
 
321
          }
320
322
        }
321
323
      }
322
324
    }
780
782
  return retval;
781
783
}
782
784
 
783
 
sig_atomic_t quit_now = 0;
784
 
 
785
785
static void resolve_callback(AvahiSServiceResolver *r,
786
786
                             AvahiIfIndex interface,
787
787
                             AvahiProtocol proto,
801
801
  /* Called whenever a service has been resolved successfully or
802
802
     timed out */
803
803
  
804
 
  if(quit_now){
805
 
    return;
806
 
  }
807
 
  
808
804
  switch(event){
809
805
  default:
810
806
  case AVAHI_RESOLVER_FAILURE:
881
877
  }
882
878
}
883
879
 
 
880
sig_atomic_t quit_now = 0;
 
881
 
884
882
/* stop main loop after sigterm has been called */
885
883
static void handle_sigterm(__attribute__((unused)) int sig){
886
884
  if(quit_now){
903
901
  int exitcode = EXIT_SUCCESS;
904
902
  const char *interface = "eth0";
905
903
  struct ifreq network;
906
 
  int sd = -1;
907
 
  bool take_down_interface = false;
 
904
  int sd;
908
905
  uid_t uid;
909
906
  gid_t gid;
910
907
  char *connect_to = NULL;
1062
1059
  
1063
1060
  /* If the interface is down, bring it up */
1064
1061
  if(interface[0] != '\0'){
1065
 
    if_index = (AvahiIfIndex) if_nametoindex(interface);
1066
 
    if(if_index == 0){
1067
 
      fprintf(stderr, "No such interface: \"%s\"\n", interface);
1068
 
      exitcode = EXIT_FAILURE;
1069
 
      goto end;
1070
 
    }
1071
 
    
1072
 
    if(quit_now){
1073
 
      goto end;
1074
 
    }
1075
 
    
1076
1062
#ifdef __linux__
1077
1063
    /* Lower kernel loglevel to KERN_NOTICE to avoid KERN_INFO
1078
1064
       messages to mess up the prompt */
1115
1101
    }
1116
1102
    if((network.ifr_flags & IFF_UP) == 0){
1117
1103
      network.ifr_flags |= IFF_UP;
1118
 
      take_down_interface = true;
1119
1104
      ret = ioctl(sd, SIOCSIFFLAGS, &network);
1120
1105
      if(ret == -1){
1121
 
        take_down_interface = false;
1122
1106
        perror("ioctl SIOCSIFFLAGS");
1123
1107
        exitcode = EXIT_FAILURE;
1124
1108
#ifdef __linux__
1146
1130
        perror("nanosleep");
1147
1131
      }
1148
1132
    }
1149
 
    if(not take_down_interface){
1150
 
      /* We won't need the socket anymore */
1151
 
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
1152
 
      if(ret == -1){
1153
 
        perror("close");
1154
 
      }
 
1133
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
1134
    if(ret == -1){
 
1135
      perror("close");
1155
1136
    }
1156
1137
#ifdef __linux__
1157
1138
    if(restore_loglevel){
1164
1145
#endif  /* __linux__ */
1165
1146
  }
1166
1147
  
1167
 
  if(quit_now){
1168
 
    goto end;
1169
 
  }
1170
 
  
1171
1148
  uid = getuid();
1172
1149
  gid = getgid();
1173
1150
  
1182
1159
    perror("setuid");
1183
1160
  }
1184
1161
  
1185
 
  if(quit_now){
1186
 
    goto end;
1187
 
  }
1188
 
  
1189
1162
  ret = init_gnutls_global(pubkey, seckey);
1190
1163
  if(ret == -1){
1191
1164
    fprintf(stderr, "init_gnutls_global failed\n");
1195
1168
    gnutls_initialized = true;
1196
1169
  }
1197
1170
  
1198
 
  if(quit_now){
1199
 
    goto end;
1200
 
  }
1201
 
  
1202
 
  tempdir_created = true;
1203
1171
  if(mkdtemp(tempdir) == NULL){
1204
 
    tempdir_created = false;
1205
1172
    perror("mkdtemp");
1206
1173
    goto end;
1207
1174
  }
1208
 
  
1209
 
  if(quit_now){
1210
 
    goto end;
1211
 
  }
 
1175
  tempdir_created = true;
1212
1176
  
1213
1177
  if(not init_gpgme(pubkey, seckey, tempdir)){
1214
1178
    fprintf(stderr, "init_gpgme failed\n");
1218
1182
    gpgme_initialized = true;
1219
1183
  }
1220
1184
  
1221
 
  if(quit_now){
1222
 
    goto end;
 
1185
  if(interface[0] != '\0'){
 
1186
    if_index = (AvahiIfIndex) if_nametoindex(interface);
 
1187
    if(if_index == 0){
 
1188
      fprintf(stderr, "No such interface: \"%s\"\n", interface);
 
1189
      exitcode = EXIT_FAILURE;
 
1190
      goto end;
 
1191
    }
1223
1192
  }
1224
1193
  
1225
1194
  if(connect_to != NULL){
1231
1200
      exitcode = EXIT_FAILURE;
1232
1201
      goto end;
1233
1202
    }
1234
 
    
1235
 
    if(quit_now){
1236
 
      goto end;
1237
 
    }
1238
 
    
1239
1203
    uint16_t port;
1240
1204
    errno = 0;
1241
1205
    tmpmax = strtoimax(address+1, &tmp, 10);
1245
1209
      exitcode = EXIT_FAILURE;
1246
1210
      goto end;
1247
1211
    }
1248
 
  
1249
 
    if(quit_now){
1250
 
      goto end;
1251
 
    }
1252
 
    
1253
1212
    port = (uint16_t)tmpmax;
1254
1213
    *address = '\0';
1255
1214
    address = connect_to;
1260
1219
    } else {
1261
1220
      af = AF_INET;
1262
1221
    }
1263
 
    
1264
 
    if(quit_now){
1265
 
      goto end;
1266
 
    }
1267
 
    
1268
1222
    ret = start_mandos_communication(address, port, if_index, af);
1269
1223
    if(ret < 0){
1270
1224
      exitcode = EXIT_FAILURE;
1273
1227
    }
1274
1228
    goto end;
1275
1229
  }
1276
 
  
1277
 
  if(quit_now){
1278
 
    goto end;
1279
 
  }
1280
 
  
 
1230
    
1281
1231
  {
1282
1232
    AvahiServerConfig config;
1283
1233
    /* Do not publish any local Zeroconf records */
1304
1254
    goto end;
1305
1255
  }
1306
1256
  
1307
 
  if(quit_now){
1308
 
    goto end;
1309
 
  }
1310
 
  
1311
1257
  /* Create the Avahi service browser */
1312
1258
  sb = avahi_s_service_browser_new(mc.server, if_index,
1313
1259
                                   AVAHI_PROTO_UNSPEC, "_mandos._tcp",
1319
1265
    goto end;
1320
1266
  }
1321
1267
  
1322
 
  if(quit_now){
1323
 
    goto end;
1324
 
  }
1325
 
  
1326
1268
  /* Run the main loop */
1327
1269
  
1328
1270
  if(debug){
1357
1299
    gpgme_release(mc.ctx);
1358
1300
  }
1359
1301
  
1360
 
  /* Take down the network interface */
1361
 
  if(take_down_interface){
1362
 
    ret = ioctl(sd, SIOCGIFFLAGS, &network);
1363
 
    if(ret == -1){
1364
 
      perror("ioctl SIOCGIFFLAGS");
1365
 
    } else if(network.ifr_flags & IFF_UP) {
1366
 
      network.ifr_flags &= ~IFF_UP; /* clear flag */
1367
 
      ret = ioctl(sd, SIOCSIFFLAGS, &network);
1368
 
      if(ret == -1){
1369
 
        perror("ioctl SIOCSIFFLAGS");
1370
 
      }
1371
 
    }
1372
 
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
1373
 
    if(ret == -1){
1374
 
      perror("close");
1375
 
    }
1376
 
  }
1377
 
  
1378
1302
  /* Removes the temp directory used by GPGME */
1379
1303
  if(tempdir_created){
1380
1304
    DIR *d;