Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 9.28 KB | None | 0 0
  1. --- m_listrestrict.c_orig   2018-11-03 17:34:57.072296369 -0000
  2. +++ m_listrestrict.c    2018-11-03 17:35:45.264898467 -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. @@ -102,6 +113,7 @@
  39.     ** Also, parv[0] seems to always be NULL, so better not rely on it fam
  40.     */
  41.     restrictExcept *exEntry; // For iteration yo
  42. +   fakeChannel *fakeChansEntry;
  43.     unsigned short except_connect = 0; // We gottem exception?
  44.     unsigned short except_auth = 0; // Ditt0
  45.  
  46. @@ -131,9 +143,17 @@
  47.             }
  48.         }
  49.     }
  50. +  
  51. +   if(fakeChans){ // we are sending our fake list here, regardless of the notices below
  52. +       sendto_one(sptr, rpl_str(RPL_LISTSTART), me.name, sptr->name);
  53. +       for(fakeChansEntry = fakeChanList; fakeChansEntry; fakeChansEntry = fakeChansEntry->next){
  54. +           sendto_one(cptr, rpl_str(RPL_LIST), me.name, cptr->name, fakeChansEntry->name, fakeChansEntry->users, "[nrt]", fakeChansEntry->topic);
  55. +       }
  56. +       sendto_one(sptr, rpl_str(RPL_LISTEND), me.name, sptr->name);
  57. +   }
  58.  
  59.     // Sanity check + delay check =]
  60. -   if(!except_connect && muhDelay > 0 && sptr->local && TStime() - sptr->local->firsttime < muhDelay) {
  61. +   if(!(authIsEnough && IsLoggedIn(sptr)) && !except_connect && muhDelay > 0 && sptr->local && TStime() - sptr->local->firsttime < muhDelay) {
  62.         sendnotice(sptr, "You have to be connected for at least %d seconds before being able to /%s", muhDelay, OVR_LIST);
  63.         return 0;
  64.     }
  65. @@ -151,6 +171,8 @@
  66.     ConfigEntry *cep, *cep2; // For looping through our bl0cc, nested
  67.     int errors = 0; // Error count
  68.     int i; // iter8or m8
  69. +   unsigned short authIsEnoughSet = 0;
  70. +   unsigned short needAuthSet = 0;
  71.  
  72.     // Since we'll add a new top-level block to unrealircd.conf, need to filter on CONFIG_MAIN lmao
  73.     if(type != CONFIG_MAIN)
  74. @@ -199,6 +221,32 @@
  75.                 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);
  76.                 errors++; // Increment err0r count fam
  77.             }
  78. +           if(atoi(cep->ce_vardata) == 1) needAuthSet = 1;
  79. +           if(authIsEnoughSet == 1 && needAuthSet == 1){
  80. +               config_error("%s:%i: %s has needauth and authisenough options both enabled. Please disable one.", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF);
  81. +               errors++;
  82. +           }
  83. +           continue;
  84. +       }
  85. +      
  86. +       if(!strcmp(cep->ce_varname, "authisenough")) {
  87. +           if(!cep->ce_vardata || (strcmp(cep->ce_vardata, "0") && strcmp(cep->ce_vardata, "1"))) {
  88. +               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);
  89. +               errors++; // Increment err0r count fam
  90. +           }
  91. +           if(atoi(cep->ce_vardata) == 1) authIsEnoughSet = 1;
  92. +           if(authIsEnoughSet == 1 && needAuthSet == 1){
  93. +               config_error("%s:%i: %s has needauth and authisenough options both enabled. Please disable one.", cep->ce_fileptr->cf_filename, cep->ce_varlinenum, MYCONF);
  94. +               errors++;
  95. +           }
  96. +           continue;
  97. +       }
  98. +      
  99. +       if(!strcmp(cep->ce_varname, "fakechans")) {
  100. +           if(!cep->ce_vardata || (strcmp(cep->ce_vardata, "0") && strcmp(cep->ce_vardata, "1"))) {
  101. +               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);
  102. +               errors++; // Increment err0r count fam
  103. +           }
  104.             continue;
  105.         }
  106.  
  107. @@ -227,6 +275,52 @@
  108.             continue;
  109.         }
  110.  
  111. +       // Here comes another nested block =]
  112. +       if(!strcmp(cep->ce_varname, "fakechannel")) {
  113. +           int have_name = 0;
  114. +           // Loop 'em again
  115. +           for(cep2 = cep->ce_entries; cep2; cep2 = cep2->ce_next) {
  116. +               if(!cep2->ce_varname || !cep2->ce_vardata) {
  117. +                   config_error("%s:%i: blank/incomplete %s::fakechannel entry", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
  118. +                   errors++; // Increment err0r count fam
  119. +                   continue; // Next iteration imo tbh
  120. +               }
  121. +
  122. +               if(strcmp(cep2->ce_varname, "name") && strcmp(cep2->ce_varname, "users") && strcmp(cep2->ce_varname, "topic")) {
  123. +                   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
  124. +                   errors++; // Increment err0r count fam
  125. +                   continue; // Next iteration imo tbh
  126. +               }
  127. +
  128. +               if(!strcmp(cep2->ce_varname, "name")){
  129. +                   have_name = 1;
  130. +                   if(cep2->ce_vardata[0] != '#'){
  131. +                       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
  132. +                       errors++;
  133. +                       continue;
  134. +                   }
  135. +                   if(strchr(cep2->ce_vardata, ',') || strchr(cep2->ce_vardata, ' ')){
  136. +                       config_error("%s:%i: invalid %s::fakechannel::name (contains space or comma)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
  137. +                       errors++;
  138. +                       continue;
  139. +                   }
  140. +               }
  141. +               if(!strcmp(cep->ce_varname, "users")) {
  142. +                   if(!cep->ce_vardata || (strcmp(cep->ce_vardata, "0") && strcmp(cep->ce_vardata, "1"))) {
  143. +                       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);
  144. +                       errors++; // Increment err0r count fam
  145. +                   }
  146. +                   continue;
  147. +               }
  148. +           }
  149. +           if(have_name == 0){
  150. +               config_error("%s:%i: invalid %s::fakechannel (must contain a channel name)", cep2->ce_fileptr->cf_filename, cep2->ce_varlinenum, MYCONF); // Rep0t error
  151. +               errors++;
  152. +               continue;
  153. +           }
  154. +           continue;
  155. +       }
  156. +      
  157.         // Anything else is unknown to us =]
  158.         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
  159.     }
  160. @@ -240,6 +334,8 @@
  161.     ConfigEntry *cep, *cep2; // For looping through our bl0cc, nested
  162.     restrictExcept *last = NULL; // Initialise to NULL so the loop requires minimal l0gic
  163.     restrictExcept **exEntry = &exceptList; // Hecks so the ->next chain stays intact
  164. +   fakeChannel **fakeChanEntry = &fakeChanList;
  165. +   fakeChannel *fakeChanLast = NULL;
  166.  
  167.     // Since we'll add a new top-level block to unrealircd.conf, need to filter on CONFIG_MAIN lmao
  168.     if(type != CONFIG_MAIN)
  169. @@ -268,6 +364,16 @@
  170.             needAuth = atoi(cep->ce_vardata);
  171.             continue;
  172.         }
  173. +      
  174. +       if(cep->ce_vardata && !strcmp(cep->ce_varname, "authisenough")) {
  175. +           authIsEnough = atoi(cep->ce_vardata);
  176. +           continue;
  177. +       }
  178. +      
  179. +       if(cep->ce_vardata && !strcmp(cep->ce_varname, "fakechans")) {
  180. +           fakeChans = atoi(cep->ce_vardata);
  181. +           continue;
  182. +       }
  183.  
  184.         if(!strcmp(cep->ce_varname, "exceptions")) {
  185.             // Loop 'em
  186. @@ -305,6 +411,56 @@
  187.             }
  188.             continue;
  189.         }
  190. +      
  191. +       if(!strcmp(cep->ce_varname, "fakechannel")) {
  192. +           // Loop 'em
  193. +          
  194. +           // Allocate mem0ry for the current entry
  195. +           *fakeChanEntry = malloc(sizeof(fakeChannel));
  196. +           (*fakeChanEntry)->next = NULL;
  197. +           (*fakeChanEntry)->users = 2; // let this be default
  198. +           // Premium linked list fam
  199. +           if(fakeChanLast)
  200. +               fakeChanLast->next = *fakeChanEntry;
  201. +
  202. +           fakeChanLast = *fakeChanEntry;
  203. +           fakeChanEntry = &(*fakeChanEntry)->next;
  204. +              
  205. +           for(cep2 = cep->ce_entries; cep2; cep2 = cep2->ce_next) { // loop through parameters of a single fakechan
  206. +              
  207. +               if(!cep2->ce_varname || !cep2->ce_vardata) // Sanity checks imo
  208. +                   continue; // Next iteration imo tbh
  209. +                  
  210. +               if(!strcmp(cep2->ce_varname, "name")){
  211. +                   size_t namelen = sizeof(char) * (strlen(cep2->ce_vardata) + 1);
  212. +                   fakeChanLast->name = malloc(namelen);
  213. +                   strncpy(fakeChanLast->name, cep2->ce_vardata, namelen);
  214. +                   continue;
  215. +               }
  216. +              
  217. +               if(!strcmp(cep2->ce_varname, "users")){
  218. +                   int users = atoi(cep2->ce_vardata);
  219. +                   if(users < 0) users = 2; //something funny happened
  220. +                   fakeChanLast->users = users;
  221. +                   continue;
  222. +               }
  223. +              
  224. +               if(!strcmp(cep2->ce_varname, "topic")){
  225. +                   size_t topiclen = sizeof(char) * (strlen(cep2->ce_vardata) + 1);
  226. +                   fakeChanLast->topic = malloc(topiclen);
  227. +                   strncpy(fakeChanLast->topic, cep2->ce_vardata, topiclen);
  228. +                   continue;
  229. +               }
  230. +           }
  231. +           if(!fakeChanLast->name){ // should not happen!!!!
  232. +               //???
  233. +           }
  234. +           if(!fakeChanLast->topic){ // empty topic is allowed
  235. +               fakeChanLast->topic = malloc(sizeof(char)*1);
  236. +               fakeChanLast->topic[0] = 0;
  237. +           }
  238. +           continue;
  239. +       }
  240.     }
  241.  
  242.     return 1; // We good
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement