From e237f94b3f5e80fb08e3ec572ea60ce6419d2c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lang=C3=A5s?= Date: Wed, 6 Mar 2002 17:05:05 +0000 Subject: [PATCH] =?UTF-8?q?Flyttet=20noe=20kode=20inn=20i=20common.c=20N?= =?UTF-8?q?=C3=A5=20kan=20man=20ogs=C3=A5=20se=20alle=20brukere=20som=20gr?= =?UTF-8?q?uppene=20man=20er=20medlem=20i,=20har?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common.c | 35 +++++++++++++++++++++++++++++++++-- mysql-admutils.h | 6 +++++- mysql-dbadm.c | 33 +-------------------------------- mysql-useradm.c | 16 +++++++++++++--- 4 files changed, 52 insertions(+), 38 deletions(-) diff --git a/common.c b/common.c index c45d72b..a125f73 100644 --- a/common.c +++ b/common.c @@ -1,5 +1,5 @@ /* - * @(#) $Header: /tmp/cvs/mysql-admutils/common.c,v 1.2 2002-02-27 08:49:48 knutpett Exp $ + * @(#) $Header: /tmp/cvs/mysql-admutils/common.c,v 1.3 2002-03-06 17:05:05 tlan Exp $ * * functions used by mysql-dbadm.c and mysql-useradm.c * @@ -22,7 +22,7 @@ char *program_name; -static char *rcsheader = "@(#) " PACKAGE " " VERSION " ljosa@initio.no $Header: /tmp/cvs/mysql-admutils/common.c,v 1.2 2002-02-27 08:49:48 knutpett Exp $"; +static char *rcsheader = "@(#) " PACKAGE " " VERSION " ljosa@initio.no $Header: /tmp/cvs/mysql-admutils/common.c,v 1.3 2002-03-06 17:05:05 tlan Exp $"; int @@ -187,6 +187,37 @@ member(char *gr) { } +/* return a list of the user's groupnames */ +/* numgroups is the total number of groups found */ +char **get_group_names(int *numgroups) +{ + char **grouplist; + gid_t gids[33]; + int nr_groups, i; + struct group *g; + + nr_groups = 0; + + nr_groups = getgroups(32, &gids[0]); /* Allow a max of 32 groups */ + + if (nr_groups == -1) { + dberror(NULL, "Error while trying to fetch group info"); + return NULL; + } + *numgroups = nr_groups; + + grouplist = malloc((nr_groups+1) * sizeof(char *)); + + for (i = 0; i < nr_groups; i++) { + g = getgrgid(gids[i]); + + grouplist[i] = strdup(g->gr_name); + } + grouplist[i] = NULL; + + return grouplist; +} + int reload(MYSQL *pmysql) diff --git a/mysql-admutils.h b/mysql-admutils.h index 8a6b5b0..3db5937 100644 --- a/mysql-admutils.h +++ b/mysql-admutils.h @@ -1,5 +1,5 @@ /* - * @(#) $Header: /tmp/cvs/mysql-admutils/mysql-admutils.h,v 1.2 2002-02-27 08:49:48 knutpett Exp $ + * @(#) $Header: /tmp/cvs/mysql-admutils/mysql-admutils.h,v 1.3 2002-03-06 17:05:05 tlan Exp $ * */ @@ -23,6 +23,10 @@ fatal_error(char *format, ...); extern int owner(char *name); +extern int member(char *gr); + +extern char **get_group_names(int *numgroups); + extern int version(void); diff --git a/mysql-dbadm.c b/mysql-dbadm.c index 7faf7cd..8507eb8 100644 --- a/mysql-dbadm.c +++ b/mysql-dbadm.c @@ -1,5 +1,5 @@ /* - * @(#) $Header: /tmp/cvs/mysql-admutils/mysql-dbadm.c,v 1.4 2002-03-06 16:47:12 tlan Exp $ + * @(#) $Header: /tmp/cvs/mysql-admutils/mysql-dbadm.c,v 1.5 2002-03-06 17:05:05 tlan Exp $ * * mysql-dbadm.c * @@ -111,37 +111,6 @@ drop(MYSQL *pmysql, char *db) return 0; } -/* return a list of the user's groupnames */ -/* numgroups is the total number of groups found */ -char **get_group_names(int *numgroups) -{ - char **grouplist; - gid_t gids[33]; - int nr_groups, i; - struct group *g; - - nr_groups = 0; - - nr_groups = getgroups(32, &gids[0]); /* Allow a max of 32 groups */ - - if (nr_groups == -1) { - dberror(NULL, "Error while trying to fetch group info"); - return NULL; - } - *numgroups = nr_groups; - - grouplist = malloc((nr_groups+1) * sizeof(char *)); - - for (i = 0; i < nr_groups; i++) { - g = getgrgid(gids[i]); - - grouplist[i] = strdup(g->gr_name); - } - grouplist[i] = NULL; - - return grouplist; -} - /* return a list of the user's databases */ char ** list(MYSQL *pmysql) diff --git a/mysql-useradm.c b/mysql-useradm.c index a3553b7..a57888c 100644 --- a/mysql-useradm.c +++ b/mysql-useradm.c @@ -1,5 +1,5 @@ /* - * @(#) $Header: /tmp/cvs/mysql-admutils/mysql-useradm.c,v 1.2 2002-02-27 08:49:48 knutpett Exp $ + * @(#) $Header: /tmp/cvs/mysql-admutils/mysql-useradm.c,v 1.3 2002-03-06 17:05:05 tlan Exp $ * * mysql-useradm.c * @@ -169,9 +169,10 @@ show(MYSQL *pmysql, const char *user) char ** list(MYSQL *pmysql) { - char query[1024]; + char query[4096]; + char **usrgroups, **cp; MYSQL_RES *res; - int rows; + int rows, numgroups; MYSQL_ROW row; char **userlist; int i; @@ -181,6 +182,15 @@ list(MYSQL *pmysql) sprintf(query, "select user from user where user='%s' or user like '%s_%%'", p->pw_name, p->pw_name); + numgroups = 0; + + usrgroups = get_group_names(&numgroups); + cp = usrgroups; + while (*cp) { + sprintf(&query[strlen(query)], " or user='%s' or user like '%s_%%'", *cp, *cp); + cp++; + } + if (mysql_query(pmysql, query)) { dberror(pmysql, "Failed to look up %s's users.", p->pw_name);