Flyttet noe kode inn i common.c
Nå kan man også se alle brukere som gruppene man er medlem i, har
This commit is contained in:
parent
fe7ad3f488
commit
e237f94b3f
35
common.c
35
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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user