/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-09-07 07:48:59 UTC
  • Revision ID: teddy@fukt.bsnet.se-20090907074859-nv2nni1wwib5hi10
* plugin-runner.c: Minor stylistic changes.

* plugins.d/askpass-fifo.c: Changed contact information and did minor
                            stylistic changes.

* plugins.d/mandos-client.c: Minor stylistic changes.

* plugins.d/password-prompt.c: Changed contact information.

* plugins.d/splashy.c: Changed contact information.
  (main): Changed error handling design.  Bug fix: Will now be much
          more tolerant against signals.  Bug fix: Will now re-raise
          signal received.

* plugins.d/usplash.c: Changed contact information and did minor
                       stylistic changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
                                   INET_ADDRSTRLEN, INET6_ADDRSTRLEN
72
72
                                */
73
73
#include <unistd.h>             /* close(), SEEK_SET, off_t, write(),
74
 
                                   getuid(), getgid(), seteuid(),
 
74
                                   getuid(), getgid(), setuid(),
75
75
                                   setgid() */
76
76
#include <arpa/inet.h>          /* inet_pton(), htons */
77
77
#include <iso646.h>             /* not, or, and */
1285
1285
  uid = getuid();
1286
1286
  gid = getgid();
1287
1287
  
1288
 
  /* Drop any group privileges we might have, just to be safe */
1289
1288
  errno = 0;
1290
 
  ret = setgid(gid);
 
1289
  setgid(gid);
1291
1290
  if(ret == -1){
1292
1291
    perror("setgid");
1293
1292
  }
1294
1293
  
1295
 
  /* Drop user privileges */
1296
 
  errno = 0;
1297
 
  /* Will we need privileges later? */
1298
 
  if(take_down_interface){
1299
 
    /* Drop user privileges temporarily */
1300
 
    ret = seteuid(uid);
1301
 
    if(ret == -1){
1302
 
      perror("seteuid");
1303
 
    }
1304
 
  } else {
1305
 
    /* Drop user privileges permanently */
1306
 
    ret = setuid(uid);
1307
 
    if(ret == -1){
1308
 
      perror("setuid");
1309
 
    }
 
1294
  ret = setuid(uid);
 
1295
  if(ret == -1){
 
1296
    perror("setuid");
1310
1297
  }
1311
1298
  
1312
1299
  if(quit_now){
1486
1473
  
1487
1474
  /* Take down the network interface */
1488
1475
  if(take_down_interface){
1489
 
    /* Re-raise priviliges */
1490
 
    errno = 0;
1491
 
    ret = seteuid(0);
 
1476
    ret = ioctl(sd, SIOCGIFFLAGS, &network);
1492
1477
    if(ret == -1){
1493
 
      perror("seteuid");
 
1478
      perror("ioctl SIOCGIFFLAGS");
 
1479
    } else if(network.ifr_flags & IFF_UP) {
 
1480
      network.ifr_flags &= ~IFF_UP; /* clear flag */
 
1481
      ret = ioctl(sd, SIOCSIFFLAGS, &network);
 
1482
      if(ret == -1){
 
1483
        perror("ioctl SIOCSIFFLAGS");
 
1484
      }
1494
1485
    }
1495
 
    if(geteuid() == 0){
1496
 
      ret = ioctl(sd, SIOCGIFFLAGS, &network);
1497
 
      if(ret == -1){
1498
 
        perror("ioctl SIOCGIFFLAGS");
1499
 
      } else if(network.ifr_flags & IFF_UP) {
1500
 
        network.ifr_flags &= ~IFF_UP; /* clear flag */
1501
 
        ret = ioctl(sd, SIOCSIFFLAGS, &network);
1502
 
        if(ret == -1){
1503
 
          perror("ioctl SIOCSIFFLAGS");
1504
 
        }
1505
 
      }
1506
 
      ret = (int)TEMP_FAILURE_RETRY(close(sd));
1507
 
      if(ret == -1){
1508
 
        perror("close");
1509
 
      }
1510
 
      /* Lower privileges, permanently this time */
1511
 
      errno = 0;
1512
 
      ret = setuid(uid);
1513
 
      if(ret == -1){
1514
 
        perror("setuid");
1515
 
      }
 
1486
    ret = (int)TEMP_FAILURE_RETRY(close(sd));
 
1487
    if(ret == -1){
 
1488
      perror("close");
1516
1489
    }
1517
1490
  }
1518
1491