/mandos/release

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

« back to all changes in this revision

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

* mandos (ClientHandler.handle): Bug fix: add missing right
                                 parenthesis.

Show diffs side-by-side

added added

removed removed

Lines of Context:
780
780
  return retval;
781
781
}
782
782
 
783
 
sig_atomic_t quit_now = 0;
784
 
 
785
783
static void resolve_callback(AvahiSServiceResolver *r,
786
784
                             AvahiIfIndex interface,
787
785
                             AvahiProtocol proto,
801
799
  /* Called whenever a service has been resolved successfully or
802
800
     timed out */
803
801
  
804
 
  if(quit_now){
805
 
    return;
806
 
  }
807
 
  
808
802
  switch(event){
809
803
  default:
810
804
  case AVAHI_RESOLVER_FAILURE:
881
875
  }
882
876
}
883
877
 
 
878
sig_atomic_t quit_now = 0;
 
879
 
884
880
/* stop main loop after sigterm has been called */
885
881
static void handle_sigterm(__attribute__((unused)) int sig){
886
882
  if(quit_now){
904
900
  const char *interface = "eth0";
905
901
  struct ifreq network;
906
902
  int sd = -1;
907
 
  bool take_down_interface = false;
 
903
  bool interface_taken_up = false;
908
904
  uid_t uid;
909
905
  gid_t gid;
910
906
  char *connect_to = NULL;
1062
1058
  
1063
1059
  /* If the interface is down, bring it up */
1064
1060
  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
1061
#ifdef __linux__
1077
1062
    /* Lower kernel loglevel to KERN_NOTICE to avoid KERN_INFO
1078
1063
       messages to mess up the prompt */
1115
1100
    }
1116
1101
    if((network.ifr_flags & IFF_UP) == 0){
1117
1102
      network.ifr_flags |= IFF_UP;
1118
 
      take_down_interface = true;
1119
1103
      ret = ioctl(sd, SIOCSIFFLAGS, &network);
1120
1104
      if(ret == -1){
1121
 
        take_down_interface = false;
1122
1105
        perror("ioctl SIOCSIFFLAGS");
1123
1106
        exitcode = EXIT_FAILURE;
1124
1107
#ifdef __linux__
1131
1114
#endif  /* __linux__ */
1132
1115
        goto end;
1133
1116
      }
 
1117
      interface_taken_up = true;
1134
1118
    }
1135
1119
    /* sleep checking until interface is running */
1136
1120
    for(int i=0; i < delay * 4; i++){
1146
1130
        perror("nanosleep");
1147
1131
      }
1148
1132
    }
1149
 
    if(not take_down_interface){
1150
 
      /* We won't need the socket anymore */
 
1133
    if(not interface_taken_up){
1151
1134
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
1152
1135
      if(ret == -1){
1153
1136
        perror("close");
1164
1147
#endif  /* __linux__ */
1165
1148
  }
1166
1149
  
1167
 
  if(quit_now){
1168
 
    goto end;
1169
 
  }
1170
 
  
1171
1150
  uid = getuid();
1172
1151
  gid = getgid();
1173
1152
  
1182
1161
    perror("setuid");
1183
1162
  }
1184
1163
  
1185
 
  if(quit_now){
1186
 
    goto end;
1187
 
  }
1188
 
  
1189
1164
  ret = init_gnutls_global(pubkey, seckey);
1190
1165
  if(ret == -1){
1191
1166
    fprintf(stderr, "init_gnutls_global failed\n");
1195
1170
    gnutls_initialized = true;
1196
1171
  }
1197
1172
  
1198
 
  if(quit_now){
1199
 
    goto end;
1200
 
  }
1201
 
  
1202
 
  tempdir_created = true;
1203
1173
  if(mkdtemp(tempdir) == NULL){
1204
 
    tempdir_created = false;
1205
1174
    perror("mkdtemp");
1206
1175
    goto end;
1207
1176
  }
1208
 
  
1209
 
  if(quit_now){
1210
 
    goto end;
1211
 
  }
 
1177
  tempdir_created = true;
1212
1178
  
1213
1179
  if(not init_gpgme(pubkey, seckey, tempdir)){
1214
1180
    fprintf(stderr, "init_gpgme failed\n");
1218
1184
    gpgme_initialized = true;
1219
1185
  }
1220
1186
  
1221
 
  if(quit_now){
1222
 
    goto end;
 
1187
  if(interface[0] != '\0'){
 
1188
    if_index = (AvahiIfIndex) if_nametoindex(interface);
 
1189
    if(if_index == 0){
 
1190
      fprintf(stderr, "No such interface: \"%s\"\n", interface);
 
1191
      exitcode = EXIT_FAILURE;
 
1192
      goto end;
 
1193
    }
1223
1194
  }
1224
1195
  
1225
1196
  if(connect_to != NULL){
1231
1202
      exitcode = EXIT_FAILURE;
1232
1203
      goto end;
1233
1204
    }
1234
 
    
1235
 
    if(quit_now){
1236
 
      goto end;
1237
 
    }
1238
 
    
1239
1205
    uint16_t port;
1240
1206
    errno = 0;
1241
1207
    tmpmax = strtoimax(address+1, &tmp, 10);
1245
1211
      exitcode = EXIT_FAILURE;
1246
1212
      goto end;
1247
1213
    }
1248
 
  
1249
 
    if(quit_now){
1250
 
      goto end;
1251
 
    }
1252
 
    
1253
1214
    port = (uint16_t)tmpmax;
1254
1215
    *address = '\0';
1255
1216
    address = connect_to;
1260
1221
    } else {
1261
1222
      af = AF_INET;
1262
1223
    }
1263
 
    
1264
 
    if(quit_now){
1265
 
      goto end;
1266
 
    }
1267
 
    
1268
1224
    ret = start_mandos_communication(address, port, if_index, af);
1269
1225
    if(ret < 0){
1270
1226
      exitcode = EXIT_FAILURE;
1273
1229
    }
1274
1230
    goto end;
1275
1231
  }
1276
 
  
1277
 
  if(quit_now){
1278
 
    goto end;
1279
 
  }
1280
 
  
 
1232
    
1281
1233
  {
1282
1234
    AvahiServerConfig config;
1283
1235
    /* Do not publish any local Zeroconf records */
1304
1256
    goto end;
1305
1257
  }
1306
1258
  
1307
 
  if(quit_now){
1308
 
    goto end;
1309
 
  }
1310
 
  
1311
1259
  /* Create the Avahi service browser */
1312
1260
  sb = avahi_s_service_browser_new(mc.server, if_index,
1313
1261
                                   AVAHI_PROTO_UNSPEC, "_mandos._tcp",
1319
1267
    goto end;
1320
1268
  }
1321
1269
  
1322
 
  if(quit_now){
1323
 
    goto end;
1324
 
  }
1325
 
  
1326
1270
  /* Run the main loop */
1327
1271
  
1328
1272
  if(debug){
1358
1302
  }
1359
1303
  
1360
1304
  /* Take down the network interface */
1361
 
  if(take_down_interface){
 
1305
  if(interface_taken_up){
1362
1306
    ret = ioctl(sd, SIOCGIFFLAGS, &network);
1363
1307
    if(ret == -1){
1364
1308
      perror("ioctl SIOCGIFFLAGS");