summaryrefslogtreecommitdiffstats
path: root/util/indexuser.c
blob: e09751301bef59bacbcd28780ac16c7ab1d3d45f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* $Id: indexuser.c,v 1.6 2003/07/20 00:55:34 in2 Exp $ */
#define _UTIL_C_
#include "bbs.h"
#define INDEXPATH BBSHOME"/index"

unsigned string_hash(unsigned char *s)
{
    unsigned int v = 0;
    while (*s)
    {
        v = (v << 8) | (v >> 24);
        v ^= toupper(*s++);     /* note this is case insensitive */
    }
    return (v * 2654435769UL) >> (32 - HASH_BITS);
}
                                        

int main(int argc, char **argv)
{
    int j;
    userec_t u;
    char buf[256];

    attach_SHM();
    if(passwd_mmap())
    {
    printf("Sorry, the data is not ready.\n");
    exit(0);
    }
    system("rm -rf "INDEXPATH"/realname");
    system("rm -rf "INDEXPATH"/email");
    system("rm -rf "INDEXPATH"/ident");
    mkdir(INDEXPATH"/realname",0700);
    mkdir(INDEXPATH"/email",0700);
    mkdir(INDEXPATH"/ident",0700);
    for(j = 1; j <= MAX_USERS; j++) {
    passwd_query(j, &u);
        if(!u.userid[0]) continue;
        if(u.realname[0])
         {
          sprintf(buf,INDEXPATH"/realname/%X",string_hash(u.realname));
          append_record(buf, (fileheader_t*)&j, sizeof(j));
         }
        if(u.email[0])
         {
          sprintf(buf,INDEXPATH"/email/%X",string_hash(u.email));
          append_record(buf, (fileheader_t*)&j, sizeof(j));
         }
        if(u.ident[0])
         {
          sprintf(buf,INDEXPATH"/ident/%X",string_hash(u.ident));
          append_record(buf, (fileheader_t*)&j, sizeof(j));
         }
    }
    return 0;
}