diff options
author | Balbir Singh <balbir@linux.vnet.ibm.com> | 2008-09-26 11:56:34 +0000 |
---|---|---|
committer | Balbir Singh <balbir@linux.vnet.ibm.com> | 2008-09-26 11:56:34 +0000 |
commit | 35d2e11a0458a79c89816a2f0be6fb957f91873e (patch) | |
tree | d3aa75330e12baf3208cc1513094fa07bd16eddd /tests | |
parent | a8f3daf54136de7e02fc2cf153ad55051ce95ab4 (diff) | |
download | libcg-35d2e11a0458a79c89816a2f0be6fb957f91873e.tar.gz libcg-35d2e11a0458a79c89816a2f0be6fb957f91873e.tar.xz libcg-35d2e11a0458a79c89816a2f0be6fb957f91873e.zip |
Merge the cgruleseng daemon from Steve Olivieri
Signed-off-by: Steve Olivieri <sjo@redhat.com>
Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@190 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile | 7 | ||||
-rw-r--r-- | tests/setuid.c | 75 |
2 files changed, 81 insertions, 1 deletions
diff --git a/tests/Makefile b/tests/Makefile index e668032..7a38b7a 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -2,9 +2,11 @@ LDFLAGS = -L .. LIBS = -lcgroup -lpthread INC = -I .. CXXFLAGS = -g -O2 -Wall -DDEBUG $(INC) +CFLAGS = -g -O2 -Wall -DDEBUG TARGET= libcgrouptest01 \ - libcg_ba + libcg_ba \ + setuid all: $(TARGET) @@ -14,5 +16,8 @@ libcgrouptest01: libcgrouptest01.c libcg_ba: libcg_ba.cpp $(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIBS) +setuid: setuid.c + $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LIBS) + clean: \rm -f $(TARGET) diff --git a/tests/setuid.c b/tests/setuid.c new file mode 100644 index 0000000..9d77850 --- /dev/null +++ b/tests/setuid.c @@ -0,0 +1,75 @@ +/* + * Copyright Red Hat Inc. 2008 + * + * Author: Steve Olivieri <sjo@redhat.com> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <unistd.h> +#include <pwd.h> +#include <grp.h> +#include <errno.h> +#include <string.h> + +/* + * This is just a simple program for changing a UID or a GID. Comment out + * whichever block you don't want to use. + */ +int main(int argc, char *argv[]) +{ + /* User data */ + struct passwd *pwd; + + /* UID of user */ + uid_t uid; + + /* Group data */ + struct group *grp; + + /* GID of group */ + gid_t gid; + + /* Return codes */ + int ret; + + pwd = getpwnam(argv[1]); + uid = pwd->pw_uid; + fprintf(stdout, "Setting UID to %s (%d).\n", pwd->pw_name, uid); + if ((ret = setuid(uid))) { + fprintf(stderr, "Call to setuid() failed with error: %s\n", + strerror(errno)); + ret = -errno; + goto finished; + } + +// while(1) { +// grp = getgrnam("root"); +// gid = grp->gr_gid; +// fprintf(stdout, "Setting GID to %s (%d).\n", +// grp->gr_name, gid); +// if ((ret = setgid(gid))) { +// fprintf(stderr, "Call to setgid() failed with error:" +// " %s\n", strerror(errno)); +// ret = -errno; +// goto finished; +// } +// } + + while (1) { + usleep(3000000); + } + +finished: + return ret; +} |