summaryrefslogtreecommitdiffstats
path: root/util/splitpasswd.c
blob: 1a800f6c14fb1c1e328ca78bcb3534af4956be3f (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
#include "bbs.h"
#include <err.h>

int main(int argc, char **argv)
{
    userec_t xuser;
    int     fd, ufd;
    char    path[80], fn[80];

    chdir(BBSHOME);
    if( (fd = open(".PASSWDS", O_RDONLY)) < 0 )
    err(1, ".PASSWDS");

    while( read(fd, &xuser, sizeof(xuser)) > 0 ){
    if( strcmp(xuser.userid, "in2") != 0 )
        continue;
    sprintf(path, "home/%c/%s", xuser.userid[0], xuser.userid);
    if( access(path, 0) < 0 ){
        printf("user home error (%s) (%s)\n", xuser.userid, path);
        continue;
    }
    sprintf(fn, "%s/.passwd", path);
    if( (ufd = open(fn, O_WRONLY | O_CREAT, 0600)) < 0 ){
        perror(path);
        continue;
    }
    write(ufd, &xuser, sizeof(xuser));
    close(ufd);
    }
    
    return 0;
}