With alter table patches and the undocumented feature for administering

mysql users and databases with same name as unix groups for the user.
This commit is contained in:
2002-02-27 08:49:48 +00:00
parent 7f589bb064
commit ff52786682
10 changed files with 260 additions and 20 deletions

@ -1,5 +1,5 @@
/*
* @(#) $Header: /tmp/cvs/mysql-admutils/common.c,v 1.1.1.1 2001-11-25 00:41:16 lkarsten Exp $
* @(#) $Header: /tmp/cvs/mysql-admutils/common.c,v 1.2 2002-02-27 08:49:48 knutpett Exp $
*
* functions used by mysql-dbadm.c and mysql-useradm.c
*
@ -17,11 +17,12 @@
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <grp.h>
#include "mysql-admutils.h"
char *program_name;
static char *rcsheader = "@(#) " PACKAGE " " VERSION " ljosa@initio.no $Header: /tmp/cvs/mysql-admutils/common.c,v 1.1.1.1 2001-11-25 00:41:16 lkarsten Exp $";
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 $";
int
@ -117,6 +118,75 @@ owner(char *name)
return 0; /* not owner if we get as far as this */
}
/**
* Decides if the user is member of a group. The Unix group can't contain any
* '_'. i.e 'fidi_s' won't be accepted.
*/
int
member(char *gr) {
char *username;
char *group;
struct group *g;
struct passwd *p;
char *foo;
/* size_t i = 0; */
/* Get username */
p = getpwuid(getuid());
if (!p) {
fprintf(stderr, "Failed to look up your UNIX username.");
exit(1);
}
username = p->pw_name;
/* Copy string, but cut at '_' */
group = strdup(gr);
if (group == NULL) {
fprintf(stderr, "Couldn't allocate memory. Terminating.");
exit(1);
}
foo = strchr(group, '_');
if (foo) {
#if DEBUG
printf("gr = %s, group = %s, foo = %s\n", gr, group, foo);
#endif
*foo = '\0';
}
/* Get group */
g = getgrnam(group);
if (g == NULL) {
fprintf(stderr, "No such group: %s\n", group);
exit(1);
}
/* Check if user is member of group */
while(*g->gr_mem != NULL) {
char * member = *g->gr_mem;
#if DEBUG
printf("Medlem: %s\n", *g->gr_mem);
#endif
if (strcmp(member,username) == 0) {
#if DEBUG
printf("You have access to '%s'\n", gr);
#endif
return 1; /* OK */
} else
*g->gr_mem++;
}
#if DEBUG
printf("You have no access to '%s'\n", gr);
#endif
return 0;
}
int
reload(MYSQL *pmysql)