Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

setugid.cc File Reference

#include <errno.h>
#include <sys/types.h>
#include <grp.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <iostream>
#include "setugid.h"

Go to the source code of this file.

Functions

void setugid (const char *uname, const char *gname)


Function Documentation

void setugid const char *  uname,
const char *  gname
 

Definition at line 15 of file setugid.cc.

Referenced by main(), and nntpd().

00016 {
00017         struct passwd *pwd;
00018         struct group *grp;
00019 
00020         if (gname && *gname) {
00021                 if ((grp = getgrnam(gname)) == NULL) {
00022                         cerr << "Cannot get grent for " << gname
00023                             <<
00024                             "\nPlease set the Groupname in newscache.conf\n";
00025                         exit(1);
00026                 }
00027                 if (setregid(grp->gr_gid, grp->gr_gid) < 0) {
00028                         cerr << "Cannot set effective groupid to " << grp->
00029                             gr_gid << ": " << strerror(errno) << endl;
00030                         exit(1);
00031                 }
00032         }
00033         if (uname && *uname) {
00034                 if ((pwd = getpwnam(uname)) == NULL) {
00035                         cerr << "Cannot get pwent for " << uname
00036                             <<
00037                             "\nPlease set the Username in newscache.conf\n";
00038                         exit(1);
00039                 }
00040                 if (setreuid(pwd->pw_uid, pwd->pw_uid) < 0) {
00041                         cerr << "Cannot set effective userid to " << pwd->
00042                             pw_uid << ": " << strerror(errno) << endl;
00043                         exit(1);
00044                 }
00045         }
00046 }


Generated on Fri Aug 20 10:58:09 2004 for NewsCache by doxygen 1.3.6-20040222