Version 0.51

Mer brukervennlige feilmeldinger, samt fikset alle kompilatoradvarsler.
This commit is contained in:
Geir Hauge 2007-02-27 14:10:08 +00:00
parent bcb560b925
commit 21f0f57f99
7 changed files with 578 additions and 700 deletions

View File

@ -230,11 +230,6 @@ pwyacc.h: pwyacc.c
mysql-dbadm$(EXEEXT): $(mysql_dbadm_OBJECTS) $(mysql_dbadm_DEPENDENCIES)
@rm -f mysql-dbadm$(EXEEXT)
$(LINK) $(mysql_dbadm_LDFLAGS) $(mysql_dbadm_OBJECTS) $(mysql_dbadm_LDADD) $(LIBS)
pwyacc.h: pwyacc.c
@if test ! -f $@; then \
rm -f pwyacc.c; \
$(MAKE) pwyacc.c; \
else :; fi
mysql-useradm$(EXEEXT): $(mysql_useradm_OBJECTS) $(mysql_useradm_DEPENDENCIES)
@rm -f mysql-useradm$(EXEEXT)
$(LINK) $(mysql_useradm_LDFLAGS) $(mysql_useradm_OBJECTS) $(mysql_useradm_LDADD) $(LIBS)

View File

@ -1,5 +1,5 @@
/*
* @(#) $Header: /tmp/cvs/mysql-admutils/common.c,v 1.8 2006-08-15 11:51:58 geirha Exp $
* @(#) $Header: /tmp/cvs/mysql-admutils/common.c,v 1.9 2007-02-27 14:10:07 geirha Exp $
*
* functions used by mysql-dbadm.c and mysql-useradm.c
*
@ -7,6 +7,7 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <mysql.h>
#include <assert.h>
@ -22,7 +23,7 @@
char *program_name;
static char *rcsheader = "@(#) " PACKAGE " " VERSION " orakel@ntnu.no $Header: /tmp/cvs/mysql-admutils/common.c,v 1.8 2006-08-15 11:51:58 geirha Exp $";
static char *rcsheader = "@(#) " PACKAGE " " VERSION " orakel@ntnu.no $Header: /tmp/cvs/mysql-admutils/common.c,v 1.9 2007-02-27 14:10:07 geirha Exp $";
int
@ -56,7 +57,7 @@ wrong_use(char *format, ...)
int
dberror(MYSQL *pmysql, char *format, ...)
{
char *errmsg;
const char *errmsg;
va_list ap;
fprintf(stderr, "%s: ", program_name);

View File

@ -1,5 +1,5 @@
/*
* @(#) $Header: /tmp/cvs/mysql-admutils/mysql-dbadm.c,v 1.18 2007-02-27 11:38:07 geirha Exp $
* @(#) $Header: /tmp/cvs/mysql-admutils/mysql-dbadm.c,v 1.19 2007-02-27 14:10:08 geirha Exp $
*
* mysql-dbadm.c
*
@ -513,9 +513,16 @@ main(int argc, char *argv[])
db[32] = '\0';
if (! (owner(db) || member(db))) {
dberror(NULL, "You are not the owner of '%s'. Skipping.",
db);
continue;
if (command == c_create)
dberror(NULL,"Unable to create mysql-database '%s'.\n"
"A mysql-database must start with either '%s_' or "
"'groupname_', where groupname is a unix group you are a "
"member of. Type \"groups\" to see which groups you are a "
"member of.\n",
db, getpwuid(getuid())->pw_name);
else
dberror(NULL, "You are not in charge of mysql-database: '%s'. Skipping.", db);
continue;
}
switch (command) {

View File

@ -1,5 +1,5 @@
/*
* @(#) $Header: /tmp/cvs/mysql-admutils/mysql-useradm.c,v 1.10 2005-06-27 10:13:01 knuta Exp $
* @(#) $Header: /tmp/cvs/mysql-admutils/mysql-useradm.c,v 1.11 2007-02-27 14:10:08 geirha Exp $
*
* mysql-useradm.c
*
@ -52,7 +52,7 @@ is_password_set(MYSQL *pmysql, const char *user)
return -1;
if (rows > 1)
return dberror(NULL, "Query for password for user '%s' gave %d results!",
user, rows);
user, rows);
row = mysql_fetch_row(res);
return (row[0] && (strlen(row[0]) > 0));
}
@ -99,25 +99,25 @@ passwd(MYSQL *pmysql, const char *user)
sprintf(prompt, "(current) MySQL password for user '%s': ", user);
password = getpass(prompt);
sprintf(query, "select password = password('%s') from user "
"where user = '%s'", password, user);
"where user = '%s'", password, user);
if (mysql_query(pmysql, query))
return dberror(pmysql, "Failed to check old password for user '%s'.",
user);
return dberror(pmysql, "Failed to check old password for user '%s'.",
user);
res = mysql_store_result(pmysql);
rows = mysql_num_rows(res);
if (rows == 0)
return dberror(NULL, "Check for old password for user '%s' "
"returned empty.", user);
return dberror(NULL, "Check for old password for user '%s' "
"returned empty.", user);
if (rows > 1)
return dberror(NULL, "Check for old password for user '%s' "
"returned more than one row!", user);
return dberror(NULL, "Check for old password for user '%s' "
"returned more than one row!", user);
row = mysql_fetch_row(res);
if (strcmp(row[0], "1") != 0)
{
fprintf(stderr, "%s: Wrong password entered for user '%s'.\n",
program_name, user);
return 1;
}
{
fprintf(stderr, "%s: Wrong password entered for user '%s'.\n",
program_name, user);
return 1;
}
}
sprintf(prompt, "New MySQL password for user '%s': ", user);
@ -133,12 +133,12 @@ passwd(MYSQL *pmysql, const char *user)
free(confirm_password);
sprintf(query, "update user set password = password('%s') "
"where user = '%s'", password, user);
"where user = '%s'", password, user);
if (mysql_query(pmysql, query))
return dberror(pmysql, "Failed to set new password for user '%s'.", user);
if (mysql_affected_rows(pmysql) > 1)
dberror(NULL, "%d rows affected by password update for user '%s'!",
mysql_affected_rows(pmysql), user);
mysql_affected_rows(pmysql), user);
fprintf(stderr, "Password updated for user '%s'.\n", user);
return 0;
@ -180,7 +180,7 @@ list(MYSQL *pmysql)
p = getpwuid(getuid());
sprintf(query, "select user from user where user='%s' or user like '%s\\_%%'",
p->pw_name, p->pw_name);
p->pw_name, p->pw_name);
// sprintf(query, "select user from user where user='myhr' or user like 'myhr\\_%%'");
numgroups = 0;
@ -212,7 +212,7 @@ list(MYSQL *pmysql)
for (i = 0; i < rows; i++)
if ((row = mysql_fetch_row(res)))
{
userlist[i] = strdup(row[0]);
userlist[i] = strdup(row[0]);
}
userlist[i] = NULL;
@ -270,7 +270,7 @@ main(int argc, char *argv[])
/* connect to the database server and select the mysql database */
if (!mysql_real_connect(&mysql, db_server, db_user, db_passwd, db_name, 0, NULL, 0))
return dberror(&mysql, "Cannot connect to database server '%s'.",
db_server);
db_server);
if (mysql_select_db(&mysql, db_name))
return dberror(&mysql, "Cannot select database '%s'.", db_name);
@ -279,11 +279,11 @@ main(int argc, char *argv[])
dblist = list(&mysql);
p = dblist;
while (*p)
{
show(&mysql, *p);
free(*p);
p++;
}
{
show(&mysql, *p);
free(*p);
p++;
}
free(dblist);
}
else {
@ -293,31 +293,40 @@ main(int argc, char *argv[])
for (i = 2; i < argc; i++) {
strncpy(user, argv[i], 32);
user[33] = '\0';
if (! (owner(user) || member(user)))
{
dberror(NULL, "You are not the owner of '%s'. Skipping.", user);
continue;
}
if (! (owner(user) || member(user)))
{
if (command == c_create)
dberror(NULL,"Unable to create mysql-user '%s'.\n"
switch (command)
{
case c_create:
create(&mysql, user);
break;
case c_delete:
delete(&mysql, user);
break;
case c_passwd:
passwd(&mysql, user);
break;
case c_show:
show(&mysql, user);
break;
default:
fprintf(stderr, "This point should never be reached.\n");
exit(1);
}
}
"A mysql-user must start with either '%s_' or "
"'groupname_', where groupname is a unix group you are a "
"member of. Type \"groups\" to see which groups you are "
"a member of.\n",
user, getpwuid(getuid())->pw_name);
else
dberror(NULL, "You are not in charge of mysql-user: '%s'. Skipping.", user);
continue;
}
switch (command)
{
case c_create:
create(&mysql, user);
break;
case c_delete:
delete(&mysql, user);
break;
case c_passwd:
passwd(&mysql, user);
break;
case c_show:
show(&mysql, user);
break;
default:
fprintf(stderr, "This point should never be reached.\n");
exit(1);
}
}
}
reload(&mysql);

