Commit a1a6a7a3 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Use GNU getopt in dbck.

(longopts): New variable.
(main): Rewrote the option-parsing loop to use GNU getopt.
Help in dbck.
(give_help): New function.
(main): Call it if -h (or --help) is given.
Reset passwords in dbck.
(reset_pwd): New variable.
(main): Set it if -P (or --clear-password) is given.
(check_persons): Reset the password if the person number equals	reset_pwd.
Grant permission in dbck.
(grant_all): New variable.
(main): Set it if -G (or --grant-all) is given.
(check_persons): Give the person all privileges if the person number
	equals grant_all.
parent 1f4b636c
/*
* $Id: dbck.c,v 0.29 1996/02/23 16:00:20 byers Exp $
* $Id: dbck.c,v 0.30 1996/02/25 20:46:58 ceder Exp $
* Copyright (C) 1991, 1992, 1993, 1994, 1995 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -28,7 +28,7 @@
* Author: Per Cederqvist.
*/
static char *rcsid = "$Id: dbck.c,v 0.29 1996/02/23 16:00:20 byers Exp $";
static char *rcsid = "$Id: dbck.c,v 0.30 1996/02/25 20:46:58 ceder Exp $";
#include "rcs.h"
USE(rcsid);
......@@ -42,6 +42,7 @@ USE(rcsid);
#include <time.h>
#include <sys/types.h>
#include "getopt.h"
#include "misc-types.h"
#include "s-string.h"
#include "kom-types.h"
......@@ -57,6 +58,25 @@ USE(rcsid);
#include "param.h"
#include "server-config.h"
#include "manipulate.h"
#include "version-info.h"
static struct option longopts[] = {
{"compact-text-mass", 0, 0, 'g' },
{"interactive", 0, 0, 'i' },
{"auto-repair", 0, 0, 'r' },
{"verbose", 0, 0, 'v' },
{"print-statistics", 0, 0, 's' },
{"list-text-no", 0, 0, 't' },
{"set-change-name", 0, 0, 'c' },
{"clear-password", required_argument, 0, 'P' },
{"grant-all", required_argument, 0, 'G' },
{"output-version", required_argument, 0, 'o' },
{"force-output", 0, 0, 'F' },
{"help", 0, 0, 'h' },
{ 0, 0, 0, 0 }
};
Info kom_info; /* Not used, but needed by server-config.o. */
struct kom_par param;
......@@ -70,6 +90,8 @@ int iflag=0; /* Interactive - prompt user and repair. */
int rflag=0; /* Repair simple error without confirmation. */
int gflag=0; /* Garbage collect text-file. */
int sflag=0; /* Statistic flag. */
static Pers_no reset_pwd=0; /* Person whose password should be cleared. */
static Pers_no grant_all=0; /* Person which should receive all bits. */
/* The following variable holds the output format */
......@@ -385,7 +407,8 @@ check_misc_infos(Text_no tno,
c = cached_get_conf_stat (group.recipient);
if ( c == NULL && group.recipient == 0 )
{
log ("Conference 0 is recipient to text %lu.\n", (unsigned long)tno);
log ("Conference 0 is recipient to text %lu.\n",
(unsigned long)tno);
if (rflag || confirm("Repair by deleting misc_item? "))
{
delete_misc(tstat, previous);
......@@ -804,7 +827,8 @@ check_membership(Pers_no pno,
log("Person %lu's membership in %lu %s %lu<%lu> <= %lu.\n",
(unsigned long)pno, (unsigned long)mship->conf_no,
"is corrupt: read text number",
(unsigned long)mship->read_texts[i], (unsigned long)i, (unsigned long)last);
(unsigned long)mship->read_texts[i], (unsigned long)i,
(unsigned long)last);
error++;
}
......@@ -842,6 +866,8 @@ check_membership_list(Pers_no pno,
static int
check_persons(void)
{
static char crypt_seed[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
Pers_no cp = 0;
Person *pstat=NULL;
Conference *cstat=NULL;
......@@ -881,6 +907,7 @@ check_persons(void)
{
log("Person %lu has no change_name capability.\n",
(unsigned long)cp);
if (rflag || confirm("Grant him the capability"))
{
pstat->privileges.change_name = 1;
......@@ -890,6 +917,40 @@ check_persons(void)
else
errors++;
}
if (cp == reset_pwd)
{
char salt[3];
salt[0] = crypt_seed [rand() % (sizeof (crypt_seed) - 1)];
salt[1] = crypt_seed [rand() % (sizeof (crypt_seed) - 1)];
salt[2] = '\0';
strcpy((char *)pstat->pwd, (const char *)crypt("", salt));
mark_person_as_changed(cp);
modifications++;
}
if (cp == grant_all)
{
pstat->privileges.wheel = 1;
pstat->privileges.admin = 1;
pstat->privileges.statistic = 1;
pstat->privileges.create_pers = 1;
pstat->privileges.create_conf = 1;
pstat->privileges.change_name = 1;
pstat->privileges.extern_gw = 1;
pstat->privileges.flg8 = 1;
pstat->privileges.flg9 = 1;
pstat->privileges.flg10 = 1;
pstat->privileges.flg11 = 1;
pstat->privileges.flg12 = 1;
pstat->privileges.flg13 = 1;
pstat->privileges.flg14 = 1;
pstat->privileges.flg15 = 1;
pstat->privileges.flg16 = 1;
mark_person_as_changed(cp);
modifications++;
}
}
if (vflag)
......@@ -1144,10 +1205,10 @@ post_check_persons(void)
Pers_no pers_no = 0;
Person *pstat;
while ( (pers_no = traverse_person(pers_no)) != 0 )
while ((pers_no = traverse_person(pers_no)) != 0)
{
if ( (pstat = cached_get_person_stat(pers_no)) == NULL )
if ((pstat = cached_get_person_stat(pers_no)) == NULL)
{
log("%s(): can't cached_get_person_stat(%d).\n",
"INTERNAL DBCK ERROR: post_check_persons", pers_no);
......@@ -1248,6 +1309,39 @@ print_statistics(void)
log("%8d %d\n", i, hist[i]);
}
static void
give_help(const char *default_config)
{
printf("dbck for %s version %s\n",
kom_version_info.server_name,
kom_version_info.server_version);
puts("Usage: dbck [options] [config_file]");
puts("Available options:");
puts("Short Long option Explanation");
puts(" -g --compact-text-mass Reclaim unused space among texts.");
puts(" -i --interactive Offer to repair some error types.");
puts(" -r --auto-repair "
"Repair simple errors without prompting.");
puts(" -v --verbose Talk more.");
puts(" -o --output-version=N File format 0 or 1.");
puts(" -F --force-output Save db even if no changes.");
puts(" -s --print-statistics Output a lot of statistics.");
puts(" -t --list-text-no "
"List the text number of all existing texts.");
puts(" -c --set-change-name "
"Consider unset change_name capabilities an error.");
puts(" -P --clear-password=pno "
"Set password to empty string for a user.");
puts(" -G --grant-all=pno Give a user all available privileges.");
puts(" -h --help Display this help.");
puts("Note: the -P and -G options "
"also require a person number as argument");
printf("The config_file argument defaults to %s\n", default_config);
puts("WARNING: Don't allow lyskomd "
"and dbck to modify the database simultaneously!");
exit(0);
}
/* Stop "no previous prototype" warning from gcc 2.0 */
int main(int, char**);
......@@ -1255,15 +1349,17 @@ int
main (int argc,
char **argv)
{
int i;
int hflag = 0;
int errors;
char *default_config_file;
char *config_file;
char optc;
BUGDECL;
for (i = 1; i < argc && argv[i][0] == '-'; i++)
while ((optc = getopt_long(argc, argv, "girvstdcP:G:Fo:",
longopts, (int *) 0)) != EOF)
{
switch (argv[i][1])
switch (optc)
{
#ifndef NDEBUG
case 'd':
......@@ -1287,6 +1383,10 @@ main (int argc,
gflag++;
break;
case 'h': /* Help: give usage message. */
hflag++;
break;
case 's': /* Statistics: text length et c. */
sflag++;
break;
......@@ -1295,49 +1395,61 @@ main (int argc,
unset_change_name_is_error = 1;
break;
case 't':
dump_text_numbers++;
break;
case 'P':
reset_pwd = atol(optarg);
log("Will reset password of person %ld", (long)reset_pwd);
#ifdef ENCRYPT_PASSWORDS
/* Seed the random number generator. */
srand(time(NULL) + getpid());
#endif
break;
case 'G':
grant_all = atol(optarg);
log("Will grant all bits to person %ld", (long)grant_all);
case 'F':
force_output = 1;
break;
case 'o': /* Select output format */
if (argv[i+1] != 0 && argv[i+1][0] != '-')
{
oformat = atoi(argv[i+1]);
i += 1;
}
else
restart_kom("usage: %s %s [config_file]\n",
argv[0],
"[-d ...] [-i] [-r] [-v] [-g] [-s] [-c] [-t] [-F] [-o ...]");
oformat = atoi(optarg);
if (oformat == 0 && *optarg != '0')
restart_kom("%s: bad output format %s", argv[0], optarg);
break;
case 't':
dump_text_numbers++;
break;
default:
restart_kom("usage: %s %s [config_file]\n",
argv[0],
"[-d ...] [-i] [-r] [-v] [-g] [-s] [-c] [-t] [-F] [-o ...]");
restart_kom("Try --help for usage message.\n");
}
}
/* Read in the configuration file. */
/* Start reading in the configuration file. */
default_config_file = smalloc(strlen(DEFAULT_DBASE_DIR) +
strlen(CONFIG_FILE) + 2);
sprintf(default_config_file, "%s/%s", DEFAULT_DBASE_DIR, CONFIG_FILE);
if (i < argc)
config_file = argv[i++];
/* Check if help was requested. */
if (hflag > 0)
give_help(default_config_file);
/* Continue reading in the configuration file. */
if (optind < argc)
config_file = argv[optind++];
else
config_file = default_config_file;
read_configuration(config_file);
sfree(default_config_file);
if (i != argc)
restart_kom("usage: %s %s [config_file]\n",
argv[0], "[-d ...] [-i] [-r] [-v] [-g] [-s] [-c] [-t]");
if (optind != argc)
restart_kom("%s: too many arguments. %s --help for usage.\n",
argv[0], argv[0]);
s_set_storage_management(smalloc, srealloc, sfree);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment