Vanilla Development Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CVS update: Vanilla/gum
Date: Wednesday July 28, 1999 @ 3:26
Author: tanner
Update of /home/netrek/cvsroot/Vanilla/gum
In directory cvs.castle.real-time.com:/var/tmp/cvs-serv16037/gum
Modified Files:
ChangeLog Makefile Makefile.am Makefile.in id.c
Added Files:
getugroups.c test-id.c xmalloc.c
Log Message:
* getugroups.c: Do not think I need this anymore. Took the
concepts and incorporated them into id.c, but left in because of
the GPL of the code I did not know what to do.
* xmalloc.c: Used code directly from the GNU sh-utils. Left it as
is.
* id.c: BETA :-) release of the functions. Some simple wrappers to
get all the groups a user belongs AND now search it for membership
in a particular group.
* Makefile.in (gum_SOURCES): Added the verify user code to the
Makefile.
****************************************
Index: Vanilla/gum/ChangeLog
diff -u Vanilla/gum/ChangeLog:1.3 Vanilla/gum/ChangeLog:1.4
--- Vanilla/gum/ChangeLog:1.3 Tue Jul 27 03:23:20 1999
+++ Vanilla/gum/ChangeLog Wed Jul 28 03:26:55 1999
@@ -1,3 +1,19 @@
+Wed Jul 28 02:24:17 1999 Bob Tanner <tanner@real-time.com>
+
+ * getugroups.c: Do not think I need this anymore. Took the
+ concepts and incorporated them into id.c, but left in because of
+ the GPL of the code I did not know what to do.
+
+ * xmalloc.c: Used code directly from the GNU sh-utils. Left it as
+ is.
+
+ * id.c: BETA :-) release of the functions. Some simple wrappers to
+ get all the groups a user belongs AND now search it for membership
+ in a particular group.
+
+ * Makefile.in (gum_SOURCES): Added the verify user code to the
+ Makefile.
+
Tue Jul 27 02:19:55 1999 Bob Tanner <tanner@real-time.com>
* id.c (main): Start of the code that will verify that the user is
@@ -19,6 +35,6 @@
* signals.c (on_About_activate): revise about screen to show who
to complain to.
- $Id: ChangeLog,v 1.3 1999/07/27 08:23:20 tanner Exp $
+ $Id: ChangeLog,v 1.4 1999/07/28 08:26:55 tanner Exp $
Index: Vanilla/gum/Makefile
diff -u Vanilla/gum/Makefile:1.6 Vanilla/gum/Makefile:1.7
--- Vanilla/gum/Makefile:1.6 Mon Jul 19 01:31:33 1999
+++ Vanilla/gum/Makefile Wed Jul 28 03:26:55 1999
@@ -16,7 +16,7 @@
srcdir = .
top_srcdir = .
-prefix = /usr/games/netrek
+prefix = /usr/local
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
@@ -73,7 +73,7 @@
bin_PROGRAMS = gum
-gum_SOURCES = support.c support.h main.c main.h signals.c signals.h
+gum_SOURCES = support.c support.h main.c main.h signals.c signals.h id.c xmalloc.c getugroups.c
gum_LDADD = -L/usr/lib -L/usr/X11R6/lib -lgtk -lgdk -rdynamic -lgmodule -lglib -ldl -lXext -lX11 -lm ../ntserv/data.o
@@ -87,7 +87,7 @@
CPPFLAGS =
LDFLAGS =
LIBS = -L/usr/lib -L/usr/X11R6/lib -lgtk -lgdk -rdynamic -lgmodule -lglib -ldl -lXext -lX11 -lm
-gum_OBJECTS = support.o main.o signals.o
+gum_OBJECTS = support.o main.o signals.o id.o xmalloc.o getugroups.o
gum_DEPENDENCIES = ../ntserv/data.o
gum_LDFLAGS =
CFLAGS = -g -O2 -I/usr/X11R6/include -I/usr/lib/glib/include -Wall
@@ -103,7 +103,8 @@
TAR = gtar
GZIP_ENV = --best
-DEP_FILES = .deps/main.P .deps/signals.P .deps/support.P
+DEP_FILES = .deps/getugroups.P .deps/id.P .deps/main.P .deps/signals.P \
+.deps/support.P .deps/xmalloc.P
SOURCES = $(gum_SOURCES)
OBJECTS = $(gum_OBJECTS)
Index: Vanilla/gum/Makefile.am
diff -u Vanilla/gum/Makefile.am:1.4 Vanilla/gum/Makefile.am:1.5
--- Vanilla/gum/Makefile.am:1.4 Sun Jul 18 09:49:52 1999
+++ Vanilla/gum/Makefile.am Wed Jul 28 03:26:56 1999
@@ -10,7 +10,8 @@
gum_SOURCES = \
support.c support.h \
main.c main.h \
- signals.c signals.h
+ signals.c signals.h \
+ id.c xmalloc.c getugroups.c
gum_LDADD = @GTK_LIBS@ ../ntserv/data.o
Index: Vanilla/gum/Makefile.in
diff -u Vanilla/gum/Makefile.in:1.6 Vanilla/gum/Makefile.in:1.7
--- Vanilla/gum/Makefile.in:1.6 Mon Jul 19 01:31:33 1999
+++ Vanilla/gum/Makefile.in Wed Jul 28 03:26:56 1999
@@ -73,7 +73,7 @@
bin_PROGRAMS = gum
-gum_SOURCES = support.c support.h main.c main.h signals.c signals.h
+gum_SOURCES = support.c support.h main.c main.h signals.c signals.h id.c xmalloc.c getugroups.c
gum_LDADD = @GTK_LIBS@ ../ntserv/data.o
@@ -87,7 +87,7 @@
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
-gum_OBJECTS = support.o main.o signals.o
+gum_OBJECTS = support.o main.o signals.o id.o xmalloc.o getugroups.o
gum_DEPENDENCIES = ../ntserv/data.o
gum_LDFLAGS =
CFLAGS = @CFLAGS@
@@ -103,7 +103,8 @@
TAR = gtar
GZIP_ENV = --best
-DEP_FILES = .deps/main.P .deps/signals.P .deps/support.P
+DEP_FILES = .deps/getugroups.P .deps/id.P .deps/main.P .deps/signals.P \
+.deps/support.P .deps/xmalloc.P
SOURCES = $(gum_SOURCES)
OBJECTS = $(gum_OBJECTS)
Index: Vanilla/gum/id.c
diff -u Vanilla/gum/id.c:1.1 Vanilla/gum/id.c:1.2
--- Vanilla/gum/id.c:1.1 Tue Jul 27 03:23:20 1999
+++ Vanilla/gum/id.c Wed Jul 28 03:26:56 1999
@@ -5,63 +5,109 @@
#include <grp.h>
#include <getopt.h>
-static void user_in_group(uid_t, gid_t);
-static void print_user __P ((int uid));
-static void print_group __P ((int gid));
+#define GETGROUPS_T gid_t
+static void print_user __P ((uid_t uid));
+static char* uid_to_string(uid_t uid);
+static void print_group __P ((gid_t gid));
+static char* gid_to_string(uid_t gid);
static void print_group_list __P ((char *username));
+int get_all_groups(char*, gid_t **);
+int search_4group(gid_t, int, gid_t *);
-/* The real and effective IDs of the user to print. */
-static uid_t ruid, euid;
-static gid_t rgid, egid;
+int
+search_4group(gid_t group, int count, gid_t *supp_groups)
+{
+ int i;
+
+ for (i = 0; i < count; i++) {
+ if (group == supp_groups[i])
+ return 1;
+ }
+ return 0;
+}
-int main (int argc, char **argv)
+int
+get_all_groups(char *username, gid_t **groups)
{
- static gid_t games = 20;
+ int max_groups;
+ gid_t *g;
- struct passwd *pwd = getpwnam("tanner");
- if (pwd == NULL) {
- printf("No such user");
- exit(1);
+ if ((max_groups = getugroups(0, NULL, username)) < 0) {
+ return -1;
}
- ruid = euid = pwd->pw_uid;
- rgid = egid = pwd->pw_gid;
-
- user_in_group(ruid, games);
-}
+ g = (gid_t *) xmalloc(max_groups * sizeof(gid_t) + 1);
+ if ((getugroups(max_groups, g, username)) < 0) {
+ return -1;
+ }
-static
-void user_in_group(uid_t uid, gid_t gid)
+ *groups = g;
+ return max_groups;
+}
+
+/* Same as getgroups by uses a username instead of uid */
+int
+getugroups (int maxcount, gid_t *grouplist, char *username)
{
- print_user(uid);
- print_group(gid);
+ struct group *grp;
+ register char **cp;
+ register int count = 0;
+
+ setgrent ();
+ while ((grp = getgrent ()) != 0)
+ for (cp = grp->gr_mem; *cp; ++cp)
+ if (!strcmp (username, *cp)) {
+ if (maxcount != 0) {
+ if (count >= maxcount) {
+ endgrent ();
+ return count;
+ }
+ grouplist[count] = grp->gr_gid;
+ }
+ count++;
+ }
+ endgrent ();
+ return count;
}
+/* Send me a uid and I'll print you the username */
+
static
-void print_user(int uid)
+void print_user(uid_t uid)
{
+ printf("%s", uid_to_string(uid));
+}
+
+static
+char *uid_to_string(uid_t uid)
+{
struct passwd *pwd = NULL;
pwd = getpwuid(uid);
if (pwd == NULL) {
- printf("Cannot find uid");
- return;
+ return NULL;
}
-
- printf("%s", pwd->pw_name);
+ return pwd->pw_name;
}
+/* Send me a guid and I'll print you the group name */
+
static
-void print_group(int gid)
+void print_group(gid_t gid)
{
+ printf("%s", gid_to_string(gid));
+}
+
+static
+char *gid_to_string(gid_t gid)
+{
struct group *grp = NULL;
grp = getgrgid(gid);
if (grp == NULL) {
- printf("Cannot find gid");
- return;
+ return NULL;
}
-
- printf("%s", grp->gr_name);
-}
+
+ return grp->gr_name;
+}