/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-06-02 11:09:07 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090602110907-utt933ql22lq8j7l
* plugins.d/mandos-client.c (main): Take down network interface on
                                    exit if it was brought up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
899
899
  int exitcode = EXIT_SUCCESS;
900
900
  const char *interface = "eth0";
901
901
  struct ifreq network;
902
 
  int sd;
 
902
  int sd = -1;
 
903
  bool interface_taken_up = false;
903
904
  uid_t uid;
904
905
  gid_t gid;
905
906
  char *connect_to = NULL;
1113
1114
#endif  /* __linux__ */
1114
1115
        goto end;
1115
1116
      }
 
1117
      interface_taken_up = true;
1116
1118
    }
1117
1119
    /* sleep checking until interface is running */
1118
1120
    for(int i=0; i < delay * 4; i++){
1128
1130
        perror("nanosleep");
1129
1131
      }
1130
1132
    }
1131
 
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
1132
 
    if(ret == -1){
1133
 
      perror("close");
 
1133
    if(not interface_taken_up){
 
1134
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
1135
      if(ret == -1){
 
1136
        perror("close");
 
1137
      }
1134
1138
    }
1135
1139
#ifdef __linux__
1136
1140
    if(restore_loglevel){
1297
1301
    gpgme_release(mc.ctx);
1298
1302
  }
1299
1303
  
 
1304
  /* Take down the network interface */
 
1305
  if(interface_taken_up){
 
1306
    ret = ioctl(sd, SIOCGIFFLAGS, &network);
 
1307
    if(ret == -1){
 
1308
      perror("ioctl SIOCGIFFLAGS");
 
1309
    } else if(network.ifr_flags & IFF_UP) {
 
1310
      network.ifr_flags &= ~IFF_UP; /* clear flag */
 
1311
      ret = ioctl(sd, SIOCSIFFLAGS, &network);
 
1312
      if(ret == -1){
 
1313
        perror("ioctl SIOCSIFFLAGS");
 
1314
      }
 
1315
    }
 
1316
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
1317
    if(ret == -1){
 
1318
      perror("close");
 
1319
    }
 
1320
  }
 
1321
  
1300
1322
  /* Removes the temp directory used by GPGME */
1301
1323
  if(tempdir_created){
1302
1324
    DIR *d;