-
Notifications
You must be signed in to change notification settings - Fork 0
/
users_test.c
74 lines (71 loc) · 2.27 KB
/
users_test.c
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "users.h"
#include "simplefs_apis.h"
int main(void) {
//we create and load the disk
// we initialize the FS
int res;
DiskDriver *disk = (DiskDriver *) malloc(sizeof(DiskDriver));
SimpleFS *fs = (SimpleFS *) malloc(sizeof(SimpleFS));
char diskname[] = "./disk";
unlink(diskname);
fs->block_num = 20000;
fs->filename = diskname;
fs->disk = disk;
unsigned root = ROOT;
formatDisk(fs, root);
res = loadDisk(fs->disk, fs->filename);
CHECK_ERR(res == FAILED, "can't load the fs");
DirectoryHandle *dh = init(fs, disk, root, root);
//we initialize the wallet
printf("create wallet\n");
Wallet *wallet = initialize_wallet(dh);
CHECK_ERR(wallet == NULL, "failed wallet creation")
//we now add two users
char usr1[] = "user1", usr2[] = "user2", usr3[] = "user3";
printf("add user1\n");
res = useradd(usr1, dh, wallet);
printf("result:%d\n", res);
printf("add user2\n");
res = useradd(usr2, dh, wallet);
printf("result:%d\n", res);
printf("add user1 in user2 group\n");
res = gpasswd(usr2, usr1, wallet, ADD);
printf("result:%d\n", res);
printf("add user2 in user1 group\n");
res = gpasswd(usr1, usr2, wallet, ADD);
printf("result:%d\n", res);
printf("remove user2 in user1 group\n");
res = gpasswd(usr1, usr2, wallet, REMOVE);
printf("result:%d\n", res);
printf("remove user1\n");
res = userdel(usr1, dh, wallet);
printf("result:%d\n", res);
printf("remove user2\n");
res = userdel(usr2, dh, wallet);
printf("result:%d\n", res);
destroy_wallet(wallet);
printf("now we destroy and reload the wallet and perform the same operations\n");
wallet = initialize_wallet(dh);
printf("add user1\n");
res = useradd(usr1, dh, wallet);
printf("result:%d\n", res);
printf("add user3\n");
res = useradd(usr3, dh, wallet);
printf("result:%d\n", res);
printf("add user1 in user3 group\n");
res = gpasswd(usr3, usr1, wallet, ADD);
printf("result:%d\n", res);
printf("add user3 in user1 group\n");
res = gpasswd(usr1, usr3, wallet, ADD);
printf("result:%d\n", res);
printf("remove user3 in user1 group\n");
res = gpasswd(usr1, usr3, wallet, REMOVE);
printf("result:%d\n", res);
printf("remove user1\n");
res = userdel(usr1, dh, wallet);
printf("result:%d\n", res);
printf("remove user3\n");
res = userdel(usr3, dh, wallet);
printf("result:%d\n", res);
destroy_wallet(wallet);
}