userchan.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  1. /*
  2. * userchan.c -- part of channels.mod
  3. *
  4. */
  5. #ifdef S_DCCPASS
  6. extern struct cmd_pass *cmdpass;
  7. #endif
  8. struct chanuserrec *get_chanrec(struct userrec *u, char *chname)
  9. {
  10. struct chanuserrec *ch;
  11. for (ch = u->chanrec; ch; ch = ch->next)
  12. if (!rfc_casecmp(ch->channel, chname))
  13. return ch;
  14. return NULL;
  15. }
  16. static struct chanuserrec *add_chanrec(struct userrec *u, char *chname)
  17. {
  18. struct chanuserrec *ch = NULL;
  19. if (findchan_by_dname(chname)) {
  20. ch = user_malloc(sizeof(struct chanuserrec));
  21. ch->next = u->chanrec;
  22. u->chanrec = ch;
  23. ch->info = NULL;
  24. ch->flags = 0;
  25. ch->flags_udef = 0;
  26. ch->laston = 0;
  27. strncpy(ch->channel, chname, 81);
  28. ch->channel[80] = 0;
  29. if (!noshare && !(u->flags & USER_UNSHARED))
  30. shareout(findchan_by_dname(chname), "+cr %s %s\n", u->handle, chname);
  31. }
  32. return ch;
  33. }
  34. static void add_chanrec_by_handle(struct userrec *bu, char *hand, char *chname)
  35. {
  36. struct userrec *u;
  37. u = get_user_by_handle(bu, hand);
  38. if (!u)
  39. return;
  40. if (!get_chanrec(u, chname))
  41. add_chanrec(u, chname);
  42. }
  43. static void get_handle_chaninfo(char *handle, char *chname, char *s)
  44. {
  45. struct userrec *u;
  46. struct chanuserrec *ch;
  47. u = get_user_by_handle(userlist, handle);
  48. if (u == NULL) {
  49. s[0] = 0;
  50. return;
  51. }
  52. ch = get_chanrec(u, chname);
  53. if (ch == NULL) {
  54. s[0] = 0;
  55. return;
  56. }
  57. if (ch->info == NULL) {
  58. s[0] = 0;
  59. return;
  60. }
  61. strcpy(s, ch->info);
  62. return;
  63. }
  64. static void set_handle_chaninfo(struct userrec *bu, char *handle,
  65. char *chname, char *info)
  66. {
  67. struct userrec *u;
  68. struct chanuserrec *ch;
  69. struct chanset_t *cst;
  70. u = get_user_by_handle(bu, handle);
  71. if (!u)
  72. return;
  73. ch = get_chanrec(u, chname);
  74. if (!ch) {
  75. add_chanrec_by_handle(bu, handle, chname);
  76. ch = get_chanrec(u, chname);
  77. }
  78. if (info) {
  79. if (strlen(info) > 80)
  80. info[80] = 0;
  81. }
  82. if (ch->info != NULL)
  83. nfree(ch->info);
  84. if (info && info[0]) {
  85. ch->info = (char *) user_malloc(strlen(info) + 1);
  86. strcpy(ch->info, info);
  87. } else
  88. ch->info = NULL;
  89. cst = findchan_by_dname(chname);
  90. if ((!noshare) && (bu == userlist) &&
  91. !(u->flags & (USER_UNSHARED | USER_BOT)) && share_greet) {
  92. shareout(cst, "chchinfo %s %s %s\n", handle, chname, info ? info : "");
  93. }
  94. }
  95. static void del_chanrec(struct userrec *u, char *chname)
  96. {
  97. struct chanuserrec *ch = u->chanrec, *lst = NULL;
  98. while (ch) {
  99. if (!rfc_casecmp(chname, ch->channel)) {
  100. if (lst == NULL)
  101. u->chanrec = ch->next;
  102. else
  103. lst->next = ch->next;
  104. if (ch->info != NULL)
  105. nfree(ch->info);
  106. nfree(ch);
  107. if (!noshare && !(u->flags & USER_UNSHARED))
  108. shareout(findchan_by_dname(chname), "-cr %s %s\n", u->handle, chname);
  109. return;
  110. }
  111. lst = ch;
  112. ch = ch->next;
  113. }
  114. }
  115. static void set_handle_laston(char *chan, struct userrec *u, time_t n)
  116. {
  117. struct chanuserrec *ch;
  118. if (!u)
  119. return;
  120. touch_laston(u, chan, n);
  121. ch = get_chanrec(u, chan);
  122. if (!ch)
  123. return;
  124. ch->laston = n;
  125. }
  126. /* Is this mask sticky?
  127. */
  128. static int u_sticky_mask(maskrec *u, char *uhost)
  129. {
  130. for (; u; u = u->next)
  131. if (!rfc_casecmp(u->mask, uhost))
  132. return (u->flags & MASKREC_STICKY);
  133. return 0;
  134. }
  135. /* Set sticky attribute for a mask.
  136. */
  137. static int u_setsticky_mask(struct chanset_t *chan, maskrec *u, char *uhost,
  138. int sticky, char *botcmd)
  139. {
  140. int j;
  141. j = atoi(uhost);
  142. if (!j)
  143. j = (-1);
  144. while(u) {
  145. if (j >= 0)
  146. j--;
  147. if (!j || ((j < 0) && !rfc_casecmp(u->mask, uhost))) {
  148. if (sticky > 0)
  149. u->flags |= MASKREC_STICKY;
  150. else if (!sticky)
  151. u->flags &= ~MASKREC_STICKY;
  152. else /* We don't actually want to change, just skip over */
  153. return 0;
  154. if (!j)
  155. strcpy(uhost, u->mask);
  156. if (!noshare)
  157. shareout(chan, "%s %s %d %s\n", botcmd, uhost, sticky,
  158. (chan) ? chan->dname : "");
  159. return 1;
  160. }
  161. u = u->next;
  162. }
  163. if (j >= 0)
  164. return -j;
  165. return 0;
  166. }
  167. /* Merge of u_equals_ban(), u_equals_exempt() and u_equals_invite().
  168. *
  169. * Returns:
  170. * 0 not a ban
  171. * 1 temporary ban
  172. * 2 perm ban
  173. */
  174. static int u_equals_mask(maskrec *u, char *mask)
  175. {
  176. for (; u; u = u->next)
  177. if (!rfc_casecmp(u->mask, mask)) {
  178. if (u->flags & MASKREC_PERM)
  179. return 2;
  180. else
  181. return 1;
  182. }
  183. return 0;
  184. }
  185. static int u_match_mask(maskrec *rec, char *mask)
  186. {
  187. for (; rec; rec = rec->next)
  188. if (wild_match(rec->mask, mask))
  189. return 1;
  190. return 0;
  191. }
  192. static int u_delban(struct chanset_t *c, char *who, int doit)
  193. {
  194. int j, i = 0;
  195. maskrec *t;
  196. maskrec **u = (c) ? &c->bans : &global_bans;
  197. char temp[256];
  198. if (!strchr(who, '!') && (j = atoi(who))) {
  199. j--;
  200. for (; (*u) && j; u = &((*u)->next), j--);
  201. if (*u) {
  202. strncpyz(temp, (*u)->mask, sizeof temp);
  203. i = 1;
  204. } else
  205. return -j - 1;
  206. } else {
  207. /* Find matching host, if there is one */
  208. for (; *u && !i; u = &((*u)->next))
  209. if (!rfc_casecmp((*u)->mask, who)) {
  210. strncpyz(temp, who, sizeof temp);
  211. i = 1;
  212. break;
  213. }
  214. if (!*u)
  215. return 0;
  216. }
  217. if (i && doit) {
  218. if (!noshare) {
  219. char *mask = str_escape(temp, ':', '\\');
  220. if (mask) {
  221. /* Distribute chan bans differently */
  222. if (c)
  223. shareout(c, "-bc %s %s\n", c->dname, mask);
  224. else
  225. shareout(NULL, "-b %s\n", mask);
  226. nfree(mask);
  227. }
  228. }
  229. if (lastdeletedmask)
  230. nfree(lastdeletedmask);
  231. lastdeletedmask = nmalloc(strlen((*u)->mask) + 1);
  232. strcpy(lastdeletedmask, (*u)->mask);
  233. nfree((*u)->mask);
  234. if ((*u)->desc)
  235. nfree((*u)->desc);
  236. if ((*u)->user)
  237. nfree((*u)->user);
  238. t = *u;
  239. *u = (*u)->next;
  240. nfree(t);
  241. }
  242. return i;
  243. }
  244. static int u_delexempt (struct chanset_t * c, char * who, int doit)
  245. {
  246. int j, i = 0;
  247. maskrec *t;
  248. maskrec **u = c ? &(c->exempts) : &global_exempts;
  249. if (!strchr(who,'!') && (j = atoi(who))) {
  250. j--;
  251. for (;(*u) && j;u=&((*u)->next),j--);
  252. if (*u) {
  253. strcpy(who, (*u)->mask);
  254. i = 1;
  255. } else
  256. return -j-1;
  257. } else {
  258. /* Find matching host, if there is one */
  259. for (;*u && !i;u=&((*u)->next))
  260. if (!rfc_casecmp((*u)->mask,who)) {
  261. i = 1;
  262. break;
  263. }
  264. if (!*u)
  265. return 0;
  266. }
  267. if (i && doit) {
  268. if (!noshare) {
  269. char *mask = str_escape(who, ':', '\\');
  270. if (mask) {
  271. /* Distribute chan exempts differently */
  272. if (c)
  273. shareout(c, "-ec %s %s\n", c->dname, mask);
  274. else
  275. shareout(NULL, "-e %s\n", mask);
  276. nfree(mask);
  277. }
  278. }
  279. nfree((*u)->mask);
  280. if ((*u)->desc)
  281. nfree((*u)->desc);
  282. if ((*u)->user)
  283. nfree((*u)->user);
  284. t = *u;
  285. *u = (*u)->next;
  286. nfree(t);
  287. }
  288. return i;
  289. }
  290. static int u_delinvite(struct chanset_t *c, char *who, int doit)
  291. {
  292. int j, i = 0;
  293. maskrec *t;
  294. maskrec **u = c ? &(c->invites) : &global_invites;
  295. if (!strchr(who,'!') && (j = atoi(who))) {
  296. j--;
  297. for (;(*u) && j;u=&((*u)->next),j--);
  298. if (*u) {
  299. strcpy(who, (*u)->mask);
  300. i = 1;
  301. } else
  302. return -j-1;
  303. } else {
  304. /* Find matching host, if there is one */
  305. for (;*u && !i; u = &((*u)->next))
  306. if (!rfc_casecmp((*u)->mask,who)) {
  307. i = 1;
  308. break;
  309. }
  310. if (!*u)
  311. return 0;
  312. }
  313. if (i && doit) {
  314. if (!noshare) {
  315. char *mask = str_escape(who, ':', '\\');
  316. if (mask) {
  317. /* Distribute chan invites differently */
  318. if (c)
  319. shareout(c, "-invc %s %s\n", c->dname, mask);
  320. else
  321. shareout(NULL, "-inv %s\n", mask);
  322. nfree(mask);
  323. }
  324. }
  325. nfree((*u)->mask);
  326. if ((*u)->desc)
  327. nfree((*u)->desc);
  328. if ((*u)->user)
  329. nfree((*u)->user);
  330. t = *u;
  331. *u = (*u)->next;
  332. nfree(t);
  333. }
  334. return i;
  335. }
  336. /* Note: If first char of note is '*' it's a sticky ban.
  337. */
  338. static int u_addban(struct chanset_t *chan, char *ban, char *from, char *note,
  339. time_t expire_time, int flags)
  340. {
  341. char host[1024], s[1024];
  342. maskrec *p = NULL, *l, **u = chan ? &chan->bans : &global_bans;
  343. module_entry *me;
  344. strcpy(host, ban);
  345. /* Choke check: fix broken bans (must have '!' and '@') */
  346. if ((strchr(host, '!') == NULL) && (strchr(host, '@') == NULL))
  347. strcat(host, "!*@*");
  348. else if (strchr(host, '@') == NULL)
  349. strcat(host, "@*");
  350. else if (strchr(host, '!') == NULL) {
  351. char *i = strchr(host, '@');
  352. strcpy(s, i);
  353. *i = 0;
  354. strcat(host, "!*");
  355. strcat(host, s);
  356. }
  357. if ((me = module_find("server", 0, 0)) && me->funcs)
  358. simple_sprintf(s, "%s!%s", me->funcs[SERVER_BOTNAME],
  359. me->funcs[SERVER_BOTUSERHOST]);
  360. else
  361. simple_sprintf(s, "%s!%s@%s", origbotname, botuser, hostname);
  362. if (wild_match(host, s)) {
  363. putlog(LOG_MISC, "*", IRC_IBANNEDME);
  364. return 0;
  365. }
  366. if (expire_time == now)
  367. return 1;
  368. for (l = *u; l; l = l->next)
  369. if (!rfc_casecmp(l->mask, host)) {
  370. p = l;
  371. break;
  372. }
  373. /* It shouldn't expire and be sticky also */
  374. if (note[0] == '*') {
  375. flags |= MASKREC_STICKY;
  376. note++;
  377. }
  378. if ((expire_time == 0L) || (flags & MASKREC_PERM)) {
  379. flags |= MASKREC_PERM;
  380. expire_time = 0L;
  381. }
  382. if (p == NULL) {
  383. p = user_malloc(sizeof(maskrec));
  384. p->next = *u;
  385. *u = p;
  386. }
  387. else {
  388. nfree( p->mask );
  389. nfree( p->user );
  390. nfree( p->desc );
  391. }
  392. p->expire = expire_time;
  393. p->added = now;
  394. p->lastactive = 0;
  395. p->flags = flags;
  396. p->mask = user_malloc(strlen(host) + 1);
  397. strcpy(p->mask, host);
  398. p->user = user_malloc(strlen(from) + 1);
  399. strcpy(p->user, from);
  400. p->desc = user_malloc(strlen(note) + 1);
  401. strcpy(p->desc, note);
  402. if (!noshare) {
  403. char *mask = str_escape(host, ':', '\\');
  404. if (mask) {
  405. if (!chan)
  406. shareout(NULL, "+b %s %lu %s%s %s %s\n", mask, expire_time - now,
  407. (flags & MASKREC_STICKY) ? "s" : "",
  408. (flags & MASKREC_PERM) ? "p" : "-", from, note);
  409. else
  410. shareout(chan, "+bc %s %lu %s %s%s %s %s\n", mask, expire_time - now,
  411. chan->dname, (flags & MASKREC_STICKY) ? "s" : "",
  412. (flags & MASKREC_PERM) ? "p" : "-", from, note);
  413. nfree(mask);
  414. }
  415. }
  416. return 1;
  417. }
  418. /* Note: If first char of note is '*' it's a sticky invite.
  419. */
  420. static int u_addinvite(struct chanset_t *chan, char *invite, char *from,
  421. char *note, time_t expire_time, int flags)
  422. {
  423. char host[1024], s[1024];
  424. maskrec *p = NULL, *l, **u = chan ? &chan->invites : &global_invites;
  425. module_entry *me;
  426. strcpy(host, invite);
  427. /* Choke check: fix broken invites (must have '!' and '@') */
  428. if ((strchr(host, '!') == NULL) && (strchr(host, '@') == NULL))
  429. strcat(host, "!*@*");
  430. else if (strchr(host, '@') == NULL)
  431. strcat(host, "@*");
  432. else if (strchr(host, '!') == NULL) {
  433. char * i = strchr(host, '@');
  434. strcpy(s, i);
  435. *i = 0;
  436. strcat(host, "!*");
  437. strcat(host, s);
  438. }
  439. if ((me = module_find("server",0,0)) && me->funcs)
  440. simple_sprintf(s, "%s!%s", me->funcs[SERVER_BOTNAME],
  441. me->funcs[SERVER_BOTUSERHOST]);
  442. else
  443. simple_sprintf(s, "%s!%s@%s", origbotname, botuser, hostname);
  444. for (l = *u; l; l = l->next)
  445. if (!rfc_casecmp(l->mask, host)) {
  446. p = l;
  447. break;
  448. }
  449. /* It shouldn't expire and be sticky also */
  450. if (note[0] == '*') {
  451. flags |= MASKREC_STICKY;
  452. note++;
  453. }
  454. if ((expire_time == 0L) || (flags & MASKREC_PERM)) {
  455. flags |= MASKREC_PERM;
  456. expire_time = 0L;
  457. }
  458. if (p == NULL) {
  459. p = user_malloc(sizeof(maskrec));
  460. p->next = *u;
  461. *u = p;
  462. }
  463. else {
  464. nfree( p->mask );
  465. nfree( p->user );
  466. nfree( p->desc );
  467. }
  468. p->expire = expire_time;
  469. p->added = now;
  470. p->lastactive = 0;
  471. p->flags = flags;
  472. p->mask = user_malloc(strlen(host)+1);
  473. strcpy(p->mask,host);
  474. p->user = user_malloc(strlen(from)+1);
  475. strcpy(p->user,from);
  476. p->desc = user_malloc(strlen(note)+1);
  477. strcpy(p->desc,note);
  478. if (!noshare) {
  479. char *mask = str_escape(host, ':', '\\');
  480. if (mask) {
  481. if (!chan)
  482. shareout(NULL, "+inv %s %lu %s%s %s %s\n", mask, expire_time - now,
  483. (flags & MASKREC_STICKY) ? "s" : "",
  484. (flags & MASKREC_PERM) ? "p": "-", from, note);
  485. else
  486. shareout(chan, "+invc %s %lu %s %s%s %s %s\n", mask, expire_time - now,
  487. chan->dname, (flags & MASKREC_STICKY) ? "s" : "",
  488. (flags & MASKREC_PERM) ? "p": "-", from, note);
  489. nfree(mask);
  490. }
  491. }
  492. return 1;
  493. }
  494. /* Note: If first char of note is '*' it's a sticky exempt.
  495. */
  496. static int u_addexempt(struct chanset_t *chan, char *exempt, char *from,
  497. char *note, time_t expire_time, int flags)
  498. {
  499. char host[1024], s[1024];
  500. maskrec *p = NULL, *l, **u = chan ? &chan->exempts : &global_exempts;
  501. module_entry *me;
  502. strcpy(host, exempt);
  503. /* Choke check: fix broken exempts (must have '!' and '@') */
  504. if ((strchr(host, '!') == NULL) && (strchr(host, '@') == NULL))
  505. strcat(host, "!*@*");
  506. else if (strchr(host, '@') == NULL)
  507. strcat(host, "@*");
  508. else if (strchr(host, '!') == NULL) {
  509. char * i = strchr(host, '@');
  510. strcpy(s, i);
  511. *i = 0;
  512. strcat(host, "!*");
  513. strcat(host, s);
  514. }
  515. if ((me = module_find("server",0,0)) && me->funcs)
  516. simple_sprintf(s, "%s!%s", me->funcs[SERVER_BOTNAME],
  517. me->funcs[SERVER_BOTUSERHOST]);
  518. else
  519. simple_sprintf(s, "%s!%s@%s", origbotname, botuser, hostname);
  520. for (l = *u; l; l = l->next)
  521. if (!rfc_casecmp(l->mask, host)) {
  522. p = l;
  523. break;
  524. }
  525. /* It shouldn't expire and be sticky also */
  526. if (note[0] == '*') {
  527. flags |= MASKREC_STICKY;
  528. note++;
  529. }
  530. if ((expire_time == 0L) || (flags & MASKREC_PERM)) {
  531. flags |= MASKREC_PERM;
  532. expire_time = 0L;
  533. }
  534. if (p == NULL) {
  535. p = user_malloc(sizeof(maskrec));
  536. p->next = *u;
  537. *u = p;
  538. }
  539. else {
  540. nfree( p->mask );
  541. nfree( p->user );
  542. nfree( p->desc );
  543. }
  544. p->expire = expire_time;
  545. p->added = now;
  546. p->lastactive = 0;
  547. p->flags = flags;
  548. p->mask = user_malloc(strlen(host)+1);
  549. strcpy(p->mask,host);
  550. p->user = user_malloc(strlen(from)+1);
  551. strcpy(p->user,from);
  552. p->desc = user_malloc(strlen(note)+1);
  553. strcpy(p->desc,note);
  554. if (!noshare) {
  555. char *mask = str_escape(host, ':', '\\');
  556. if (mask) {
  557. if (!chan)
  558. shareout(NULL, "+e %s %lu %s%s %s %s\n", mask, expire_time - now,
  559. (flags & MASKREC_STICKY) ? "s" : "",
  560. (flags & MASKREC_PERM) ? "p": "-", from, note);
  561. else
  562. shareout(chan, "+ec %s %lu %s %s%s %s %s\n", mask, expire_time - now,
  563. chan->dname, (flags & MASKREC_STICKY) ? "s" : "",
  564. (flags & MASKREC_PERM) ? "p": "-", from, note);
  565. nfree(mask);
  566. }
  567. }
  568. return 1;
  569. }
  570. /* Take host entry from ban list and display it ban-style.
  571. */
  572. static void display_ban(int idx, int number, maskrec *ban,
  573. struct chanset_t *chan, int show_inact)
  574. {
  575. char dates[81], s[41];
  576. if (ban->added) {
  577. daysago(now, ban->added, s);
  578. sprintf(dates, "%s %s", MODES_CREATED, s);
  579. if (ban->added < ban->lastactive) {
  580. strcat(dates, ", ");
  581. strcat(dates, MODES_LASTUSED);
  582. strcat(dates, " ");
  583. daysago(now, ban->lastactive, s);
  584. strcat(dates, s);
  585. }
  586. } else
  587. dates[0] = 0;
  588. if (ban->flags & MASKREC_PERM)
  589. strcpy(s, "(perm)");
  590. else {
  591. char s1[41];
  592. days(ban->expire, now, s1);
  593. sprintf(s, "(expires %s)", s1);
  594. }
  595. if (ban->flags & MASKREC_STICKY)
  596. strcat(s, " (sticky)");
  597. if (!chan || ischanban(chan, ban->mask)) {
  598. if (number >= 0) {
  599. dprintf(idx, " [%3d] %s %s\n", number, ban->mask, s);
  600. } else {
  601. dprintf(idx, "BAN: %s %s\n", ban->mask, s);
  602. }
  603. } else if (show_inact) {
  604. if (number >= 0) {
  605. dprintf(idx, "! [%3d] %s %s\n", number, ban->mask, s);
  606. } else {
  607. dprintf(idx, "BAN (%s): %s %s\n", MODES_INACTIVE, ban->mask, s);
  608. }
  609. } else
  610. return;
  611. dprintf(idx, " %s: %s\n", ban->user, ban->desc);
  612. if (dates[0])
  613. dprintf(idx, " %s\n", dates);
  614. }
  615. /* Take host entry from exempt list and display it ban-style.
  616. */
  617. static void display_exempt(int idx, int number, maskrec *exempt,
  618. struct chanset_t *chan, int show_inact)
  619. {
  620. char dates[81], s[41];
  621. if (exempt->added) {
  622. daysago(now, exempt->added, s);
  623. sprintf(dates, "%s %s", MODES_CREATED, s);
  624. if (exempt->added < exempt->lastactive) {
  625. strcat(dates, ", ");
  626. strcat(dates, MODES_LASTUSED);
  627. strcat(dates, " ");
  628. daysago(now, exempt->lastactive, s);
  629. strcat(dates, s);
  630. }
  631. } else
  632. dates[0] = 0;
  633. if (exempt->flags & MASKREC_PERM)
  634. strcpy(s, "(perm)");
  635. else {
  636. char s1[41];
  637. days(exempt->expire, now, s1);
  638. sprintf(s, "(expires %s)", s1);
  639. }
  640. if (exempt->flags & MASKREC_STICKY)
  641. strcat(s, " (sticky)");
  642. if (!chan || ischanexempt(chan, exempt->mask)) {
  643. if (number >= 0) {
  644. dprintf(idx, " [%3d] %s %s\n", number, exempt->mask, s);
  645. } else {
  646. dprintf(idx, "EXEMPT: %s %s\n", exempt->mask, s);
  647. }
  648. } else if (show_inact) {
  649. if (number >= 0) {
  650. dprintf(idx, "! [%3d] %s %s\n", number, exempt->mask, s);
  651. } else {
  652. dprintf(idx, "EXEMPT (%s): %s %s\n", MODES_INACTIVE, exempt->mask, s);
  653. }
  654. } else
  655. return;
  656. dprintf(idx, " %s: %s\n", exempt->user, exempt->desc);
  657. if (dates[0])
  658. dprintf(idx, " %s\n", dates);
  659. }
  660. /* Take host entry from invite list and display it ban-style.
  661. */
  662. static void display_invite (int idx, int number, maskrec *invite,
  663. struct chanset_t *chan, int show_inact)
  664. {
  665. char dates[81], s[41];
  666. if (invite->added) {
  667. daysago(now, invite->added, s);
  668. sprintf(dates, "%s %s", MODES_CREATED, s);
  669. if (invite->added < invite->lastactive) {
  670. strcat(dates, ", ");
  671. strcat(dates, MODES_LASTUSED);
  672. strcat(dates, " ");
  673. daysago(now, invite->lastactive, s);
  674. strcat(dates, s);
  675. }
  676. } else
  677. dates[0] = 0;
  678. if (invite->flags & MASKREC_PERM)
  679. strcpy(s, "(perm)");
  680. else {
  681. char s1[41];
  682. days(invite->expire, now, s1);
  683. sprintf(s, "(expires %s)", s1);
  684. }
  685. if (invite->flags & MASKREC_STICKY)
  686. strcat(s, " (sticky)");
  687. if (!chan || ischaninvite(chan, invite->mask)) {
  688. if (number >= 0) {
  689. dprintf(idx, " [%3d] %s %s\n", number, invite->mask, s);
  690. } else {
  691. dprintf(idx, "INVITE: %s %s\n", invite->mask, s);
  692. }
  693. } else if (show_inact) {
  694. if (number >= 0) {
  695. dprintf(idx, "! [%3d] %s %s\n", number, invite->mask, s);
  696. } else {
  697. dprintf(idx, "INVITE (%s): %s %s\n", MODES_INACTIVE, invite->mask, s);
  698. }
  699. } else
  700. return;
  701. dprintf(idx, " %s: %s\n", invite->user, invite->desc);
  702. if (dates[0])
  703. dprintf(idx, " %s\n", dates);
  704. }
  705. static void tell_bans(int idx, int show_inact, char *match)
  706. {
  707. int k = 1;
  708. char *chname;
  709. struct chanset_t *chan = NULL;
  710. maskrec *u;
  711. /* Was a channel given? */
  712. if (match[0]) {
  713. chname = newsplit(&match);
  714. if (chname[0] && (strchr(CHANMETA, chname[0]))) {
  715. chan = findchan_by_dname(chname);
  716. if (!chan) {
  717. dprintf(idx, "%s.\n", CHAN_NOSUCH);
  718. return;
  719. }
  720. } else
  721. match = chname;
  722. }
  723. /* don't return here, we want to show global bans even if no chan */
  724. if (!chan && !(chan = findchan_by_dname(dcc[idx].u.chat->con_chan)) &&
  725. !(chan = chanset))
  726. chan = NULL;
  727. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  728. if (private(user, chan, PRIV_OP)) {
  729. dprintf(idx, "%s.\n", CHAN_NOSUCH);
  730. return;
  731. }
  732. if (chan && show_inact)
  733. dprintf(idx, "%s: (! = %s %s)\n", BANS_GLOBAL,
  734. MODES_NOTACTIVE, chan->dname);
  735. else
  736. dprintf(idx, "%s:\n", BANS_GLOBAL);
  737. for (u = global_bans; u; u = u->next) {
  738. if (match[0]) {
  739. if ((wild_match(match, u->mask)) ||
  740. (wild_match(match, u->desc)) ||
  741. (wild_match(match, u->user)))
  742. display_ban(idx, k, u, chan, 1);
  743. k++;
  744. } else
  745. display_ban(idx, k++, u, chan, show_inact);
  746. }
  747. if (chan) {
  748. if (show_inact)
  749. dprintf(idx, "%s %s: (! = %s, * = %s)\n",
  750. BANS_BYCHANNEL, chan->dname,
  751. MODES_NOTACTIVE2, MODES_NOTBYBOT);
  752. else
  753. dprintf(idx, "%s %s: (* = %s)\n",
  754. BANS_BYCHANNEL, chan->dname,
  755. MODES_NOTBYBOT);
  756. for (u = chan->bans; u; u = u->next) {
  757. if (match[0]) {
  758. if ((wild_match(match, u->mask)) ||
  759. (wild_match(match, u->desc)) ||
  760. (wild_match(match, u->user)))
  761. display_ban(idx, k, u, chan, 1);
  762. k++;
  763. } else
  764. display_ban(idx, k++, u, chan, show_inact);
  765. }
  766. if (chan->status & CHAN_ACTIVE) {
  767. masklist *b;
  768. char s[UHOSTLEN], *s1, *s2, fill[256];
  769. int min, sec;
  770. for (b = chan->channel.ban; b && b->mask[0]; b = b->next) {
  771. if ((!u_equals_mask(global_bans, b->mask)) &&
  772. (!u_equals_mask(chan->bans, b->mask))) {
  773. strcpy(s, b->who);
  774. s2 = s;
  775. s1 = splitnick(&s2);
  776. if (s1[0])
  777. sprintf(fill, "%s (%s!%s)", b->mask, s1, s2);
  778. else
  779. sprintf(fill, "%s (server %s)", b->mask, s2);
  780. if (b->timer != 0) {
  781. min = (now - b->timer) / 60;
  782. sec = (now - b->timer) - (min * 60);
  783. sprintf(s, " (active %02d:%02d)", min, sec);
  784. strcat(fill, s);
  785. }
  786. if ((!match[0]) || (wild_match(match, b->mask)))
  787. dprintf(idx, "* [%3d] %s\n", k, fill);
  788. k++;
  789. }
  790. }
  791. }
  792. }
  793. if (k == 1)
  794. dprintf(idx, "(There are no bans, permanent or otherwise.)\n");
  795. if ((!show_inact) && (!match[0]))
  796. dprintf(idx, "%s.\n", BANS_USEBANSALL);
  797. }
  798. static void tell_exempts(int idx, int show_inact, char *match)
  799. {
  800. int k = 1;
  801. char *chname;
  802. struct chanset_t *chan = NULL;
  803. maskrec *u;
  804. /* Was a channel given? */
  805. if (match[0]) {
  806. chname = newsplit(&match);
  807. if (chname[0] && strchr(CHANMETA, chname[0])) {
  808. chan = findchan_by_dname(chname);
  809. if (!chan) {
  810. dprintf(idx, "%s.\n", CHAN_NOSUCH);
  811. return;
  812. }
  813. } else
  814. match = chname;
  815. }
  816. /* don't return here, we want to show global exempts even if no chan */
  817. if (!chan && !(chan = findchan_by_dname(dcc[idx].u.chat->con_chan))
  818. && !(chan = chanset))
  819. chan = NULL;
  820. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  821. if (private(user, chan, PRIV_OP)) {
  822. dprintf(idx, "%s.\n", CHAN_NOSUCH);
  823. return;
  824. }
  825. if (chan && show_inact)
  826. dprintf(idx, "%s: (! = %s %s)\n", EXEMPTS_GLOBAL,
  827. MODES_NOTACTIVE, chan->dname);
  828. else
  829. dprintf(idx, "%s:\n", EXEMPTS_GLOBAL);
  830. for (u = global_exempts; u; u = u->next) {
  831. if (match[0]) {
  832. if ((wild_match(match, u->mask)) ||
  833. (wild_match(match, u->desc)) ||
  834. (wild_match(match, u->user)))
  835. display_exempt(idx, k, u, chan, 1);
  836. k++;
  837. } else
  838. display_exempt(idx, k++, u, chan, show_inact);
  839. }
  840. if (chan) {
  841. if (show_inact)
  842. dprintf(idx, "%s %s: (! = %s, * = %s)\n",
  843. EXEMPTS_BYCHANNEL, chan->dname,
  844. MODES_NOTACTIVE2,
  845. MODES_NOTBYBOT);
  846. else
  847. dprintf(idx, "%s %s: (* = %s)\n",
  848. EXEMPTS_BYCHANNEL, chan->dname,
  849. MODES_NOTBYBOT);
  850. for (u = chan->exempts; u; u = u->next) {
  851. if (match[0]) {
  852. if ((wild_match(match, u->mask)) ||
  853. (wild_match(match, u->desc)) ||
  854. (wild_match(match, u->user)))
  855. display_exempt(idx, k, u, chan, 1);
  856. k++;
  857. } else
  858. display_exempt(idx, k++, u, chan, show_inact);
  859. }
  860. if (chan->status & CHAN_ACTIVE) {
  861. masklist *e;
  862. char s[UHOSTLEN], *s1, *s2,fill[256];
  863. int min, sec;
  864. for (e = chan->channel.exempt; e && e->mask[0]; e = e->next) {
  865. if ((!u_equals_mask(global_exempts,e->mask)) &&
  866. (!u_equals_mask(chan->exempts, e->mask))) {
  867. strcpy(s, e->who);
  868. s2 = s;
  869. s1 = splitnick(&s2);
  870. if (s1[0])
  871. sprintf(fill, "%s (%s!%s)", e->mask, s1, s2);
  872. else
  873. sprintf(fill, "%s (server %s)", e->mask, s2);
  874. if (e->timer != 0) {
  875. min = (now - e->timer) / 60;
  876. sec = (now - e->timer) - (min * 60);
  877. sprintf(s, " (active %02d:%02d)", min, sec);
  878. strcat(fill, s);
  879. }
  880. if ((!match[0]) || (wild_match(match, e->mask)))
  881. dprintf(idx, "* [%3d] %s\n", k, fill);
  882. k++;
  883. }
  884. }
  885. }
  886. }
  887. if (k == 1)
  888. dprintf(idx, "(There are no ban exempts, permanent or otherwise.)\n");
  889. if ((!show_inact) && (!match[0]))
  890. dprintf(idx, "%s.\n", EXEMPTS_USEEXEMPTSALL);
  891. }
  892. static void tell_invites(int idx, int show_inact, char *match)
  893. {
  894. int k = 1;
  895. char *chname;
  896. struct chanset_t *chan = NULL;
  897. maskrec *u;
  898. /* Was a channel given? */
  899. if (match[0]) {
  900. chname = newsplit(&match);
  901. if (chname[0] && strchr(CHANMETA, chname[0])) {
  902. chan = findchan_by_dname(chname);
  903. if (!chan) {
  904. dprintf(idx, "%s.\n", CHAN_NOSUCH);
  905. return;
  906. }
  907. } else
  908. match = chname;
  909. }
  910. /* don't return here, we want to show global invites even if no chan */
  911. if (!chan && !(chan = findchan_by_dname(dcc[idx].u.chat->con_chan))
  912. && !(chan = chanset))
  913. chan = NULL;
  914. get_user_flagrec(dcc[idx].user, &user, chan->dname);
  915. if (private(user, chan, PRIV_OP)) {
  916. dprintf(idx, "%s.\n", CHAN_NOSUCH);
  917. return;
  918. }
  919. if (chan && show_inact)
  920. dprintf(idx, "%s: (! = %s %s)\n", INVITES_GLOBAL,
  921. MODES_NOTACTIVE, chan->dname);
  922. else
  923. dprintf(idx, "%s:\n", INVITES_GLOBAL);
  924. for (u = global_invites; u; u = u->next) {
  925. if (match[0]) {
  926. if ((wild_match(match, u->mask)) ||
  927. (wild_match(match, u->desc)) ||
  928. (wild_match(match, u->user)))
  929. display_invite(idx, k, u, chan, 1);
  930. k++;
  931. } else
  932. display_invite(idx, k++, u, chan, show_inact);
  933. }
  934. if (chan) {
  935. if (show_inact)
  936. dprintf(idx, "%s %s: (! = %s, * = %s)\n",
  937. INVITES_BYCHANNEL, chan->dname,
  938. MODES_NOTACTIVE2,
  939. MODES_NOTBYBOT);
  940. else
  941. dprintf(idx, "%s %s: (* = %s)\n",
  942. INVITES_BYCHANNEL, chan->dname,
  943. MODES_NOTBYBOT);
  944. for (u = chan->invites; u; u = u->next) {
  945. if (match[0]) {
  946. if ((wild_match(match, u->mask)) ||
  947. (wild_match(match, u->desc)) ||
  948. (wild_match(match, u->user)))
  949. display_invite(idx, k, u, chan, 1);
  950. k++;
  951. } else
  952. display_invite(idx, k++, u, chan, show_inact);
  953. }
  954. if (chan->status & CHAN_ACTIVE) {
  955. masklist *i;
  956. char s[UHOSTLEN], *s1, *s2,fill[256];
  957. int min, sec;
  958. for (i = chan->channel.invite; i && i->mask[0]; i = i->next) {
  959. if ((!u_equals_mask(global_invites,i->mask)) &&
  960. (!u_equals_mask(chan->invites, i->mask))) {
  961. strcpy(s, i->who);
  962. s2 = s;
  963. s1 = splitnick(&s2);
  964. if (s1[0])
  965. sprintf(fill, "%s (%s!%s)", i->mask, s1, s2);
  966. else
  967. sprintf(fill, "%s (server %s)", i->mask, s2);
  968. if (i->timer != 0) {
  969. min = (now - i->timer) / 60;
  970. sec = (now - i->timer) - (min * 60);
  971. sprintf(s, " (active %02d:%02d)", min, sec);
  972. strcat(fill, s);
  973. }
  974. if ((!match[0]) || (wild_match(match, i->mask)))
  975. dprintf(idx, "* [%3d] %s\n", k, fill);
  976. k++;
  977. }
  978. }
  979. }
  980. }
  981. if (k == 1)
  982. dprintf(idx, "(There are no invites, permanent or otherwise.)\n");
  983. if ((!show_inact) && (!match[0]))
  984. dprintf(idx, "%s.\n", INVITES_USEINVITESALL);
  985. }
  986. static int write_config(FILE *f, int idx)
  987. {
  988. int i = 0;
  989. #ifdef S_DCCPASS
  990. struct cmd_pass *cp;
  991. #endif
  992. putlog(LOG_DEBUG, "@", "Writing config entries...");
  993. if (lfprintf(f, CONFIG_NAME " - -\n") == EOF) /* Daemus */
  994. return 0;
  995. for (i = 0; i < cfg_count; i++)
  996. if ((cfg[i]->flags & CFGF_GLOBAL) && (cfg[i]->gdata)) {
  997. if (lfprintf(f, "@ %s %s\n", cfg[i]->name, cfg[i]->gdata ? cfg[i]->gdata : "") == EOF)
  998. return 0;
  999. }
  1000. #ifdef S_DCCPASS
  1001. for (cp = cmdpass; cp; cp = cp->next)
  1002. if (lfprintf(f, "- %s %s\n", cp->name, cp->pass) == EOF)
  1003. return 0;
  1004. #endif
  1005. return 1;
  1006. }
  1007. /* Write the ban lists and the ignore list to a file.
  1008. */
  1009. static int write_bans(FILE *f, int idx)
  1010. {
  1011. struct chanset_t *chan;
  1012. maskrec *b;
  1013. struct igrec *i;
  1014. char *mask;
  1015. if (global_ign)
  1016. if (lfprintf(f, IGNORE_NAME " - -\n") == EOF) /* Daemus */
  1017. return 0;
  1018. for (i = global_ign; i; i = i->next) {
  1019. mask = str_escape(i->igmask, ':', '\\');
  1020. if (!mask ||
  1021. lfprintf(f, "- %s:%s%lu:%s:%lu:%s\n", mask,
  1022. (i->flags & IGREC_PERM) ? "+" : "", i->expire,
  1023. i->user ? i->user : botnetnick, i->added,
  1024. i->msg ? i->msg : "") == EOF) {
  1025. if (mask)
  1026. nfree(mask);
  1027. return 0;
  1028. }
  1029. nfree(mask);
  1030. }
  1031. if (global_bans)
  1032. if (lfprintf(f, BAN_NAME " - -\n") == EOF) /* Daemus */
  1033. return 0;
  1034. for (b = global_bans; b; b = b->next) {
  1035. mask = str_escape(b->mask, ':', '\\');
  1036. if (!mask ||
  1037. lfprintf(f, "- %s:%s%lu%s:+%lu:%lu:%s:%s\n", mask,
  1038. (b->flags & MASKREC_PERM) ? "+" : "", b->expire,
  1039. (b->flags & MASKREC_STICKY) ? "*" : "", b->added,
  1040. b->lastactive, b->user ? b->user : botnetnick,
  1041. b->desc ? b->desc : "requested") == EOF) {
  1042. if (mask)
  1043. nfree(mask);
  1044. return 0;
  1045. }
  1046. nfree(mask);
  1047. }
  1048. for (chan = chanset; chan; chan = chan->next)
  1049. if ((idx < 0) || 1) {
  1050. struct flag_record fr = {FR_CHAN | FR_GLOBAL | FR_BOT, 0, 0, 0, 0, 0};
  1051. if (idx >= 0)
  1052. get_user_flagrec(dcc[idx].user, &fr, chan->dname);
  1053. else
  1054. fr.chan = BOT_SHARE;
  1055. //if ((fr.chan & BOT_SHARE) || (fr.bot & BOT_GLOBAL)) {
  1056. if (lfprintf(f, "::%s bans\n", chan->dname) == EOF)
  1057. return 0;
  1058. for (b = chan->bans; b; b = b->next) {
  1059. mask = str_escape(b->mask, ':', '\\');
  1060. if (!mask ||
  1061. lfprintf(f, "- %s:%s%lu%s:+%lu:%lu:%s:%s\n", mask,
  1062. (b->flags & MASKREC_PERM) ? "+" : "", b->expire,
  1063. (b->flags & MASKREC_STICKY) ? "*" : "", b->added,
  1064. b->lastactive, b->user ? b->user : botnetnick,
  1065. b->desc ? b->desc : "requested") == EOF) {
  1066. if (mask)
  1067. nfree(mask);
  1068. return 0;
  1069. }
  1070. nfree(mask);
  1071. }
  1072. //}
  1073. }
  1074. return 1;
  1075. }
  1076. #ifdef S_IRCNET
  1077. /* Write the exemptlists to a file.
  1078. */
  1079. static int write_exempts(FILE *f, int idx)
  1080. {
  1081. struct chanset_t *chan;
  1082. maskrec *e;
  1083. char *mask;
  1084. if (global_exempts)
  1085. if (lfprintf(f, EXEMPT_NAME " - -\n") == EOF) /* Daemus */
  1086. return 0;
  1087. for (e = global_exempts; e; e = e->next) {
  1088. mask = str_escape(e->mask, ':', '\\');
  1089. if (!mask ||
  1090. lfprintf(f, "%s %s:%s%lu%s:+%lu:%lu:%s:%s\n", "%", e->mask,
  1091. (e->flags & MASKREC_PERM) ? "+" : "", e->expire,
  1092. (e->flags & MASKREC_STICKY) ? "*" : "", e->added,
  1093. e->lastactive, e->user ? e->user : botnetnick,
  1094. e->desc ? e->desc : "requested") == EOF) {
  1095. if (mask)
  1096. nfree(mask);
  1097. return 0;
  1098. }
  1099. nfree(mask);
  1100. }
  1101. for (chan = chanset;chan;chan=chan->next)
  1102. if ((idx < 0) || 1) {
  1103. struct flag_record fr = {FR_CHAN | FR_GLOBAL | FR_BOT, 0, 0, 0, 0, 0};
  1104. if (idx >= 0)
  1105. get_user_flagrec(dcc[idx].user,&fr,chan->dname);
  1106. else
  1107. fr.chan = BOT_SHARE;
  1108. // if ((fr.chan & BOT_SHARE) || (fr.bot & BOT_GLOBAL)) {
  1109. if (lfprintf(f, "&&%s exempts\n", chan->dname) == EOF)
  1110. return 0;
  1111. for (e = chan->exempts; e; e = e->next) {
  1112. mask = str_escape(e->mask, ':', '\\');
  1113. if (!mask ||
  1114. lfprintf(f,"%s %s:%s%lu%s:+%lu:%lu:%s:%s\n","%",e->mask,
  1115. (e->flags & MASKREC_PERM) ? "+" : "", e->expire,
  1116. (e->flags & MASKREC_STICKY) ? "*" : "", e->added,
  1117. e->lastactive, e->user ? e->user : botnetnick,
  1118. e->desc ? e->desc : "requested") == EOF) {
  1119. if (mask)
  1120. nfree(mask);
  1121. return 0;
  1122. }
  1123. nfree(mask);
  1124. }
  1125. //}
  1126. }
  1127. return 1;
  1128. }
  1129. /* Write the invitelists to a file.
  1130. */
  1131. static int write_invites(FILE *f, int idx)
  1132. {
  1133. struct chanset_t *chan;
  1134. maskrec *ir;
  1135. char *mask;
  1136. if (global_invites)
  1137. if (lfprintf(f, INVITE_NAME " - -\n") == EOF) /* Daemus */
  1138. return 0;
  1139. for (ir = global_invites; ir; ir = ir->next) {
  1140. mask = str_escape(ir->mask, ':', '\\');
  1141. if (!mask ||
  1142. lfprintf(f,"@ %s:%s%lu%s:+%lu:%lu:%s:%s\n",ir->mask,
  1143. (ir->flags & MASKREC_PERM) ? "+" : "", ir->expire,
  1144. (ir->flags & MASKREC_STICKY) ? "*" : "", ir->added,
  1145. ir->lastactive, ir->user ? ir->user : botnetnick,
  1146. ir->desc ? ir->desc : "requested") == EOF) {
  1147. if (mask)
  1148. nfree(mask);
  1149. return 0;
  1150. }
  1151. nfree(mask);
  1152. }
  1153. for (chan = chanset; chan; chan = chan->next)
  1154. if ((idx < 0) || (1)) {
  1155. struct flag_record fr = {FR_CHAN | FR_GLOBAL | FR_BOT, 0, 0, 0, 0, 0};
  1156. if (idx >= 0)
  1157. get_user_flagrec(dcc[idx].user,&fr,chan->dname);
  1158. else
  1159. fr.chan = BOT_SHARE;
  1160. // if ((fr.chan & BOT_SHARE) || (fr.bot & BOT_GLOBAL)) {
  1161. if (lfprintf(f, "$$%s invites\n", chan->dname) == EOF)
  1162. return 0;
  1163. for (ir = chan->invites; ir; ir = ir->next) {
  1164. mask = str_escape(ir->mask, ':', '\\');
  1165. if (!mask ||
  1166. lfprintf(f,"@ %s:%s%lu%s:+%lu:%lu:%s:%s\n",ir->mask,
  1167. (ir->flags & MASKREC_PERM) ? "+" : "", ir->expire,
  1168. (ir->flags & MASKREC_STICKY) ? "*" : "", ir->added,
  1169. ir->lastactive, ir->user ? ir->user : botnetnick,
  1170. ir->desc ? ir->desc : "requested") == EOF) {
  1171. if (mask)
  1172. nfree(mask);
  1173. return 0;
  1174. }
  1175. nfree(mask);
  1176. }
  1177. //}
  1178. }
  1179. return 1;
  1180. }
  1181. #endif
  1182. /* Write the channels to the userfile
  1183. */
  1184. static int write_chans(FILE *f, int idx)
  1185. {
  1186. char w[1024], w2[1024], name[163];
  1187. char udefs[2048] = "", sadd[5], buf[2048];
  1188. /* Chanchar template
  1189. *char temp[121];
  1190. */
  1191. struct chanset_t *chan;
  1192. struct udef_struct *ul;
  1193. putlog(LOG_DEBUG, "*", "Writing channels..");
  1194. if (lfprintf(f, CHANS_NAME " - -\n") == EOF) /* Daemus */
  1195. return 0;
  1196. for (chan = chanset; chan; chan = chan->next) {
  1197. if ((idx < 0) || (1)) {
  1198. struct flag_record fr = {FR_CHAN | FR_GLOBAL | FR_BOT, 0, 0, 0, 0, 0};
  1199. if (idx >= 0)
  1200. get_user_flagrec(dcc[idx].user,&fr,chan->dname);
  1201. else
  1202. fr.chan = BOT_SHARE;
  1203. // if ((fr.chan & BOT_SHARE) || (fr.bot & BOT_GLOBAL)) {
  1204. putlog(LOG_DEBUG, "*", "writing channel %s to userfile..", chan->dname);
  1205. memset(udefs,'\0',2048);
  1206. convert_element(chan->dname, name);
  1207. get_mode_protect(chan, w);
  1208. convert_element(w, w2);
  1209. /* Chanchar template
  1210. * convert_element(chan->temp, temp);
  1211. */
  1212. for (ul = udef; ul; ul = ul->next) { //put the udefs into one string
  1213. memset(buf,'\0',2048);
  1214. if (ul->defined && ul->name) {
  1215. if (ul->type == UDEF_FLAG)
  1216. sprintf(buf, "%c%s%s ", getudef(ul->values, chan->dname) ? '+' : '-', "udef-flag-", ul->name);
  1217. else if (ul->type == UDEF_INT)
  1218. sprintf(buf, "%s%s %d ", "udef-int-", ul->name, getudef(ul->values, chan->dname));
  1219. else
  1220. debug1("UDEF-ERROR: unknown type %d", ul->type);
  1221. strcat(udefs,buf);
  1222. }
  1223. }
  1224. //insert the ending character into a string
  1225. sprintf(sadd, "}\n");
  1226. if (lfprintf(f, "+ channel %s %s%schanmode %s idle-kick %d limit %d stopnethack-mode %d \
  1227. revenge-mode %d \
  1228. flood-chan %d:%d flood-ctcp %d:%d flood-join %d:%d \
  1229. flood-kick %d:%d flood-deop %d:%d flood-nick %d:%d \
  1230. ban-time %d \
  1231. exempt-time %d invite-time %d \
  1232. %cenforcebans %cdynamicbans %cuserbans %cbitch \
  1233. %cprotectops %cdontkickops \
  1234. %crevenge %crevengebot %cprivate \
  1235. %ccycle %cinactive \
  1236. %cdynamicexempts %cuserexempts %cdynamicinvites %cuserinvites \
  1237. %cnodesynch \
  1238. %cclosed %ctake %cmanop %cvoice %cfastop %s %s",
  1239. "add",
  1240. name,
  1241. " { ",
  1242. w2,
  1243. /* Chanchar template
  1244. * temp,
  1245. * also include temp %s in dprintf.
  1246. */
  1247. chan->idle_kick, /* idle-kick 0 is same as dont-idle-kick (lcode)*/
  1248. chan->limitraise,
  1249. chan->stopnethack_mode,
  1250. chan->revenge_mode,
  1251. chan->flood_pub_thr, chan->flood_pub_time,
  1252. chan->flood_ctcp_thr, chan->flood_ctcp_time,
  1253. chan->flood_join_thr, chan->flood_join_time,
  1254. chan->flood_kick_thr, chan->flood_kick_time,
  1255. chan->flood_deop_thr, chan->flood_deop_time,
  1256. chan->flood_nick_thr, chan->flood_nick_time,
  1257. /* Chanint template
  1258. * chan->temp,
  1259. * also include temp %d in dprintf
  1260. */
  1261. chan->ban_time,
  1262. #ifdef S_IRCNET
  1263. chan->exempt_time,
  1264. chan->invite_time,
  1265. #endif
  1266. PLSMNS(channel_enforcebans(chan)),
  1267. PLSMNS(channel_dynamicbans(chan)),
  1268. PLSMNS(!channel_nouserbans(chan)),
  1269. PLSMNS(channel_bitch(chan)),
  1270. PLSMNS(channel_protectops(chan)),
  1271. PLSMNS(channel_dontkickops(chan)),
  1272. PLSMNS(channel_revenge(chan)),
  1273. PLSMNS(channel_revengebot(chan)),
  1274. PLSMNS(channel_private(chan)),
  1275. PLSMNS(channel_cycle(chan)),
  1276. PLSMNS(channel_inactive(chan)),
  1277. #ifdef S_IRCNET
  1278. PLSMNS(channel_dynamicexempts(chan)),
  1279. PLSMNS(!channel_nouserexempts(chan)),
  1280. PLSMNS(channel_dynamicinvites(chan)),
  1281. PLSMNS(!channel_nouserinvites(chan)),
  1282. #endif
  1283. PLSMNS(channel_nodesynch(chan)),
  1284. PLSMNS(channel_closed(chan)),
  1285. PLSMNS(channel_take(chan)),
  1286. PLSMNS(channel_manop(chan)),
  1287. PLSMNS(channel_voice(chan)),
  1288. PLSMNS(channel_fastop(chan)),
  1289. /* Chanflag template
  1290. * also include a %ctemp above.
  1291. * PLSMNS(channel_temp(chan)),
  1292. */
  1293. udefs,
  1294. sadd) == EOF)
  1295. return 0;
  1296. // }
  1297. }
  1298. }
  1299. return 1;
  1300. }
  1301. static void channels_writeuserfile(void)
  1302. {
  1303. #ifdef HUB
  1304. char s[1024];
  1305. FILE *f;
  1306. int ret = 0;
  1307. putlog(LOG_DEBUG, "@", "Writing channel/ban/exempt/invite entries.");
  1308. simple_sprintf(s, "%s~new", userfile);
  1309. f = fopen(s, "a");
  1310. if (f) {
  1311. //write channels to the userfile
  1312. ret = write_chans(f, -1);
  1313. ret += write_config(f, -1);
  1314. ret += write_bans(f, -1);
  1315. #ifdef S_IRCNET
  1316. ret += write_exempts(f, -1);
  1317. ret += write_invites(f, -1);
  1318. #endif
  1319. fclose(f);
  1320. }
  1321. #ifdef S_IRCNET
  1322. if (ret < 5)
  1323. #else
  1324. if (ret < 3)
  1325. #endif
  1326. putlog(LOG_MISC, "*", USERF_ERRWRITE);
  1327. //old .chan write_channels();
  1328. #endif
  1329. }
  1330. /* Expire mask originally set by `who' on `chan'?
  1331. *
  1332. * We might not want to expire masks in all cases, as other bots
  1333. * often tend to immediately reset masks they've listed in their
  1334. * internal ban list, making it quite senseless for us to remove
  1335. * them in the first place.
  1336. *
  1337. * Returns 1 if a mask on `chan' by `who' may be expired and 0 if
  1338. * not.
  1339. */
  1340. static int expired_mask(struct chanset_t *chan, char *who)
  1341. {
  1342. memberlist *m, *m2;
  1343. char buf[UHOSTLEN], *snick, *sfrom;
  1344. struct userrec *u;
  1345. /* Always expire masks, regardless of who set it? */
  1346. if (force_expire)
  1347. return 1;
  1348. strcpy(buf, who);
  1349. sfrom = buf;
  1350. snick = splitnick(&sfrom);
  1351. if (!snick[0])
  1352. return 1;
  1353. m = ismember(chan, snick);
  1354. if (!m)
  1355. for (m2 = chan->channel.member; m2 && m2->nick[0]; m2 = m2->next)
  1356. if (!egg_strcasecmp(sfrom, m2->userhost)) {
  1357. m = m2;
  1358. break;
  1359. }
  1360. if (!m || !chan_hasop(m) || !rfc_casecmp(m->nick, botname))
  1361. return 1;
  1362. /* At this point we know the person/bot who set the mask is currently
  1363. * present in the channel and has op.
  1364. */
  1365. if (m->user)
  1366. u = m->user;
  1367. else {
  1368. simple_sprintf(buf, "%s!%s", m->nick, m->userhost);
  1369. u = get_user_by_host(buf);
  1370. }
  1371. /* Do not expire masks set by bots. */
  1372. if (u && u->flags & USER_BOT)
  1373. return 0;
  1374. else
  1375. return 1;
  1376. }
  1377. #ifdef LEAF
  1378. int checklimit = 1;
  1379. void check_limitraise() {
  1380. int i=0;
  1381. struct chanset_t * chan;
  1382. for (chan=chanset;chan;chan=chan->next,i++) {
  1383. if (i % 2 == checklimit) {
  1384. if (chan->limitraise) {
  1385. if (dolimit(chan))
  1386. raise_limit(chan);
  1387. }
  1388. }
  1389. }
  1390. if (checklimit)
  1391. checklimit=0;
  1392. else
  1393. checklimit=1;
  1394. }
  1395. #endif
  1396. /* Check for expired timed-bans.
  1397. */
  1398. static void check_expired_bans(void)
  1399. {
  1400. maskrec *u, *u2;
  1401. struct chanset_t *chan;
  1402. masklist *b;
  1403. for (u = global_bans; u; u = u2) {
  1404. u2 = u->next;
  1405. if (!(u->flags & MASKREC_PERM) && (now >= u->expire)) {
  1406. putlog(LOG_MISC, "*", "%s %s (%s)", BANS_NOLONGER,
  1407. u->mask, MISC_EXPIRED);
  1408. for (chan = chanset; chan; chan = chan->next)
  1409. for (b = chan->channel.ban; b->mask[0]; b = b->next)
  1410. if (!rfc_casecmp(b->mask, u->mask) &&
  1411. expired_mask(chan, b->who) && b->timer != now) {
  1412. add_mode(chan, '-', 'b', u->mask);
  1413. b->timer = now;
  1414. }
  1415. u_delban(NULL, u->mask, 1);
  1416. }
  1417. }
  1418. /* Check for specific channel-domain bans expiring */
  1419. for (chan = chanset; chan; chan = chan->next) {
  1420. for (u = chan->bans; u; u = u2) {
  1421. u2 = u->next;
  1422. if (!(u->flags & MASKREC_PERM) && (now >= u->expire)) {
  1423. putlog(LOG_MISC, "*", "%s %s %s %s (%s)", BANS_NOLONGER,
  1424. u->mask, MISC_ONLOCALE, chan->dname, MISC_EXPIRED);
  1425. for (b = chan->channel.ban; b->mask[0]; b = b->next)
  1426. if (!rfc_casecmp(b->mask, u->mask) &&
  1427. expired_mask(chan, b->who) && b->timer != now) {
  1428. add_mode(chan, '-', 'b', u->mask);
  1429. b->timer = now;
  1430. }
  1431. u_delban(chan, u->mask, 1);
  1432. }
  1433. }
  1434. }
  1435. }
  1436. #ifdef S_IRCNET
  1437. /* Check for expired timed-exemptions
  1438. */
  1439. static void check_expired_exempts(void)
  1440. {
  1441. maskrec *u, *u2;
  1442. struct chanset_t *chan;
  1443. masklist *b, *e;
  1444. int match;
  1445. if (!use_exempts)
  1446. return;
  1447. for (u = global_exempts; u; u = u2) {
  1448. u2 = u->next;
  1449. if (!(u->flags & MASKREC_PERM) && (now >= u->expire)) {
  1450. putlog(LOG_MISC, "*", "%s %s (%s)", EXEMPTS_NOLONGER,
  1451. u->mask, MISC_EXPIRED);
  1452. for (chan = chanset; chan; chan = chan->next) {
  1453. match = 0;
  1454. b = chan->channel.ban;
  1455. while (b->mask[0] && !match) {
  1456. if (wild_match(b->mask, u->mask) ||
  1457. wild_match(u->mask, b->mask))
  1458. match = 1;
  1459. else
  1460. b = b->next;
  1461. }
  1462. if (match)
  1463. putlog(LOG_MISC, chan->dname,
  1464. "Exempt not expired on channel %s. Ban still set!",
  1465. chan->dname);
  1466. else
  1467. for (e = chan->channel.exempt; e->mask[0]; e = e->next)
  1468. if (!rfc_casecmp(e->mask, u->mask) &&
  1469. expired_mask(chan, e->who) && e->timer != now) {
  1470. add_mode(chan, '-', 'e', u->mask);
  1471. e->timer = now;
  1472. }
  1473. }
  1474. u_delexempt(NULL, u->mask,1);
  1475. }
  1476. }
  1477. /* Check for specific channel-domain exempts expiring */
  1478. for (chan = chanset; chan; chan = chan->next) {
  1479. for (u = chan->exempts; u; u = u2) {
  1480. u2 = u->next;
  1481. if (!(u->flags & MASKREC_PERM) && (now >= u->expire)) {
  1482. match=0;
  1483. b = chan->channel.ban;
  1484. while (b->mask[0] && !match) {
  1485. if (wild_match(b->mask, u->mask) ||
  1486. wild_match(u->mask, b->mask))
  1487. match=1;
  1488. else
  1489. b = b->next;
  1490. }
  1491. if (match)
  1492. putlog(LOG_MISC, chan->dname,
  1493. "Exempt not expired on channel %s. Ban still set!",
  1494. chan->dname);
  1495. else {
  1496. putlog(LOG_MISC, "*", "%s %s %s %s (%s)", EXEMPTS_NOLONGER,
  1497. u->mask, MISC_ONLOCALE, chan->dname, MISC_EXPIRED);
  1498. for (e = chan->channel.exempt; e->mask[0]; e = e->next)
  1499. if (!rfc_casecmp(e->mask, u->mask) &&
  1500. expired_mask(chan, e->who) && e->timer != now) {
  1501. add_mode(chan, '-', 'e', u->mask);
  1502. e->timer = now;
  1503. }
  1504. u_delexempt(chan, u->mask, 1);
  1505. }
  1506. }
  1507. }
  1508. }
  1509. }
  1510. /* Check for expired timed-invites.
  1511. */
  1512. static void check_expired_invites(void)
  1513. {
  1514. maskrec *u, *u2;
  1515. struct chanset_t *chan;
  1516. masklist *b;
  1517. if (!use_invites)
  1518. return;
  1519. for (u = global_invites; u; u = u2) {
  1520. u2 = u->next;
  1521. if (!(u->flags & MASKREC_PERM) && (now >= u->expire)) {
  1522. putlog(LOG_MISC, "*", "%s %s (%s)", INVITES_NOLONGER,
  1523. u->mask, MISC_EXPIRED);
  1524. for (chan = chanset; chan; chan = chan->next)
  1525. if (!(chan->channel.mode & CHANINV))
  1526. for (b = chan->channel.invite; b->mask[0]; b = b->next)
  1527. if (!rfc_casecmp(b->mask, u->mask) &&
  1528. expired_mask(chan, b->who) && b->timer != now) {
  1529. add_mode(chan, '-', 'I', u->mask);
  1530. b->timer = now;
  1531. }
  1532. u_delinvite(NULL, u->mask,1);
  1533. }
  1534. }
  1535. /* Check for specific channel-domain invites expiring */
  1536. for (chan = chanset; chan; chan = chan->next) {
  1537. for (u = chan->invites; u; u = u2) {
  1538. u2 = u->next;
  1539. if (!(u->flags & MASKREC_PERM) && (now >= u->expire)) {
  1540. putlog(LOG_MISC, "*", "%s %s %s %s (%s)", INVITES_NOLONGER,
  1541. u->mask, MISC_ONLOCALE, chan->dname, MISC_EXPIRED);
  1542. if (!(chan->channel.mode & CHANINV))
  1543. for (b = chan->channel.invite; b->mask[0]; b = b->next)
  1544. if (!rfc_casecmp(b->mask, u->mask) &&
  1545. expired_mask(chan, b->who) && b->timer != now) {
  1546. add_mode(chan, '-', 'I', u->mask);
  1547. b->timer = now;
  1548. }
  1549. u_delinvite(chan, u->mask, 1);
  1550. }
  1551. }
  1552. }
  1553. }
  1554. #endif