/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: Björn Påhlsson
  • Date: 2011-11-24 21:32:23 UTC
  • mfrom: (505.3.12 client-network-hooks)
  • mto: This revision was merged to the branch mainline in revision 525.
  • Revision ID: belorn@fukt.bsnet.se-20111124213223-er6pl323sru1y0sz
merge

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