Automatically determine user and group.
This commit is contained in:
+4
-3
@@ -1,6 +1,7 @@
|
|||||||
/* user and group to drop privileges to */
|
/* user and group to drop privileges to */
|
||||||
static const char *user = "igor";
|
/* NOTE: Leave these empty if you want them to be determined automatically. */
|
||||||
static const char *group = "igor";
|
static const char *user = "";
|
||||||
|
static const char *group = "";
|
||||||
|
|
||||||
static const char *colorname[NUMCOLS] = {
|
static const char *colorname[NUMCOLS] = {
|
||||||
[INIT] = "black", /* after initialization */
|
[INIT] = "black", /* after initialization */
|
||||||
@@ -24,7 +25,7 @@ static const Passthrough passthroughs[] = {
|
|||||||
{ 0, XF86XK_MonBrightnessDown },
|
{ 0, XF86XK_MonBrightnessDown },
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *dspoffcmd[] = { "xset", "dpms", "force", "off", NULL };
|
/*static const char *dspoffcmd[] = { "xset", "dpms", "force", "off", NULL };*/
|
||||||
|
|
||||||
static const Key keys[] = {
|
static const Key keys[] = {
|
||||||
/* modifier key function argument */
|
/* modifier key function argument */
|
||||||
|
|||||||
@@ -409,6 +409,8 @@ main(int argc, char **argv) {
|
|||||||
int s, nlocks, nscreens;
|
int s, nlocks, nscreens;
|
||||||
int event_base, error_base;
|
int event_base, error_base;
|
||||||
|
|
||||||
|
char *username, *groupname;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'v':
|
case 'v':
|
||||||
puts("slock-"VERSION);
|
puts("slock-"VERSION);
|
||||||
@@ -417,15 +419,25 @@ main(int argc, char **argv) {
|
|||||||
usage();
|
usage();
|
||||||
} ARGEND
|
} ARGEND
|
||||||
|
|
||||||
|
if(strlen(user) && strlen(group)) {
|
||||||
|
username = (char *)user;
|
||||||
|
groupname = (char *)group;
|
||||||
|
} else {
|
||||||
|
username = getenv("USER");
|
||||||
|
groupname = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s:%s\n", username, groupname);
|
||||||
|
|
||||||
/* validate drop-user and -group */
|
/* validate drop-user and -group */
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (!(pwd = getpwnam(user)))
|
if (!(pwd = getpwnam(username)))
|
||||||
die("slock: getpwnam %s: %s\n", user,
|
die("slock: getpwnam %s: %s\n", username,
|
||||||
errno ? strerror(errno) : "user entry not found");
|
errno ? strerror(errno) : "user entry not found");
|
||||||
duid = pwd->pw_uid;
|
duid = pwd->pw_uid;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (!(grp = getgrnam(group)))
|
if (!(grp = getgrnam(groupname)))
|
||||||
die("slock: getgrnam %s: %s\n", group,
|
die("slock: getgrnam %s: %s\n", groupname,
|
||||||
errno ? strerror(errno) : "group entry not found");
|
errno ? strerror(errno) : "group entry not found");
|
||||||
dgid = grp->gr_gid;
|
dgid = grp->gr_gid;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user