16 Kasım 2023, 02:13 | #1 |
| Oper/Admin/Root/Owner ekleme Modulu Oper/Admin/Root/Owner ekleme Modulu HTML-Kodu: /* /* * ================================================================= * Dosya Adi: OperEkle.c * ================================================================= */ #include "config.h" #include "struct.h" #include "common.h" #include "sys.h" #include "numeric.h" #include "msg.h" #include "channel.h" #include <time.h> #include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef _WIN32 #include <io.h> #endif #include <fcntl.h> #include "h.h" #ifdef STRIPBADWORDS #include "badwords.h" #endif #ifdef _WIN32 #include "version.h" #endif typedef struct _conf_operflag OperFlag; typedef struct _blocklist BlockList; typedef struct _operpass OperPass; typedef struct _cmdinfo CmdInfo; struct _conf_operflag { long flag; char *name; }; struct _operpass { OperPass *prev, *next; aClient *cptr; }; struct _blocklist { BlockList *prev, *next; ConfigItem_oper *oper; }; struct _cmdinfo { char *msg, *tok; iFP func; Command *cmd; }; extern void sendto_one(aClient *to, char *pattern, ...); extern void sendto_serv_butone_token(aClient *one, char *prefix, char *command, char *token, char *pattern, ...); extern OperFlag *config_binary_flags_search(OperFlag *table, char *cmd, int size); extern anAuthStruct AuthTypes[]; #define OPER_DB "yetki.db" #define OPER_DB_VERSION 1001 #define ircstrdup(x,y) if (x) MyFree(x); if (!y) x = NULL; else x = strdup(y) #define ircfree(x) if (x) MyFree(x); x = NULL #define IsParam(x) (parc > (x) && !BadPtr(parv[(x)])) #define IsNotParam(x) (parc <= (x) || BadPtr(parv[(x)])) #define DelCommand(x) if (x) CommandDel(x); x = NULL #define DelHook(x) if (x) HookDel(x); x = NULL /* Helpful macros to make the code a bit more readable */ #define FromLoop(counter, list) \ for (counter = (ConfigItem_oper_from *) list; \ counter; counter = (ConfigItem_oper_from *) (counter)->next) #define FromLoop2(counter, list, next) \ for (counter = (ConfigItem_oper_from *) list; \ counter; counter = (ConfigItem_oper_from *) next) #define NewFrom \ (ConfigItem_oper_from *) MyMallocEx(sizeof(ConfigItem_oper_from)) #define OF_NAME 0x01 #define OF_SWHOIS 0x02 #define OF_SNOMASK 0x04 #define OF_MAXLOGINS 0x08 #define OF_PASSWORD 0x10 #define OF_USERHOST 0x20 #define OF_FLAGS 0x40 #define OF_CLASS 0x80 #define OF_TABLESIZE sizeof(_OperFields)/sizeof(_OperFields[0]) static CMD_FUNC(m_addoper); static CMD_FUNC(m_addroper); static CMD_FUNC(m_addgoper); static CMD_FUNC(m_deloper); static CMD_FUNC(m_delroper); static CMD_FUNC(m_delgoper); static CMD_FUNC(m_modoper); static CMD_FUNC(m_modroper); static CMD_FUNC(m_modgoper); static CMD_FUNC(m_confoper); static CMD_FUNC(m_confroper); static CMD_FUNC(m_masterpass); static Command *AddCommand(Module *module, char *msg, char *token, iFP func); static int add_commands(Module *module); static void del_commands(); static int cb_config_rehash(); static int cb_rehash_complete(); static int cb_test(ConfigFile *, ConfigEntry *, int, int *); static int cb_conf(ConfigFile *, ConfigEntry *, int); static int cb_stats(aClient *sptr, char *stats); static int cb_quit(aClient *, char *); static int save_opers(); static int load_opers(); static void free_extopers(); static void free_operpasslist(); static OperPass *FindOperPass(aClient *cptr); static BlockList *FindExternalOper(ConfigItem_oper *oper); static Hook *HookConfTest, *HookConfRun, *HookStats; static Hook *HookQuit; static Hook *HookConfRehash; static Hook *HookRehashDone; static anAuthStruct *opers_auth; static BlockList *ExternalOpers; static OperPass *OperPassList; static char buf[1024]; static unsigned oper_db_version = OPER_DB_VERSION; static CmdInfo OperCommands[] = { { "operekle", "OA", m_addoper, NULL }, { "ekle1sdfsd", "ORA", m_addroper, NULL }, { "addgoper", "OGA", m_addgoper, NULL }, { "opersil", "OD", m_deloper, NULL }, { "sil1sd", "ORD", m_delroper, NULL }, { "delgoper", "OGD", m_delgoper, NULL }, { "fsd1", "OM", m_modoper, NULL }, { "fsd2", "ORM", m_modroper, NULL }, { "fsd3", "OGM", m_modgoper, NULL }, { "operbak", "OC", m_confoper, NULL }, { "fsd5", "ORC", m_confroper, NULL }, { "masterpass", "MP", m_masterpass, NULL }, { NULL, NULL, NULL, NULL } }; static int _OldOperFlags[] = { OFLAG_LOCAL, 'o', OFLAG_GLOBAL, 'O', OFLAG_REHASH, 'r', OFLAG_DIE, 'D', OFLAG_RESTART, 'R', OFLAG_HELPOP, 'h', OFLAG_GLOBOP, 'g', OFLAG_WALLOP, 'w', OFLAG_LOCOP, 'l', OFLAG_LROUTE, 'c', OFLAG_GROUTE, 'L', OFLAG_LKILL, 'k', OFLAG_GKILL, 'K', OFLAG_KLINE, 'b', OFLAG_UNKLINE, 'B', OFLAG_LNOTICE, 'n', OFLAG_GNOTICE, 'G', OFLAG_ADMIN_, 'A', OFLAG_SADMIN_, 'a', OFLAG_NADMIN, 'N', OFLAG_COADMIN, 'C', OFLAG_ROOTADMIN, 'X', OFLAG_SUPERADMIN, 'J', OFLAG_OWNER, 'U', OFLAG_ZLINE, 'z', OFLAG_WHOIS, 'W', OFLAG_HIDE, 'H', OFLAG_TKL, 't', OFLAG_GZL, 'Z', OFLAG_OVERRIDE, 'v', OFLAG_UMODEQ, 'q', OFLAG_DCCDENY, 'd', 0, 0 }; /* This MUST be alphabetized */ static OperFlag _OperFields[] = { { OF_CLASS, "class" }, { OF_FLAGS, "flags" }, { OF_MAXLOGINS, "maxlogins" }, { OF_NAME, "name" }, { OF_PASSWORD, "password" }, { OF_SNOMASK, "snomask" }, { OF_SWHOIS, "swhois" }, { OF_USERHOST, "userhost" }, }; ModuleHeader MOD_HEADER(opers) = { "OperEkle", "Kolayca oper/admin ekleme", "Kolayca oper/admin ekleme", "3.2-b8-1", NULL }; static void InitConf() { opers_auth = NULL; ExternalOpers = NULL; } static void FreeConf() { if (opers_auth) Auth_DeleteAuthStruct(opers_auth); free_extopers(); } DLLFUNC int MOD_TEST(opers)(ModuleInfo *modinfo) { HookConfTest = HookAddEx(modinfo->handle, HOOKTYPE_CONFIGTEST, cb_test); return MOD_SUCCESS; } DLLFUNC int MOD_INIT(opers)(ModuleInfo *modinfo) { #ifndef STATIC_LINKING ModuleSetOptions(modinfo->handle, MOD_OPT_PERM); #endif InitConf(); HookQuit = HookAddEx(modinfo->handle, HOOKTYPE_LOCAL_QUIT, cb_quit); HookConfRehash = HookAddEx(modinfo->handle, HOOKTYPE_REHASH, cb_config_rehash); HookRehashDone = HookAddEx(modinfo->handle, HOOKTYPE_REHASH_COMPLETE, cb_rehash_complete); HookConfRun = HookAddEx(modinfo->handle, HOOKTYPE_CONFIGRUN, cb_conf); HookStats = HookAddEx(modinfo->handle, HOOKTYPE_STATS, cb_stats); return add_commands(modinfo->handle); } DLLFUNC int MOD_LOAD(opers)(int module_load) { load_opers(); return MOD_SUCCESS; } DLLFUNC int MOD_UNLOAD(opers)(int module_unload) { FreeConf(); free_operpasslist(); del_commands(); DelHook(HookStats); DelHook(HookConfRun); DelHook(HookRehashDone); DelHook(HookConfRehash); DelHook(HookQuit); DelHook(HookConfTest); return MOD_SUCCESS; } static Command *AddCommand(Module *module, char *msg, char *token, iFP func) { Command *cmd; if (CommandExists(msg)) { config_error("Bu komut %s zaten kullanilmistir.", msg); return NULL; } if (CommandExists(token)) { config_error("Bu komut %s zaten kullanilmistir.", token); return NULL; } cmd = CommandAdd(module, msg, token, func, MAXPARA, 0); #ifndef STATIC_LINKING if (ModuleGetError(module) != MODERR_NOERROR || !cmd) #else if (!cmd) #endif { #ifndef STATIC_LINKING config_error("Dikkat: islem Basarisizdir. Sonuc: %s: %s", msg, ModuleGetErrorStr(module)); #else config_error("Dikkat: islem Basarisizdir. Sonuc: %s", msg); #endif return NULL; } return cmd; } static int add_commands(Module *module) { CmdInfo *p; int ret = MOD_SUCCESS; for (p = OperCommands; p->msg; p++) { p->cmd = AddCommand(module, p->msg, p->tok, p->func); if (!p->cmd) ret = MOD_FAILED; } return ret; } static void del_commands() { CmdInfo *p; for (p = OperCommands; p->msg; p++) { DelCommand(p->cmd); } } static int cb_config_rehash() { FreeConf(); InitConf(); return 0; } static int cb_rehash_complete() { load_opers(); return 0; } static int cb_quit(aClient *sptr, char *comment) { OperPass *p; for (p = OperPassList; p; p = p->next) if (p->cptr == sptr) break; if (p) { DelListItem(p, OperPassList); MyFree(p); } return 0; } static int cb_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) { int errors = 0; if (type != CONFIG_SET) return 0; if (!strcmp(ce->ce_varname, "master-password")) { if (!ce->ce_vardata) { config_error("%s:%i: set::master-password master sifresini giriniz.", ce->ce_fileptr->cf_filename, ce->ce_varlinenum); errors++; } else if (Auth_CheckError(ce) < 0) errors++; *errs = errors; return errors ? -1 : 1; } else return 0; } static int cb_conf(ConfigFile *cf, ConfigEntry *ce, int type) { if (type != CONFIG_SET) return 0; if (!strcmp(ce->ce_varname, "master-password")) { if (opers_auth) Auth_DeleteAuthStruct(opers_auth); opers_auth = Auth_ConvertConf2AuthStruct(ce); return 1; } return 0; } static int cb_stats(aClient *sptr, char *stats) { if (*stats == 'S') { sendto_one(sptr, ":%s %i %s :master-password: <%s>", me.name, RPL_TEXT, sptr->name, opers_auth ? "hidden" : "none"); } return 0; } static void free_operpasslist() { OperPass *p; ListStruct *next; for (p = OperPassList; p; p = (OperPass *) next) { next = (ListStruct *) p->next; DelListItem(p, OperPassList); MyFree(p); } } static OperPass *FindOperPass(aClient *cptr) { OperPass *p; for (p = OperPassList; p; p = p->next) if (p->cptr == cptr) break; return p; } static void AddOperPass(aClient *cptr) { OperPass *p; p = (OperPass *) MyMalloc(sizeof(OperPass)); p->cptr = cptr; AddListItem(p, OperPassList); } static BlockList *FindExternalOper(ConfigItem_oper *oper) { BlockList *p; for (p = ExternalOpers; p; p = p->next) if (p->oper == oper) break; return p; } static void AddExternalOper(ConfigItem_oper *oper) { BlockList *p; p = (BlockList *) MyMalloc(sizeof(BlockList)); p->oper = oper; AddListItem(p, ExternalOpers); } inline static void DelExternalOper(BlockList *extoper) { DelListItem(extoper, ExternalOpers); MyFree(extoper); } static void free_extopers() { BlockList *p; ListStruct *next; for (p = ExternalOpers; p; p = (BlockList *) next) { next = (ListStruct *) p->next; DelListItem(p, ExternalOpers); MyFree(p); } } // ================================================== ======================= static void free_oper(ConfigItem_oper *oper) { ListStruct *next; ConfigItem_oper_from *from; ircfree(oper->name); ircfree(oper->swhois); ircfree(oper->snomask); Auth_DeleteAuthStruct(oper->auth); FromLoop2(from, oper->from, next) { next = (ListStruct *) from->next; DelListItem(from, oper->from); ircfree(from->name); MyFree(from); } MyFree(oper); } // ================================================== ======================= #ifndef _WIN32 #define OpenFile(fd, file, flags) fd = open(file, flags, S_IRUSR|S_IWUSR) #else #define OpenFile(fd, file, flags) fd = open(file, flags, S_IREAD|S_IWRITE) #endif #define R_SAFE(x) \ do { \ if ((x)) \ { \ close(fd); \ if (oper) \ free_oper(oper); \ config_error("Okunamadi !!! : %s", OPER_DB); \ return -1; \ } \ } while (0) #define RF_SAFE(x) \ do { \ if ((x)) \ { \ close(fd); \ if (oper) \ free_oper(oper); \ ircfree(from); \ config_error("Okunamadi !!! : %s", OPER_DB); \ return -1; \ } \ } while (0) #define W_SAFE(x) \ do { \ if ((x)) \ { \ close(fd); \ config_error("Yazilim Hatasi %s", OPER_DB); \ return -1; \ } \ } while (0) static inline int read_data(int fd, void *buf, size_t count) { if ((size_t) read(fd, buf, count) < count) return -1; return 0; } static inline int write_data(int fd, void *buf, size_t count) { if ((size_t) write(fd, buf, count) < count) return -1; return 0; } static int write_str(int fd, char *x) { size_t count = x ? strlen(x) : 0; if (write_data(fd, &count, sizeof count)) return -1; if (count) { if (write_data(fd, x, sizeof(char) * count)) return -1; } return 0; } static int read_str(int fd, char **x) { size_t count; if (read_data(fd, &count, sizeof count)) return -1; if (!count) { *x = NULL; return 0; } *x = (char *) MyMalloc(sizeof(char) * count + 1); if (read_data(fd, *x, sizeof(char) * count)) { MyFree(*x); *x = NULL; return -1; } (*x)[count] = 0; return 0; } static int save_opers() { ConfigItem_oper *oper; ConfigItem_oper_from *from; int fd; size_t count, fromcount; OpenFile(fd, OPER_DB, O_CREAT | O_WRONLY | O_TRUNC); if (fd == -1) { config_status("Hata: %s %s Dosyasina Yazilamadi.", OPER_DB, strerror(errno)); return -1; } W_SAFE(write_data(fd, &oper_db_version, sizeof oper_db_version)); count = 0; for (oper = conf_oper; oper; oper = (ConfigItem_oper *) oper->next) if (FindExternalOper(oper)) count++; W_SAFE(write_data(fd, &count, sizeof count)); for (oper = conf_oper; oper; oper = (ConfigItem_oper *) oper->next) { if (!FindExternalOper(oper)) continue; W_SAFE(write_str(fd, oper->name)); W_SAFE(write_str(fd, oper->swhois)); W_SAFE(write_str(fd, oper->snomask)); W_SAFE(write_str(fd, oper->auth->data)); W_SAFE(write_data(fd, &oper->auth->type, sizeof oper->auth->type)); W_SAFE(write_str(fd, oper->class->name)); W_SAFE(write_data(fd, &oper->oflags, sizeof oper->oflags)); W_SAFE(write_data(fd, &oper->maxlogins, sizeof oper->maxlogins)); fromcount = 0; FromLoop(from, oper->from) fromcount++; W_SAFE(write_data(fd, &fromcount, sizeof fromcount)); FromLoop(from, oper->from) W_SAFE(write_str(fd, from->name)); } close(fd); return 0; } static int load_opers() { ConfigItem_oper *oper = NULL; ConfigItem_oper_from *from = NULL; char *class; int fd; size_t count, fromcount, i, j; unsigned version; OpenFile(fd, OPER_DB, O_RDONLY); if (fd == -1) { if (errno != ENOENT) config_status("Hata: %s %s Dosyasina Yazilamadi.", OPER_DB, strerror(errno)); return -1; } R_SAFE(read_data(fd, &version, sizeof version)); if (version != oper_db_version) { config_status("File %s has a wrong database version (expected: %u, got: %u)", OPER_DB, oper_db_version, version); close(fd); return -1; } R_SAFE(read_data(fd, &count, sizeof count)); for (i = 1; i <= count; i++) { from = NULL; oper = MyMallocEx(sizeof(ConfigItem_oper)); oper->auth = (anAuthStruct *) MyMallocEx(sizeof(anAuthStruct)); R_SAFE(read_str(fd, &oper->name)); R_SAFE(read_str(fd, &oper->swhois)); R_SAFE(read_str(fd, &oper->snomask)); R_SAFE(read_str(fd, &oper->auth->data)); R_SAFE(read_data(fd, &oper->auth->type, sizeof oper->auth->type)); R_SAFE(read_str(fd, &class)); oper->class = Find_class(class); if (!oper->class) { config_status("Dikkat: '%s' Nickli oper (%s), Hatayi verdi. Bakınız: (%s)", oper->name, class, default_class->name); oper->class = default_class; } ircfree(class); R_SAFE(read_data(fd, &oper->oflags, sizeof oper->oflags)); R_SAFE(read_data(fd, &oper->maxlogins, sizeof oper->maxlogins)); R_SAFE(read_data(fd, &fromcount, sizeof fromcount)); for (j = 1; j <= fromcount; j++) { from = NewFrom; RF_SAFE(read_str(fd, &from->name)); AddListItem(from, oper->from); } if (Find_oper(oper->name)) { char *oldname = oper->name; config_status("Dikkat: Hesap Bloke Edildi. Hesap: '%s', " "Zaten Boyle bi hesap bulunmakta. Hesap: '_%s'", oldname, oldname); oper->name = (char *) MyMallocEx(strlen(oldname) + 2); *oper->name = '_'; strcat(oper->name, oldname); MyFree(oldname); } AddListItem(oper, conf_oper); AddExternalOper(oper); } close(fd); return 0; } // ================================================== ======================= /* * Auth_CheckError2: * makes sure password and authtype are valid */ static int Auth_CheckError2(aClient *sptr, char *password, short type) { #ifdef AUTHENABLE_SSL_CLIENTCERT X509 *x509_filecert = NULL; FILE *x509_f = NULL; #endif switch (type) { #ifdef AUTHENABLE_UNIXCRYPT case AUTHTYPE_UNIXCRYPT: /* If our data is like 1 or none, we just let em through .. */ if (strlen(password) < 2) { sendnotice(sptr, "*** AUTHTYPE_UNIXCRYPT: no salt (crypt strings will always be >2 in length)"); return 0; } break; #endif #ifdef AUTHENABLE_SSL_CLIENTCERT case AUTHTYPE_SSL_CLIENTCERT: if (!(x509_f = fopen(password, "r"))) { sendnotice(sptr, "*** AUTHTYPE_SSL_CLIENTCERT: error opening file %s", password); return 0; } x509_filecert = PEM_read_X509(x509_f, NULL, NULL, NULL); fclose(x509_f); if (!x509_filecert) { sendnotice(sptr, "*** AUTHTYPE_SSL_CLIENTCERT: PEM_read_X509 errored in file %s (format error?)", password); return 0; } X509_free(x509_filecert); break; #endif default: ; } return 1; } /* * Auth_Convert2: * converts password and authtype to anAuthStruct */ static anAuthStruct *Auth_Convert2(char *password, short type) { anAuthStruct *as; as = (anAuthStruct *) MyMalloc(sizeof(anAuthStruct)); as->data = strdup(password); as->type = type; return as; } /* * Auth_FindName: * finds an authentication method name (used by /confoper) */ static char *Auth_FindName(short type) { anAuthStruct *p; for (p = AuthTypes; p->data; p++) if (p->type == type) break; return p->data; } static anAuthStruct *Auth_DoAll(aClient *sptr, char *password, char *authtype) { short type; char *encpass = NULL; if ((type = Auth_FindType(authtype)) == -1) { sendnotice(sptr, "*** %s is not a supported authentication method", authtype); return NULL; } if (!Auth_CheckError2(sptr, password, type)) { /* error message already sent */ return NULL; } if (type == AUTHTYPE_SSL_CLIENTCERT) encpass = password; else if (!(encpass = Auth_Make(type, password))) { sendnotice(sptr, "*** Authentication method %s failed", authtype); return NULL; } return Auth_Convert2(encpass, type); } // ================================================== ======================= static unsigned parse_password(char **authtype, char **password) { char *p; if ((p = strchr(*password, '@'))) { if (p == *password || !p[1]) return 0; *p = 0; *authtype = *password; *password = p+1; } else *authtype = "plain"; return 1; } /* * is_valid_mask: * checks whether a mask is in a correct user@host form * returns NULL on error, otherwise a pointer to '@'. */ static char *is_valid_mask(char *mask) { char *p, *mid; /* '@' */ if (!*mask || (!(mid = strchr(mask, '@')))) return NULL; if (mid == mask || !mid[1]) return NULL; /* username */ if (*mask != '~' && *mask != '*' && *mask != '?' && !isallowed(*mask)) return NULL; for (p = mask + 1; p < mid; p++) if (*p != '*' && *p != '?' && !isallowed(*p)) return NULL; /* hostname */ for (p = mid + 1; *p; p++) if ((*p != '*') && (*p != '?') && (*p != '_') && (*p != '-') && (*p != '.') && (*p != ':') && !isalnum(*p)) return NULL; return mid; } /* * check_all_masks: * Checks all user@host masks for validity in a string separated by * spaces. Returns the first bad mask, or NULL if all masks are valid. */ static char *check_all_masks(char *userhosts) { char *m, *p = NULL; char *str = strdup(userhosts); for (m = strtoken(&p, str, " "); m; m = strtoken(&p, NULL, " ")) if (!is_valid_mask(m)) { strcpy(buf, m); ircfree(str); return buf; } ircfree(str); return NULL; } static long convert_oflags(char *flags) { long oflags = 0; char *m; int *i, flag; for (m = flags; *m; m++) for (i = _OldOperFlags; (flag = *i); i += 2) if (*m == (char)(*(i + 1))) { oflags |= flag; break; } return oflags; } static void add_userhosts(ConfigItem_oper *oper, char *userhosts) { ConfigItem_oper_from *from; char *str = strdup(userhosts); char *tmp, *p = NULL; for (tmp = strtoken(&p, str, " "); tmp; tmp = strtoken(&p, NULL, " ")) { FromLoop(from, oper->from) if (!strcmp(from->name, tmp)) break; if (from) continue; from = NewFrom; from->name = strdup(tmp); AddListItem(from, oper->from); } ircfree(str); } static unsigned has_privileges(aClient *sptr, int remote) { if (!IsPerson(sptr)) return 0; if (!MyConnect(sptr)) return 1; if (opers_auth) { if (!IsAnOper(sptr) || !FindOperPass(sptr)) return 0; } else { if (!IsOper(sptr)) return 0; if (!remote) { if (!IsAdmin(sptr)) return 0; } else { if (!IsNetAdmin(sptr)) return 0; } } return 1; } static int check_target(aClient *cptr, aClient *sptr, char *command, char *token, int global, int parc, char *parv[]) { static char format[] = "%s %s %s %s %s %s %s %s"; int ret = 0; /* parc > 1 */ format[(parc - 1) * 3 - 1] = 0; if (global) sendto_serv_butone_token(cptr, sptr->name, command, token, format, parv[1], parv[2], parv[3], parv[4], parv[5], parv[6], parv[7], parv[8]); else ret = hunt_server_token(cptr, sptr, command, token, format, 1, parc, parv); format[(parc - 1) * 3 - 1] = ' '; return ret; } /* ** ADDOPER/ADDGOPER ADDROPER ** parv[0] = sender prefix sender prefix ** parv[1] = oper name server mask ** parv[2] = oper password oper name ** parv[3] = flags oper password ** parv[4] = class flags ** parv[5] = userhosts class ** parv[6] = userhosts */ static int add_oper(aClient *sptr, char *name, char *password, char *flags, char *classname, char *userhosts) { ConfigItem_oper *oper = NULL; ConfigItem_class *class = NULL; anAuthStruct *auth; char *p, *authtype; if (Find_oper(name)) { sendnotice(sptr, "*** Uyari: %s Zaten Oper Listesinde", name); return 0; } if (!parse_password(&authtype, &password)) { sendnotice(sptr, "*** Lütfen daha Degisik bi sifre bulunuz."); return 0; } if (!(class = Find_class(classname))) { sendnotice(sptr, "*** Uyari: %s Nickli Oper Kullanilmiyor", classname); return 0; } if (userhosts && (p = check_all_masks(userhosts))) { sendnotice(sptr, "*** Uyari: Sebeb: '%s' . Bu sebepten dolayı islem yapilamadi. ", p); return 0; } if (!(auth = Auth_DoAll(sptr, password, authtype))) return 0; oper = MyMallocEx(sizeof(ConfigItem_oper)); oper->name = strdup(name); oper->auth = auth; oper->class = class; oper->oflags = convert_oflags(flags); add_userhosts(oper, userhosts ? userhosts : "*@*"); AddListItem(oper, conf_oper); AddExternalOper(oper); save_opers(); sendnotice(sptr, "*** %s oper listesine eklendi.", name); ircsprintf(buf, "*** [%s] %s nickini oper listesine ekleyen %s (verdigi flag: %s, klas: %s, hostu: %s)", me.name, name, sptr->name, flags, classname, userhosts ? userhosts : "*@*"); sendto_snomask(SNO_EYES, "%s", buf); sendto_serv_butone_token(NULL, me.name, MSG_SENDSNO, TOK_SENDSNO, "e :%s", buf); return 1; } static CMD_FUNC(m_addoper) { if (!has_privileges(sptr, 0)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if (IsNotParam(4)) { sendnotice(sptr, "*** Kullanimi: /ekle <oper-nicki> <oper-sifresi> <flaglari> <klas> [:][<userhost masks>]"); sendnotice(sptr, "*** Alttaki Örnekleri Okuyunuz !!!"); sendnotice(sptr, "*** Ornek1: OwnerAdmin => /ekle Nick şifre OoCAaNUJehgwnGcLkKbBXzZtvqHWr clients"); sendnotice(sptr, "*** Ornek2: RootAdmin => /ekle Nick şifre OoCAaNXhgwnGcLkKbBzZtvqHWr clients"); sendnotice(sptr, "*** Ornek3: SystemAdmin => /ekle Nick şifre OoaArewqgcLkKZNCnGWHvJ clients"); sendnotice(sptr, "*** Ornek4: NetAdmin => /ekle Nick şifre OoawkKbBnCGAreDRhgcLZtGNzvWHe clients"); sendnotice(sptr, "*** Ornek5: NetAdmin => /ekle Nick şifre OoawkKbBnCGAreDRhgcLZtGNzvWHe clients"); sendnotice(sptr, "*** Ornek6: Services Admini => /ekle Nick şifre OoawkKbBnCGArehgcLZtGzvWHe clients"); sendnotice(sptr, "*** Ornek7: Server Admini => /ekle Nick şifre OowkKbBnCGArehgcLZtGzvWHe clients"); sendnotice(sptr, "*** Ornek8: Co Admini => /ekle Nick şifre OowkKbBnCGrehgcLZtGzvWHe clients"); sendnotice(sptr, "*** Ornek9: IRCop => /ekle Nick şifre OowkKbBnGrehgcLZtGzvWHe clients"); return 0; } add_oper(sptr, parv[1], parv[2], parv[3], parv[4], IsParam(5) ? parv[5] : NULL); return 0; } static CMD_FUNC(m_addroper) { if (!has_privileges(sptr, 1)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if (IsNotParam(5)) { sendnotice(sptr, "*** Usage: /addroper <servermask> <name> [<auth-type>@]<password> <flags> <class> [:][<userhost masks>]"); sendnotice(sptr, "*** Examples: /addroper irc.server.com newlogin newpass NDRztZWHv clients"); sendnotice(sptr, "*** /addroper server2.* newlogin crypt@newpass NDRztZWHv clients :*@host1.* *@host2.*"); return 0; } if (check_target(cptr, sptr, "ADDROPER", "ORA", 0, parc, parv) == HUNTED_ISME) { add_oper(sptr, parv[2], parv[3], parv[4], parv[5], IsParam(6) ? parv[6] : NULL); } return 0; } static CMD_FUNC(m_addgoper) { if (!has_privileges(sptr, 1)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if (IsNotParam(4)) { sendnotice(sptr, "*** Usage: /addgoper <name> [<auth-type>@]<password> <flags> <class> [:][<userhost masks>]"); sendnotice(sptr, "*** Examples: /addgoper newlogin newpass NDRztZWHv clients"); sendnotice(sptr, "*** /addgoper newlogin crypt@newpass NDRztZWHv clients :*@host1.* *@host2.*"); return 0; } check_target(cptr, sptr, "ADDGOPER", "OGA", 1, parc, parv); add_oper(sptr, parv[1], parv[2], parv[3], parv[4], IsParam(5) ? parv[5] : NULL); return 0; } /* ** DELOPER/DELGOPER DELROPER ** parv[0] = sender prefix sender prefix ** parv[1] = oper name server mask ** parv[2] = oper name */ static int del_oper(aClient *sptr, char *login) { ConfigItem_oper *oper; BlockList *extoper; if (!(oper = Find_oper(login))) { sendnotice(sptr, "*** Oper %s does not exist", login); return 0; } if (!(extoper = FindExternalOper(oper))) { sendnotice(sptr, "*** Oper %s is not present in the external O:Line database", login); return 0; } DelListItem(oper, conf_oper); DelExternalOper(extoper); free_oper(oper); save_opers(); sendnotice(sptr, "*** %s in Operligi Silindi. ", login); ircsprintf(buf, "*** [%s] %s nickinin operini silen kisi: %s", me.name, login, sptr->name); sendto_snomask(SNO_EYES, "%s", buf); sendto_serv_butone_token(NULL, me.name, MSG_SENDSNO, TOK_SENDSNO, "e :%s", buf); return 0; } static CMD_FUNC(m_deloper) { if (!has_privileges(sptr, 0)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if (IsNotParam(1)) { sendnotice(sptr, "*** Kullanimi: /opersil <oper-nicki>"); sendnotice(sptr, "*** Ornek: /opersil Nick"); sendnotice(sptr, "*** şeklinde kişinin operini silebilirsiniz."); return 0; } del_oper(sptr, parv[1]); return 0; } static CMD_FUNC(m_delroper) { if (!has_privileges(sptr, 1)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return -1; } if (IsNotParam(2)) { sendnotice(sptr, "*** Usage: /delroper <servermask> <name>"); return 0; } if (check_target(cptr, sptr, "DELROPER", "ORD", 0, parc, parv) == HUNTED_ISME) del_oper(sptr, parv[2]); return 0; } static CMD_FUNC(m_delgoper) { if (!has_privileges(sptr, 1)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return -1; } if (IsNotParam(1)) { sendnotice(sptr, "*** Usage: /delgoper <name>"); return 0; } check_target(cptr, sptr, "DELGOPER", "OGD", 1, parc, parv); del_oper(sptr, parv[1]); return 0; } /* ** MODOPER/MODGOPER MODROPER ** parv[0] = sender prefix sender prefix ** parv[1] = oper name server mask ** parv[2] = option oper name ** parv[3] = value option ** parv[4] = encryption type value ** parv[5] = encryption type */ #define CHECKVALUE \ if (!value) \ { \ sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), \ me.name, sptr->name, cmd); \ return 0; \ } static int mod_oper(aClient *sptr, char *cmd, char *name, char *option, char *value, char *enctype) { ConfigItem_oper *oper; OperFlag *of; if (!(of = config_binary_flags_search(_OperFields, option, OF_TABLESIZE))) { sendnotice(sptr, "*** Invalid option %s", option); return 0; } if (!(oper = Find_oper(name))) { sendnotice(sptr, "*** Oper %s does not exist", name); return 0; } if (!FindExternalOper(oper)) { sendnotice(sptr, "*** Oper %s is not present in the external O:Line database", name); return 0; } switch (of->flag) { /* name */ case OF_NAME: { CHECKVALUE if (strchr(value, SPACE)) { sendnotice(sptr, "*** Oper names may not contain spaces"); return 0; } if (Find_oper(value)) { sendnotice(sptr, "*** Oper %s already exists", value); return 0; } ircfree(oper->name); oper->name = strdup(value); ircsprintf(buf, "%s changed the name of oper %s to %s", sptr->name, name, value); break; } /* swhois */ case OF_SWHOIS: { ircfree(oper->swhois); if (value) { oper->swhois = strdup(value); ircsprintf(buf, "%s changed the SWHOIS information for oper %s to %s", sptr->name, name, value); } else ircsprintf(buf, "%s removed the SWHOIS information from oper %s", sptr->name, name); break; } /* maxlogins */ case OF_MAXLOGINS: { oper->maxlogins = (value ? atoi(value) : 0); ircsprintf(buf, "%s changed the number of max logins for oper %s to %d", sptr->name, name, oper->maxlogins); break; } /* class */ case OF_CLASS: { ConfigItem_class *class; CHECKVALUE if (!(class = Find_class(value))) { sendnotice(sptr, "*** Unknown class %s", value); return 0; } oper->class = class; ircsprintf(buf, "%s changed the connection class of %s to %s", sptr->name, name, value); break; } /* snomask */ case OF_SNOMASK: { if (value) { if (strchr(value, SPACE)) { sendnotice(sptr, "*** Snomasks may not contain spaces"); return 0; } } ircfree(oper->snomask); if (value) { oper->snomask = strdup(value); ircsprintf(buf, "%s changed the snomask of oper %s to %s", sptr->name, name, value); } else ircsprintf(buf, "%s cleared the snomask of oper %s", sptr->name, name); break; } /* userhost */ case OF_USERHOST: { unsigned add = 1; ConfigItem_oper_from *from; CHECKVALUE if (strchr(value, SPACE)) { sendnotice(sptr, "*** Userhosts may not contain spaces"); return 0; } if (*value == '-') { add = 0; value++; } else if (*value == '+') value++; if (add && !is_valid_mask(value)) { sendnotice(sptr, "*** Bad mask '%s'", value); return 0; } FromLoop(from, oper->from) if (!strcmp(from->name, value)) break; if (add) { if (from) { sendnotice(sptr, "*** Mask %s already added", value); return 0; } from = NewFrom; from->name = strdup(value); AddListItem(from, oper->from); ircsprintf(buf, "%s added userhost '%s' for oper %s", sptr->name, value, name); } else /* del */ { if (!from) { sendnotice(sptr, "*** Mask %s not found", value); return 0; } ircfree(from->name); DelListItem(from, oper->from); MyFree(from); /* add mask *@* if oper->from is NULL */ if (!oper->from) { from = NewFrom; from->name = strdup("*@*"); AddListItem(from, oper->from); } ircsprintf(buf, "%s removed userhost '%s' from oper %s", sptr->name, value, name); } break; } /* flags */ case OF_FLAGS: { CHECKVALUE oper->oflags = convert_oflags(value); ircsprintf(buf, "%s changed the flags of oper %s to %s", sptr->name, name, oflagstr(oper->oflags)); break; } /* password */ case OF_PASSWORD: { anAuthStruct *auth; char *authtype; CHECKVALUE if (enctype) { authtype = value; value = enctype; } else authtype = "plain"; if (strchr(value, SPACE)) { sendnotice(sptr, "*** Passwords may not contain spaces"); return 0; } if (!(auth = Auth_DoAll(sptr, value, authtype))) return 0; Auth_DeleteAuthStruct(oper->auth); oper->auth = auth; ircsprintf(buf, "%s set a new password for oper %s", sptr->name, name); break; } } save_opers(); sendnotice(sptr, "*** Oper %s modified succesfully", name); sendto_snomask(SNO_EYES, "*** [%s] %s", me.name, buf); sendto_serv_butone_token(NULL, me.name, MSG_SENDSNO, TOK_SENDSNO, "e :*** [%s] %s", me.name, buf); return 0; } static CMD_FUNC(m_modoper) { if (!has_privileges(sptr, 0)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if (IsNotParam(2)) { sendnotice(sptr, "*** Usage: /modoper <name> name|class|flags <value>"); sendnotice(sptr, "*** /modoper <name> swhois|snomask|maxlogins [:][<value>]"); sendnotice(sptr, "*** /modoper <name> password [<auth method>] <password>"); sendnotice(sptr, "*** /modoper <name> userhost +|-<mask>"); sendnotice(sptr, "*** Examples: /modoper someone snomask cFfkejvGq"); sendnotice(sptr, "*** /modoper someone swhois :This is the new swhois info"); sendnotice(sptr, "*** /modoper someone password crypt newpass"); return 0; } mod_oper(sptr, "MODOPER", parv[1], parv[2], IsParam(3) ? parv[3] : NULL, IsParam(4) ? parv[4] : NULL); return 0; } static CMD_FUNC(m_modroper) { if (!has_privileges(sptr, 1)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if (IsNotParam(3)) { sendnotice(sptr, "*** Usage: /modroper <servermask> <name> name|class|flags <value>"); sendnotice(sptr, "*** /modroper <servermask> <name> swhois|snomask|maxlogins [:][<value>]"); sendnotice(sptr, "*** /modroper <servermask> <name> password [<auth method>] <password>"); sendnotice(sptr, "*** /modroper <servermask> <name> userhost +|-<mask>"); sendnotice(sptr, "*** Examples: /modroper server2.* someone snomask cFfkejvGq"); sendnotice(sptr, "*** /modroper irc.* someone swhois :This is the new swhois info"); sendnotice(sptr, "*** /modroper server1.* someone password crypt newpass"); return 0; } if (check_target(cptr, sptr, "MODROPER", "ORM", 0, parc, parv) == HUNTED_ISME) { mod_oper(sptr, "MODROPER", parv[2], parv[3], IsParam(4) ? parv[4] : NULL, IsParam(5) ? parv[5] : NULL); } return 0; } static CMD_FUNC(m_modgoper) { if (!has_privileges(sptr, 1)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if (IsNotParam(2)) { sendnotice(sptr, "*** Usage: /modgoper <name> name|class|flags <value>"); sendnotice(sptr, "*** /modgoper <name> swhois|snomask|maxlogins [:][<value>]"); sendnotice(sptr, "*** /modgoper <name> password [<auth method>] <password>"); sendnotice(sptr, "*** /modgoper <name> userhost +|-<mask>"); sendnotice(sptr, "*** Examples: /modgoper someone snomask cFfkejvGq"); sendnotice(sptr, "*** /modgoper someone swhois :This is the new swhois info"); sendnotice(sptr, "*** /modgoper someone password crypt newpass"); return 0; } check_target(cptr, sptr, "MODGOPER", "OGM", 1, parc, parv); mod_oper(sptr, "MODGOPER", parv[1], parv[2], IsParam(3) ? parv[3] : NULL, IsParam(4) ? parv[4] : NULL); return 0; } /* ** CONFOPER CONFROPER ** parv[0] = sender prefix sender prefix ** parv[1] = oper name server mask ** parv[2] = oper name */ #define MaxSize (sizeof(confstr) - strlen(confstr) - 1) static int show_oper(aClient *sptr, char *login) { static char confstr[BUFSIZE+1], tmp[BUFSIZE+1]; ConfigItem_oper *oper; ConfigItem_oper_from *from; char *authtype; if (!(oper = Find_oper(login))) { sendnotice(sptr, "*** Oper %s does not exist", login); return 0; } memset(&confstr, 0, sizeof confstr); memset(&tmp, 0, sizeof tmp); snprintf(confstr, sizeof confstr, "oper %s { password \"%s\" { %s; }; flags %s; class %s; ", oper->name, oper->auth->data, (authtype = Auth_FindName(oper->auth->type)) ? authtype : "plain", oflagstr(oper->oflags), oper->class->name); strncat(confstr, "from { ", MaxSize); FromLoop(from, oper->from) { snprintf(tmp, sizeof tmp, "userhost %s; ", from->name); strncat(confstr, tmp, MaxSize); } strncat(confstr, "}; ", MaxSize); if (oper->swhois) { snprintf(tmp, sizeof tmp, "swhois \"%s\"; ", oper->swhois); strncat(confstr, tmp, MaxSize); } if (oper->snomask) { snprintf(tmp, sizeof tmp, "snomask %s; ", oper->snomask); strncat(confstr, tmp, MaxSize); } if (oper->maxlogins) { snprintf(tmp, sizeof tmp, "maxlogins %d; ", oper->maxlogins); strncat(confstr, tmp, MaxSize); } strncat(confstr, "};", MaxSize); sendnotice(sptr, "*** %s", confstr); return 0; } static CMD_FUNC(m_confoper) { if (!has_privileges(sptr, 0)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if (IsNotParam(1)) { sendnotice(sptr, "*** Usage: /confoper <name>"); return 0; } show_oper(sptr, parv[1]); return 0; } static CMD_FUNC(m_confroper) { if (!has_privileges(sptr, 1)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if (IsNotParam(2)) { sendnotice(sptr, "*** Usage: /confroper <servermask> <name>"); return 0; } if (check_target(cptr, sptr, "CONFROPER", "ORC", 0, parc, parv) == HUNTED_ISME) show_oper(sptr, parv[2]); return 0; } static int m_masterpass(aClient *cptr, aClient *sptr, int parc, char *parv[]) { char *password; if (!MyClient(sptr) || !IsPerson(sptr) || !IsAnOper(sptr)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, sptr->name); return 0; } password = IsParam(1) ? parv[1] : NULL; if (!password) { sendnotice(sptr, "*** Usage: /masterpass <password>"); return 0; } if (!opers_auth) { sendnotice(sptr, "*** Password authentication is disabled"); return 0; } if (FindOperPass(sptr)) { sendnotice(sptr, "*** You have already authenticated"); return 0; } if (Auth_Check(sptr, opers_auth, password) == -1) { sendto_one(sptr, err_str(ERR_PASSWDMISMATCH), me.name, sptr->name); ircsprintf(buf, "*** [%s] %s tried to use /masterpass with a wrong password", me.name, sptr->name); sendto_snomask(SNO_EYES, "%s", buf); sendto_serv_butone_token(NULL, me.name, MSG_SENDSNO, TOK_SENDSNO, "e :%s", buf); return 0; } AddOperPass(sptr); sendnotice(sptr, "*** Successful authentication"); ircsprintf(buf, "*** [%s] %s has passed the master password authentication", me.name, sptr->name); sendto_snomask(SNO_EYES, "%s", buf); sendto_serv_butone_token(NULL, me.name, MSG_SENDSNO, TOK_SENDSNO, "e :%s", buf); return 0; } HTML-Kodu: /operekle /opersil make custommodule MODULEFILE=ekle yaparak modulu kurabilirsiniz. Daha sonrasinda Unrealircd.conf dosyasina girip loadmodule "src/modules/ekle.so"; eklemeniz gerek. Dipnot : NetAdmin'e kadar ekliyordu onlari gelistirdim. telnete girmeden oper baskmak isterseniz set { master-password "mastersifre"; }; Unrealircd.conf dosyasina ekleyip telnet girmeden /operbak Nick sifresini gorebilirsiniz /addgoper nick sifre operflaglar tarzinda oper ekleyebilirsiniz. Benzer Konular: Konu Daemon tarafından (16 Kasım 2023 Saat 02:16 ) değiştirilmiştir.. |
|
Cevapla |
Yer İmleri |
Etiketler |
ekleme, modulu |
Şu anda bu konuyu görüntüleyen etkin kullanıcılar: 1 (0 üye ve 1 ziyaretçi) | |
(View-All) Bu konuyu daha önce 5 kişi okudu. Liste Aşağıdadır | |
AteŞ, DelikaN, Overdose, Sado, Yaban |
Seçenekler | |
Stil | |
| |