~ubuntu-branches/debian/lenny/ggz-server/lenny

« back to all changes in this revision

Viewing changes to ggzd/ggzduedit.c

  • Committer: Bazaar Package Importer
  • Author(s): Neil Williams
  • Date: 2008-08-30 22:28:31 UTC
  • mfrom: (3.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080830222831-lt2l462usl5opxfd
Tags: 0.0.14.1-1.2
* Non-maintainer upload.
* Improve the database.m4 fix to migrate to libdb4.6
  instead of 4.4 {request from Steve Langasek.}

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 * Project: GGZ Server
5
5
 * Date: 09/24/01
6
6
 * Desc: User database editor for ggzd server
7
 
 * $Id: ggzduedit.c 7714 2006-01-02 16:53:31Z josef $
 
7
 * $Id: ggzduedit.c 9205 2007-07-23 07:33:15Z josef $
8
8
 *
9
9
 * Copyright (C) 2001 Brent Hendricks.
10
10
 *
38
38
 
39
39
#include "ggzdb.h"
40
40
#include "ggzdb_proto.h"
41
 
#define PERMS_DEFINE_STR_TABLE
 
41
#include "datatypes.h" /* For Options type */
42
42
#include "perms.h"
43
43
 
44
44
 
 
45
/* Server options */
 
46
/* This is required by the database functions
 
47
 * but isn't actually used here */
 
48
Options opt;
 
49
 
45
50
char lb[1024];
46
51
ggzdbPlayerEntry pe;
47
52
 
100
105
 
101
106
static void show_all_perms(void)
102
107
{
103
 
        int i;
 
108
        GGZPerm p;
104
109
 
105
110
        printf("Available permissions:\n");
106
 
        for(i=0; i<8; i++) {
107
 
                printf(" [%s] (bit %i)\n", perms_str_table[i], i);
 
111
        for (p = 0; p < GGZ_PERM_COUNT; p++) {
 
112
                printf(" [%32s] (bit %i)\n", ggz_perm_to_string(p), p);
108
113
        }
109
114
}
110
115
 
111
116
 
112
 
static void show_perms(unsigned int perms, int add_spaces)
 
117
static void show_perms(GGZPermset perms, int add_spaces)
113
118
{
114
 
        int i;
115
 
        unsigned int testbit=1;
116
119
        int first=1;
117
120
        int col=1;
118
 
 
119
 
        for(i=0; i<32; i++) {
120
 
                if((perms & testbit) == testbit) {
 
121
        GGZPerm p;
 
122
 
 
123
        for (p = 0; p < GGZ_PERM_COUNT; p++) {
 
124
                if (ggz_perms_is_set(perms, p)) {
 
125
                        const char *name = ggz_perm_to_string(p);
 
126
 
121
127
                        if(first) {
122
 
                                printf("%s", perms_str_table[i]);
 
128
                                printf("%24s", name);
123
129
                                first = 0;
124
130
                        } else if(col) {
125
 
                                printf("      %s\n", perms_str_table[i]);
 
131
                                printf("        %24s\n", name);
126
132
                                col = 0;
127
133
                        } else {
128
134
                                if(add_spaces)
129
135
                                        printf("%*c", add_spaces, ' ');
130
 
                                printf("               %s", perms_str_table[i]);
 
136
                                printf("               %24s", name);
131
137
                                col = 1;
132
138
                        }
133
139
                }
134
 
                testbit <<= 1;
135
140
        }
136
141
 
137
142
        if(first)
140
145
                printf("\n");
141
146
 
142
147
        printf("               -> roles: ");
143
 
        if((perms & PERMS_ADMIN_MASK) == PERMS_ADMIN_MASK)
 
148
        if (ggz_perms_is_admin(perms))
144
149
                printf("[admin]");
145
 
        if((perms & PERMS_DEFAULT_SETTINGS) == PERMS_DEFAULT_SETTINGS)
 
150
        if (ggz_perms_is_host(perms))
 
151
                printf("[host]");
 
152
        if (ggz_perms_is_set(perms, GGZ_PERM_ROOMS_LOGIN))
146
153
                printf("[registered]");
147
 
        if((perms & PERMS_DEFAULT_ANON) == PERMS_DEFAULT_ANON)
 
154
        if (ggz_perms_is_set(perms, GGZ_PERM_NO_STATS))
148
155
                printf("[guest]");
149
 
        if(perms & PERMS_CHAT_BOT)
 
156
        if (ggz_perms_is_set(perms, GGZ_PERM_CHAT_BOT))
150
157
                printf("[chatbot]");
151
158
        printf("\n");
152
159
}
420
427
                {"dbname", required_argument, 0, 'D'},
421
428
                {"username", required_argument, 0, 'u'},
422
429
                {"password", optional_argument, 0, 'p'},
 
430
                {"type", optional_argument, 0, 't'},
423
431
                {"help", no_argument, 0, 'h'},
424
432
                {"version", no_argument, 0, 'v'},
425
433
                {0, 0, 0, 0}
426
434
        };
427
435
 
 
436
        conn.type = NULL;
428
437
        conn.datadir = NULL;
429
438
        conn.database = NULL;
430
439
        conn.host = NULL;
434
443
 
435
444
        while(1)
436
445
        {
437
 
                opt = getopt_long(argc, argv, "vhd:H:D:u:p::", options, &optindex);
 
446
                opt = getopt_long(argc, argv, "vhd:H:D:u:t:p::", options, &optindex);
438
447
                if(opt == -1) break;
439
448
                switch(opt)
440
449
                {
450
459
                        case 'u':
451
460
                                conn.username = optarg;
452
461
                                break;
 
462
                        case 't':
 
463
                                conn.type = optarg;
 
464
                                break;
453
465
                        case 'p':
454
466
                                if(!optarg)
455
467
                                {
459
471
                                        fgets(password, sizeof(password), stdin);
460
472
                                        echomode(1);
461
473
                                        printf("\n");
 
474
                                        password[strlen(password) - 1] = '\0';
462
475
                                        optarg = password;
463
476
                                }
464
477
                                conn.password = optarg;
474
487
                                printf("[-H | --host     <hostname>] Host of the database\n");
475
488
                                printf("[-u | --username <username>] Database user\n");
476
489
                                printf("[-p | --password=[password]] Database password\n");
 
490
                                printf("[-t | --type     <dbtype>  ] Type of database (for DBI only)\n");
477
491
                                printf("[-h | --help               ] Display this help\n");
478
492
                                printf("[-v | --version            ] Display version number only\n");
479
493
                                exit(0);
494
508
                        conn.username = ggz_conf_read_string(rc, "General", "DatabaseUsername", NULL);
495
509
                if(!conn.password)
496
510
                        conn.password = ggz_conf_read_string(rc, "General", "DatabasePassword", NULL);
 
511
                if(!conn.type)
 
512
                        conn.type = ggz_conf_read_string(rc, "General", "DatabaseType", NULL);
497
513
                ggz_conf_close(rc);
498
514
        }
499
515
 
500
516
        if(!conn.datadir) {
501
517
                if(!conn.database) {
502
 
                        conn.datadir = DATADIR;
 
518
                        conn.datadir = GGZDSTATEDIR;
503
519
                }
504
520
        }
505
521
 
513
529
                }
514
530
        }
515
531
 
 
532
        if(!strcmp(DATABASE_TYPE, "dbi")) {
 
533
                if(!conn.type) {
 
534
                        fprintf(stderr, "Database type '%s' needs plugin type name\n",
 
535
                                DATABASE_TYPE);
 
536
                        exit(-1);
 
537
                }
 
538
        }
 
539
 
516
540
        if((!strcmp(DATABASE_TYPE, "mysql"))
517
541
        || (!strcmp(DATABASE_TYPE, "pgsql"))
518
 
        || (!strcmp(DATABASE_TYPE, "sqlite"))) {
 
542
        || (!strcmp(DATABASE_TYPE, "sqlite"))
 
543
        || (!strcmp(DATABASE_TYPE, "dbi"))) {
519
544
                if((!conn.database) || (!conn.host) || (!conn.username) || (!conn.password)) {
520
545
                        fprintf(stderr, "Database type '%s' needs database access parameters\n",
521
546
                                DATABASE_TYPE);