]>
jfr.im git - irc/quakenet/newserv.git/blob - fsck/fsck.c
1 /* fsck.c - check some internal structures */
3 #include "../control/control.h"
4 #include "../nick/nick.h"
5 #include "../channel/channel.h"
6 #include "../server/server.h"
8 int dofsck(void *source
, int cargc
, char **cargv
);
11 registercontrolhelpcmd("fsck",NO_DEVELOPER
,0,dofsck
, "Usage: fsck\nRuns internal structure check.");
15 deregistercontrolcmd("fsck",dofsck
);
18 int dofsck(void *source
, int cargc
, char **cargv
) {
20 nick
*sender
=source
, *np
, *np2
;
23 unsigned int nickmarker
;
25 unsigned int nummask
,mnum
;
27 /* Start off with strict nick consistency checks.. */
29 controlreply(sender
,"- Performing nickname checks");
31 nickmarker
=nextnickmarker();
33 for(i
=0;i
<HOSTHASHSIZE
;i
++)
34 for(hp
=hosttable
[i
];hp
;hp
=hp
->next
)
37 for(i
=0;i
<REALNAMEHASHSIZE
;i
++)
38 for(rnp
=realnametable
[i
];rnp
;rnp
=rnp
->next
)
41 controlreply(sender
," - Scanning nick hash table");
43 for (i
=0;i
<NICKHASHSIZE
;i
++) {
44 for(np
=nicktable
[i
];np
;np
=np
->next
) {
45 if (np
->marker
==nickmarker
) {
46 controlreply(sender
, "ERROR: bumped into the same nick %s/%s twice in hash table.",longtonumeric(np
->numeric
,5),np
->nick
);
50 /* Mark this nick so we can check we found them all */
51 np
->marker
=nickmarker
;
53 /* Check that we can find this nick with the lookup functions */
54 if (getnickbynick(np
->nick
) != np
) {
55 controlreply(sender
, "ERROR: can't find %s/%s using getnickbynick().",
56 longtonumeric(np
->numeric
,5),np
->nick
);
60 if (getnickbynumeric(np
->numeric
) != np
) {
61 controlreply(sender
, "ERROR: can't find %s/%s using getnickbynumeric().",
62 longtonumeric(np
->numeric
,5),np
->nick
);
66 /* Check that the nick appears in the list of nicks using its host */
67 if (findhost(np
->host
->name
->content
) != np
->host
) {
68 controlreply(sender
, "ERROR: can't find %s/%s's host (%s) using findhost().",
69 longtonumeric(np
->numeric
,5),np
->nick
,np
->host
->name
->content
);
73 for(np2
=np
->host
->nicks
;np2
;np2
=np2
->nextbyhost
)
78 controlreply(sender
, "ERROR: can't find %s/%s (host=%s) on the host users list.",
79 longtonumeric(np
->numeric
,5),np
->nick
,np
->host
->name
->content
);
85 /* Same for realnames */
86 if (findrealname(np
->realname
->name
->content
) != np
->realname
) {
87 controlreply(sender
, "ERROR: can't find %s/%s's realname (%s) using findrealname().",
88 longtonumeric(np
->numeric
,5),np
->nick
,np
->realname
->name
->content
);
92 for(np2
=np
->realname
->nicks
;np2
;np2
=np2
->nextbyrealname
)
98 "ERROR: can't find %s/%s (realname=%s) on the realname users list.",
99 longtonumeric(np
->numeric
,5),np
->nick
,np
->realname
->name
->content
);
103 np
->realname
->marker
++;
105 if (IsAccount(np
) && !np
->authname
[0]) {
106 controlreply(sender
, "ERROR: nick %s/%s is +r but no authname stored.",
107 longtonumeric(np
->numeric
,5),np
->nick
);
112 if (!IsAccount(np) && np->authname[0]) {
113 controlreply(sender, "ERROR: nick %s/%s is -r but carries authname '%s'.",
114 longtonumeric(np->numeric,5),np->nick,np->authname);
119 if (IsSetHost(np
) && (!np
->sethost
|| !np
->shident
)) {
120 controlreply(sender
, "ERROR: nick %s/%s is +h but nick or hostname not set.",
121 longtonumeric(np
->numeric
,5),np
->nick
);
125 if (!IsSetHost(np
) && (np
->sethost
|| np
->shident
)) {
126 controlreply(sender
, "ERROR: nick %s/%s is -h but has nick or hostname set.",
127 longtonumeric(np
->numeric
,5),np
->nick
);
134 controlreply(sender
," - Scanning server user tables");
136 for(i
=0;i
<MAXSERVERS
;i
++) {
137 if (serverlist
[i
].linkstate
!= LS_INVALID
) {
138 nummask
=((MAXSERVERS
-1)<<18) | serverlist
[i
].maxusernum
;
139 for (j
=0;j
<=serverlist
[i
].maxusernum
;j
++) {
140 if ((np
=servernicks
[i
][j
])) {
142 if ((np
->numeric
& nummask
) != mnum
) {
143 controlreply(sender
, "ERROR: nick %s/%s has wrong masked numeric.",longtonumeric(np
->numeric
,5),np
->nick
);
146 if (np
->marker
!= nickmarker
) {
147 controlreply(sender
, "ERROR: nick %s/%s in server user table but not hash!",
148 longtonumeric(np
->numeric
,5),np
->nick
);
157 controlreply(sender
," - Scanning host and realname tables");
159 for (i
=0;i
<HOSTHASHSIZE
;i
++) {
160 for (hp
=hosttable
[i
];hp
;hp
=hp
->next
) {
162 /* Check that the user counts match up */
163 if (hp
->clonecount
!= hp
->marker
) {
165 "ERROR: host %s has inconsistent clone count (stored=%d, measured=%u)",
166 hp
->name
->content
,hp
->clonecount
,hp
->marker
);
170 for (np
=hp
->nicks
;np
;np
=np
->nextbyhost
) {
171 if (np
->host
!= hp
) {
173 "ERROR: nick %s/%s is in list for wrong host "
174 "(in list for %s, actual host %s).",
175 longtonumeric(np
->numeric
,5),np
->nick
,hp
->name
->content
,
176 np
->host
->name
->content
);
185 for (i
=0;i
<REALNAMEHASHSIZE
;i
++) {
186 for (rnp
=realnametable
[i
];rnp
;rnp
=rnp
->next
) {
187 if (rnp
->usercount
!= rnp
->marker
) {
189 "ERROR: realname '%s' has inconsistent clone count "
190 "(stored=%d, measured=%d).",
191 rnp
->name
->content
,rnp
->usercount
,rnp
->marker
);
195 for (np
=rnp
->nicks
;np
;np
=np
->nextbyrealname
) {
196 if (np
->realname
!= rnp
) {
198 "ERROR: nick %s/%s is in list for wrong realname "
199 "(in list for '%s', actual realname '%s').",
200 longtonumeric(np
->numeric
,5),np
->nick
,
201 rnp
->name
->content
, np
->realname
->name
->content
);
211 controlreply(sender
,"All checks complete. %d errors found.",errors
);
213 controlreply(sender
,"All checks complete. No errors found.");