/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

* network-hooks.d: New directory.
* network-hooks.d/bridge: New example hook.
* network-hooks.d/bridge.conf: Config file for bridge example hook.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1301
1301
    }
1302
1302
    return 0;
1303
1303
  }
1304
 
  if(debug){
1305
 
    fprintf_plus(stderr, "Hook \"%s\" is acceptable\n",
1306
 
                 direntry->d_name);
1307
 
  }
1308
1304
  return 1;
1309
1305
}
1310
1306
 
1392
1388
  } else {
1393
1389
    int devnull = open("/dev/null", O_RDONLY);
1394
1390
    for(int i = 0; i < numhooks; i++){
1395
 
      direntry = direntries[i];
 
1391
      direntry = direntries[0];
1396
1392
      char *fullname = NULL;
1397
1393
      ret = asprintf(&fullname, "%s/%s", hookdir, direntry->d_name);
1398
1394
      if(ret < 0){
1399
1395
        perror_plus("asprintf");
1400
1396
        continue;
1401
1397
      }
1402
 
      if(debug){
1403
 
        fprintf_plus(stderr, "Running network hook \"%s\"\n",
1404
 
                     direntry->d_name);
1405
 
      }
1406
1398
      pid_t hook_pid = fork();
1407
1399
      if(hook_pid == 0){
1408
1400
        /* Child */
1473
1465
        }
1474
1466
      }
1475
1467
      free(fullname);
1476
 
      if(debug){
1477
 
        fprintf_plus(stderr, "Network hook \"%s\" ran successfully\n",
1478
 
                     direntry->d_name);
 
1468
      if(quit_now){
 
1469
        break;
1479
1470
      }
1480
1471
    }
1481
1472
    close(devnull);
1678
1669
    }
1679
1670
  }
1680
1671
    
1681
 
  if(getuid() == 0){
 
1672
  {
1682
1673
    /* Work around Debian bug #633582:
1683
1674
       <http://bugs.debian.org/633582> */
1684
1675
    struct stat st;
1742
1733
  
1743
1734
  /* Run network hooks */
1744
1735
  {
1745
 
    if(getuid() == 0){
1746
 
      /* Re-raise priviliges */
1747
 
      errno = 0;
1748
 
      ret = seteuid(0);
1749
 
      if(ret == -1){
1750
 
        perror_plus("seteuid");
1751
 
      }
 
1736
    /* Re-raise priviliges */
 
1737
    errno = 0;
 
1738
    ret = seteuid(0);
 
1739
    if(ret == -1){
 
1740
      perror_plus("seteuid");
1752
1741
    }
1753
1742
    if(not run_network_hooks("start", interface, delay)){
1754
1743
      goto end;
1755
1744
    }
1756
 
    if(getuid() == 0){
1757
 
      /* Lower privileges */
1758
 
      errno = 0;
1759
 
      ret = seteuid(uid);
1760
 
      if(ret == -1){
1761
 
        perror_plus("seteuid");
1762
 
      }
 
1745
    /* Lower privileges */
 
1746
    errno = 0;
 
1747
    ret = seteuid(uid);
 
1748
    if(ret == -1){
 
1749
      perror_plus("seteuid");
1763
1750
    }
1764
1751
  }
1765
1752
  
2205
2192
  if(gpgme_initialized){
2206
2193
    gpgme_release(mc.ctx);
2207
2194
  }
2208
 
  
 
2195
 
2209
2196
  /* Cleans up the circular linked list of Mandos servers the client
2210
2197
     has seen */
2211
2198
  if(mc.current_server != NULL){
2219
2206
  
2220
2207
  /* Re-raise priviliges */
2221
2208
  {
2222
 
    if(getuid() == 0){
2223
 
      errno = 0;
2224
 
      ret = seteuid(0);
2225
 
      if(ret == -1){
2226
 
        perror_plus("seteuid");
2227
 
      }
 
2209
    errno = 0;
 
2210
    ret = seteuid(0);
 
2211
    if(ret == -1){
 
2212
      perror_plus("seteuid");
2228
2213
    }
2229
 
    
2230
2214
    /* Run network hooks */
2231
 
    run_network_hooks("stop", interface, delay);
 
2215
    if(not run_network_hooks("stop", interface, delay)){
 
2216
      goto end;
 
2217
    }
2232
2218
    
2233
2219
    /* Take down the network interface */
2234
2220
    if(take_down_interface and geteuid() == 0){
2248
2234
      }
2249
2235
    }
2250
2236
  }
2251
 
  if(getuid() == 0){
2252
 
    /* Lower privileges permanently */
2253
 
    errno = 0;
2254
 
    ret = setuid(uid);
2255
 
    if(ret == -1){
2256
 
      perror_plus("setuid");
2257
 
    }
 
2237
  /* Lower privileges permanently */
 
2238
  errno = 0;
 
2239
  ret = setuid(uid);
 
2240
  if(ret == -1){
 
2241
    perror_plus("setuid");
2258
2242
  }
2259
2243
  
2260
2244
  /* Removes the GPGME temp directory and all files inside */