View File

@ -1,11 +1,13 @@
/*
* @($) $Id: pwfile.c,v 1.2 2002-02-27 08:49:48 knutpett Exp $
* @($) $Id: pwfile.c,v 1.3 2007-02-27 14:10:08 geirha Exp $
*
* functions for parsing the config file.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <sys/resource.h>

1077
pwyacc.c

File diff suppressed because it is too large Load Diff

View File

@ -1,58 +1,17 @@
/* A Bison parser, made by GNU Bison 1.875. */
#ifndef BISON_Y_TAB_H
# define BISON_Y_TAB_H
/* Skeleton parser for Yacc-like parsing with Bison,
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software Foundation, Inc.
# ifndef YYSTYPE
# define YYSTYPE int
# define YYSTYPE_IS_TRIVIAL 1
# endif
# define SET 257
# define HOST 258
# define USER 259
# define PASSWORD 260
# define STRING 261
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, when this file is copied by Bison into a
Bison output file, you may use that output file without restriction.
This special exception was added by the Free Software Foundation
in version 1.24 of Bison. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
SET = 258,
HOST = 259,
USER = 260,
PASSWORD = 261,
STRING = 262
};
#endif
#define SET 258
#define HOST 259
#define USER 260
#define PASSWORD 261
#define STRING 262
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
typedef int YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
# define YYSTYPE_IS_TRIVIAL 1
#endif
extern YYSTYPE yylval;
#endif /* not BISON_Y_TAB_H */