Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 12.31 KB | None | 0 0
  1. --- m_listrestrict.c_orig   2018-11-03 17:34:57.072296369 -0000
  2. +++ m_listrestrict.c    2018-11-03 23:18:32.997177692 -0000
  3. @@ -18,6 +18,14 @@
  4.     restrictExcept *next;
  5.  };
  6.  
  7. +typedef struct t_fakechans fakeChannel;
  8. +struct t_fakechans {
  9. +   char *name;
  10. +   int users;
  11. +   char *topic;
  12. +   fakeChannel *next;
  13. +};
  14. +
  15.  // Quality fowod declarations
  16.  static int listrestrict_override(Cmdoverride *ovr, aClient *cptr, aClient *sptr, int parc, char *parv[]);
  17.  int listrestrict_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs);
  18. @@ -28,15 +36,18 @@
  19.  static ModuleInfo *lrestrictMI = NULL; // Store ModuleInfo so we can use it to check for errors in MOD_LOAD
  20.  Cmdoverride *lrestrictOVR; // Pointer to the override we're gonna add
  21.  restrictExcept *exceptList = NULL; // Stores exceptions yo
  22. +fakeChannel *fakeChanList = NULL;
  23.  
  24.  // Deez defaults
  25.  int muhDelay = 0; // Default to off yo
  26.  unsigned short needAuth = 0; // Must be identified w/ NickServ
  27. +unsigned short fakeChans = 0;
  28. +unsigned short authIsEnough = 0;
  29.  
  30.  // Dat dere module header
  31.  ModuleHeader MOD_HEADER(m_listrestrict) = {
  32.     "m_listrestrict", // Module name
  33. -   "$Id: v1.02 2017/09/02 Gottem$", // Version
  34. +   "$Id: v1.03 2018/11/03 Gottem/k4be$", // Version
  35.     "Impose certain restrictions on /LIST usage", // Description
  36.     "3.2-b8-1", // Modversion, not sure wat do
  37.     NULL
  38. @@ -80,10 +91,23 @@
  39.         restrictExcept *exEntry;
  40.         while((exEntry = exceptList) != NULL) {
  41.             exceptList = exceptList->next;
  42. +           if(exEntry->mask) free(exEntry->mask);
  43.             free(exEntry);
  44.         }
  45.         exceptList = NULL;
  46.     }
  47. +  
  48. +   if(fakeChanList) {
  49. +       // This shit is a bit convoluted to prevent memory issues obv famalmalmalmlmalm
  50. +       fakeChannel *fakeChanEntry;
  51. +       while((fakeChanEntry = fakeChanList) != NULL) {
  52. +           fakeChanList = fakeChanList->next;
  53. +           if(fakeChanEntry->name) free(fakeChanEntry->name);
  54. +           if(fakeChanEntry->topic) free(fakeChanEntry->topic);
  55. +           free(fakeChanEntry);
  56. +       }
  57. +       fakeChanList = NULL;
  58. +   }
  59.  
  60.     return MOD_SUCCESS; // We good
  61.  }
  62. @@ -102,13 +126,16 @@
  63.     ** Also, parv[0] seems to always be NULL, so better not rely on it fam
  64.     */
  65.     restrictExcept *exEntry; // For iteration yo
  66. +   fakeChannel *fakeChansEntry;
  67.     unsigned short except_connect = 0; // We gottem exception?
  68.     unsigned short except_auth = 0; // Ditt0
  69. +   unsigned short except_fakelist = 0;
  70.  
  71.     // Checkem exceptions bro
  72.     if(!MyConnect(sptr) || !IsPerson(sptr) || IsOper(sptr) || IsULine(sptr)) { // Default set lel
  73.         except_connect = 1;
  74.         except_auth = 1;
  75. +       except_fakelist = 1;
  76.     }
  77.     else { // Not an oper/U:Line/server, checkem whitelist (if ne)
  78.         for(exEntry = exceptList; exEntry; exEntry = exEntry->next) {
  79. @@ -124,6 +151,9 @@
  80.                     case 'c':
  81.                         except_connect = 1;
  82.                         break;
  83. +                   case 'f':
  84. +                       except_fakelist = 1;
  85. +                       break;
  86.                     default:
  87.                         break;
  88.                 }
  89. @@ -131,16 +161,29 @@
  90.             }
  91.         }
  92.     }
  93. +  
  94. +   if(authIsEnough && IsLoggedIn(sptr)) except_connect = 1; // do not check time when user already identified
  95. +
  96. +   int delayF = !except_connect && muhDelay > 0 && (sptr->local && TStime() - sptr->local->firsttime < muhDelay); // Sanity check + delay check =]
  97. +   int authF = !except_auth && needAuth && !IsLoggedIn(sptr); // Need identified check ;];;]
  98. +
  99. +   if(fakeChans && !except_fakelist && (delayF || authF)) {
  100. +       sendto_one(sptr, rpl_str(RPL_LISTSTART), me.name, sptr->name);
  101. +       for(fakeChansEntry = fakeChanList; fakeChansEntry; fakeChansEntry = fakeChansEntry->next){
  102. +           sendto_one(cptr, rpl_str(RPL_LIST), me.name, cptr->name, fakeChansEntry->name, fakeChansEntry->users, "[+ntr]", fakeChansEntry->topic);
  103. +       }
  104. +       sendto_one(sptr, rpl_str(RPL_LISTEND), me.name, sptr->name);
  105. +   }
  106.  
  107. -   // Sanity check + delay check =]
  108. -   if(!except_connect && muhDelay > 0 && sptr->local && TStime() - sptr->local->firsttime < muhDelay) {
  109. +   if(delayF) {
  110.         sendnotice(sptr, "You have to be connected for at least %d seconds before being able to /%s", muhDelay, OVR_LIST);
  111. +       if(fakeChans && !except_fakelist) sendnotice(sptr, "Please ignore the fake /%s output above.", OVR_LIST);
  112.         return 0;
  113.     }
  114.  
  115. -   // Need identified check ;];;]
  116. -   if(!except_auth && needAuth && !IsLoggedIn(sptr)) {
  117. +   if(authF) {
  118.         sendnotice(sptr, "You have to be identified with services before being able to /%s", OVR_LIST);
  119. +       if(fakeChans && !except_fakelist) sendnotice(sptr, "Please ignore the fake /%s output above.", OVR_LIST);
  120.         return 0;
  121.     }
  122.  
  123. @@ -201,6 +244,22 @@
  124.             }
  125.             continue;
  126.         }
  127. +      
  128. +       if(!strcmp(cep->ce_varname, "authisenough")) {
  129. +           if(!cep->ce_vardata || (strcmp(cep->ce_vardata, "0") && strcmp(cep->ce_vardata, "1"))) {
  130. +               config_error("%s:%i: %s::%s must be either 0 or 1 fam", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF, cep->ce_varname);
  131. +               errors++; // Increment err0r count fam
  132. +           }
  133. +           continue;
  134. +       }
  135. +      
  136. +       if(!strcmp(cep->ce_varname, "fakechans")) {
  137. +           if(!cep->ce_vardata || (strcmp(cep->ce_vardata, "0") && strcmp(cep->ce_vardata, "1"))) {
  138. +               config_error("%s:%i: %s::%s must be either 0 or 1 fam", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF, cep->ce_varname);
  139. +               errors++; // Increment err0r count fam
  140. +           }
  141. +           continue;
  142. +       }
  143.  
  144.         // Here comes a nested block =]
  145.         if(!strcmp(cep->ce_varname, "exceptions")) {
  146. @@ -212,8 +271,8 @@
  147.                     continue; // Next iteration imo tbh
  148.                 }
  149.  
  150. -               if(strcmp(cep2->ce_varname, "connect") && strcmp(cep2->ce_varname, "auth") && strcmp(cep2->ce_varname, "all")) {
  151. -                   config_error("%s:%i: invalid %s::exceptions type (must be one of: connect, auth, all)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
  152. +               if(strcmp(cep2->ce_varname, "connect") && strcmp(cep2->ce_varname, "auth") && strcmp(cep2->ce_varname, "all") && strcmp(cep2->ce_varname, "fake")) {
  153. +                   config_error("%s:%i: invalid %s::exceptions type (must be one of: connect, auth, fake, all)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
  154.                     errors++; // Increment err0r count fam
  155.                     continue; // Next iteration imo tbh
  156.                 }
  157. @@ -227,10 +286,68 @@
  158.             continue;
  159.         }
  160.  
  161. +       // Here comes another nested block =]
  162. +       if(!strcmp(cep->ce_varname, "fakechannel")) {
  163. +           int have_name = 0;
  164. +           // Loop 'em again
  165. +           for(cep2 = cep->ce_entries; cep2; cep2 = cep2->ce_next) {
  166. +               if(!cep2->ce_varname || !cep2->ce_vardata) {
  167. +                   config_error("%s:%i: blank/incomplete %s::fakechannel entry", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
  168. +                   errors++; // Increment err0r count fam
  169. +                   continue; // Next iteration imo tbh
  170. +               }
  171. +
  172. +               if(strcmp(cep2->ce_varname, "name") && strcmp(cep2->ce_varname, "users") && strcmp(cep2->ce_varname, "topic")) {
  173. +                   config_error("%s:%i: invalid %s::fakechannel entry (must be one of: name, users, topic)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
  174. +                   errors++; // Increment err0r count fam
  175. +                   continue; // Next iteration imo tbh
  176. +               }
  177. +
  178. +               if(!strcmp(cep2->ce_varname, "name")){
  179. +                   have_name = 1;
  180. +                   if(cep2->ce_vardata[0] != '#'){
  181. +                       config_error("%s:%i: invalid %s::fakechannel::name (channel name must start with a #)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
  182. +                       errors++;
  183. +                       continue;
  184. +                   }
  185. +                   if(strchr(cep2->ce_vardata, ',') || strchr(cep2->ce_vardata, ' ')){
  186. +                       config_error("%s:%i: invalid %s::fakechannel::name (contains space or comma)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
  187. +                       errors++;
  188. +                       continue;
  189. +                   }
  190. +                   if(strlen(cep2->ce_vardata) > CHANNELLEN){
  191. +                       config_error("%s:%i: invalid %s::fakechannel::name (too long). Max length is %i characters.", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF, CHANNELLEN); // Rep0t error
  192. +                       errors++;
  193. +                       continue;
  194. +                   }
  195. +               }
  196. +               if(!strcmp(cep2->ce_varname, "users")) {
  197. +                   if(!cep2->ce_vardata) {
  198. +                       config_error("%s:%i: %s::%s must be an integer of >= 0", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF, cep->ce_varname);
  199. +                       errors++; // Increment err0r count fam
  200. +                   }
  201. +                   for(i = 0; cep2->ce_vardata[i]; i++) {
  202. +                       if(!isdigit(cep2->ce_vardata[i])) {
  203. +                           config_error("%s:%i: %s::%s must be an integer of >= 0", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF, cep->ce_varname);
  204. +                           errors++; // Increment err0r count fam
  205. +                           break;
  206. +                       }
  207. +                   }
  208. +                   continue;
  209. +               }
  210. +           }
  211. +           if(have_name == 0){
  212. +               config_error("%s:%i: invalid %s::fakechannel (must contain a channel name)", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF); // Rep0t error
  213. +               errors++;
  214. +               continue;
  215. +           }
  216. +           continue;
  217. +       }
  218. +      
  219.         // Anything else is unknown to us =]
  220.         config_warn("%s:%i: unknown item %s::%s", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF, cep->ce_varname); // So display just a warning
  221.     }
  222. -
  223. +  
  224.     *errs = errors;
  225.     return errors ? -1 : 1; // Returning 1 means "all good", -1 means we shat our panties
  226.  }
  227. @@ -240,6 +357,8 @@
  228.     ConfigEntry *cep, *cep2; // For looping through our bl0cc, nested
  229.     restrictExcept *last = NULL; // Initialise to NULL so the loop requires minimal l0gic
  230.     restrictExcept **exEntry = &exceptList; // Hecks so the ->next chain stays intact
  231. +   fakeChannel **fakeChanEntry = &fakeChanList;
  232. +   fakeChannel *fakeChanLast = NULL;
  233.  
  234.     // Since we'll add a new top-level block to unrealircd.conf, need to filter on CONFIG_MAIN lmao
  235.     if(type != CONFIG_MAIN)
  236. @@ -268,6 +387,16 @@
  237.             needAuth = atoi(cep->ce_vardata);
  238.             continue;
  239.         }
  240. +      
  241. +       if(cep->ce_vardata && !strcmp(cep->ce_varname, "authisenough")) {
  242. +           authIsEnough = atoi(cep->ce_vardata);
  243. +           continue;
  244. +       }
  245. +      
  246. +       if(cep->ce_vardata && !strcmp(cep->ce_varname, "fakechans")) {
  247. +           fakeChans = atoi(cep->ce_vardata);
  248. +           continue;
  249. +       }
  250.  
  251.         if(!strcmp(cep->ce_varname, "exceptions")) {
  252.             // Loop 'em
  253. @@ -275,7 +404,6 @@
  254.                 if(!cep2->ce_varname || !cep2->ce_vardata) // Sanity checks imo
  255.                     continue; // Next iteration imo tbh
  256.  
  257. -               size_t masklen = sizeof(char) * (strlen(cep2->ce_vardata) + 1); // Get size
  258.                 char etype; // Wat type etc
  259.  
  260.                 if(!strcmp(cep2->ce_varname, "all"))
  261. @@ -284,17 +412,18 @@
  262.                     etype = 'a';
  263.                 else if(!strcmp(cep2->ce_varname, "connect"))
  264.                     etype = 'c';
  265. +               else if(!strcmp(cep2->ce_varname, "fake"))
  266. +                   etype = 'f';
  267.  
  268.                 // Allocate mem0ry for the current entry
  269.                 *exEntry = malloc(sizeof(restrictExcept));
  270.  
  271.                 // Allocate/initialise shit here
  272. -               (*exEntry)->mask = malloc(masklen);
  273. +               (*exEntry)->mask = strdup(cep2->ce_vardata);
  274.                 (*exEntry)->next = NULL;
  275.  
  276.                 // Copy that shit fam
  277.                 (*exEntry)->type = etype;
  278. -               strncpy((*exEntry)->mask, cep2->ce_vardata, masklen);
  279.  
  280.                 // Premium linked list fam
  281.                 if(last)
  282. @@ -305,6 +434,53 @@
  283.             }
  284.             continue;
  285.         }
  286. +      
  287. +       if(!strcmp(cep->ce_varname, "fakechannel")) {
  288. +           // Loop 'em
  289. +          
  290. +           // Allocate mem0ry for the current entry
  291. +           *fakeChanEntry = malloc(sizeof(fakeChannel));
  292. +           (*fakeChanEntry)->next = NULL;
  293. +           (*fakeChanEntry)->users = 2; // let this be default
  294. +           // Premium linked list fam
  295. +           if(fakeChanLast)
  296. +               fakeChanLast->next = *fakeChanEntry;
  297. +
  298. +           fakeChanLast = *fakeChanEntry;
  299. +           fakeChanEntry = &(*fakeChanEntry)->next;
  300. +              
  301. +           for(cep2 = cep->ce_entries; cep2; cep2 = cep2->ce_next) { // loop through parameters of a single fakechan
  302. +              
  303. +               if(!cep2->ce_varname || !cep2->ce_vardata) // Sanity checks imo
  304. +                   continue; // Next iteration imo tbh
  305. +                  
  306. +               if(!strcmp(cep2->ce_varname, "name")){
  307. +                   fakeChanLast->name = strdup(cep2->ce_vardata);
  308. +                   clean_channelname(fakeChanLast->name);
  309. +                   continue;
  310. +               }
  311. +              
  312. +               if(!strcmp(cep2->ce_varname, "users")){
  313. +                   int users = atoi(cep2->ce_vardata);
  314. +                   if(users < 0) users = 2; //something funny happened
  315. +                   fakeChanLast->users = users;
  316. +                   continue;
  317. +               }
  318. +              
  319. +               if(!strcmp(cep2->ce_varname, "topic")){
  320. +                   if(strlen(cep2->ce_vardata) <= 0) continue;
  321. +                   fakeChanLast->topic = strdup(cep2->ce_vardata);
  322. +                   continue;
  323. +               }
  324. +           }
  325. +           if(!fakeChanLast->name){ // should not happen!!!!
  326. +               //???
  327. +           }
  328. +           if(!fakeChanLast->topic){ // empty topic is allowed
  329. +               fakeChanLast->topic = strdup("DO NOT JOIN");
  330. +           }
  331. +           continue;
  332. +       }
  333.     }
  334.  
  335.     return 1; // We good
  336. @@ -316,3 +492,4 @@
  337.     needAuth = 0;
  338.     return HOOK_CONTINUE;
  339.  }
  340. +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement