MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // master.c -- master object |
| 4 | // |
| 5 | // $Id: master.c 7041 2008-10-13 18:18:27Z Zesstra $ |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 6 | |
Dominik Schäfer | a87e408 | 2017-03-26 20:17:54 +0200 | [diff] [blame] | 7 | #define WHITELIST "/"LIBDATADIR"/secure/ARCH/players_deny_whitelist.o" |
| 8 | #define TARGETLIST "/"LIBDATADIR"/secure/ARCH/players_deny_targets.o" |
| 9 | #define WHITELISTDUMP "/"LIBDATADIR"/secure/ARCH/players_deny_whitelist.dump" |
| 10 | #define TARGETLISTDUMP "/"LIBDATADIR"/secure/ARCH/players_deny_targets.dump" |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 11 | |
| 12 | //#define PLDENY_LEARNMODE |
| 13 | |
| 14 | #include "/secure/wizlevels.h" |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 15 | |
| 16 | /* Diese Objekte duerfen aus /players/ includieren/erben */ |
| 17 | nosave private mapping whitelist; |
| 18 | /* Diese Dinge werden von Objektn in whitelist aus /players/ inkludiert/geerbt. */ |
| 19 | nosave private mapping targets; |
| 20 | |
| 21 | private mapping ParseList(string list) { |
| 22 | mixed data; |
| 23 | |
| 24 | if (!stringp(list)) return ([:0 ]); |
| 25 | if (!stringp(data = read_file(list))) return ([:0 ]); |
| 26 | data = explode(data, "\n") || ({}); |
| 27 | |
| 28 | return mkmapping(data); |
| 29 | } |
| 30 | |
| 31 | private void ParseWhiteList() { |
| 32 | DEBUG("Parsing Whitelist\n"); |
| 33 | whitelist=ParseList(WHITELISTDUMP); |
| 34 | } |
| 35 | private void ParseTargetList() { |
| 36 | DEBUG("Parsing Targetlist\n"); |
| 37 | targets=ParseList(TARGETLISTDUMP); |
| 38 | } |
| 39 | |
| 40 | private void DumpList(mapping list, string file) { |
| 41 | if (!stringp(file) || !mappingp(list) |
| 42 | || !sizeof(file) || !sizeof(list)) |
| 43 | return; |
| 44 | |
| 45 | write_file(file, implode(m_indices(list),"\n"), 1); |
| 46 | } |
| 47 | |
| 48 | private void DumpWhiteList() { |
| 49 | DEBUG("Dumping Whitelist\n"); |
| 50 | DumpList(whitelist, WHITELISTDUMP); |
| 51 | } |
| 52 | private void DumpTargetList() { |
| 53 | DEBUG("Dumping Targetlist\n"); |
| 54 | DumpList(targets, TARGETLISTDUMP); |
| 55 | } |
| 56 | |
| 57 | public void DumpPLDenyLists() { |
| 58 | if ( extern_call() && call_sefun("secure_level") < ARCH_LVL ) |
| 59 | return; |
| 60 | DEBUG("Dumping PLDenylists\n"); |
| 61 | limited(#'DumpWhiteList); |
| 62 | limited(#'DumpTargetList); |
| 63 | } |
| 64 | |
| 65 | public void SavePLDenyLists() { |
| 66 | if ( extern_call() && call_sefun("secure_level") < ARCH_LVL ) |
| 67 | return; |
| 68 | DEBUG("Saving PLDenyLists\n"); |
| 69 | write_file(WHITELIST, |
| 70 | save_value(whitelist), 1); |
| 71 | write_file(TARGETLIST, |
| 72 | save_value(targets), 1); |
| 73 | } |
| 74 | |
| 75 | public void LoadPLDenylists() { |
| 76 | mixed tmp; |
| 77 | |
| 78 | if ( extern_call() && call_sefun("secure_level") < ARCH_LVL ) |
| 79 | return; |
| 80 | |
Zesstra | d77ab42 | 2019-09-27 17:39:27 +0200 | [diff] [blame] | 81 | debug_message("Loading PLDenylists\n", DMSG_STAMP); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 82 | |
| 83 | if (stringp(tmp=read_file(WHITELIST))) { |
| 84 | // savefile exists |
| 85 | whitelist = restore_value(tmp); |
| 86 | } |
| 87 | else { |
| 88 | limited(#'ParseWhiteList); |
| 89 | } |
| 90 | if (stringp(tmp=read_file(TARGETLIST))) { |
| 91 | targets = restore_value(tmp); |
| 92 | } |
| 93 | else { |
| 94 | limited(#'ParseTargetList); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | mixed include_file(string file, string compiled_file, int sys_include) { |
| 99 | |
| 100 | if (sys_include) return 0; |
| 101 | // Loggen, wenn Files ausserhalb /players/ Kram aus /players/ |
| 102 | // inkludieren/erben. |
| 103 | if (strstr(file, "/players/") == 0 |
| 104 | && (strstr(compiled_file,"/players/") == -1 |
| 105 | && !member(whitelist, compiled_file) )) { |
| 106 | #ifdef PLDENY_LEARNMODE |
| 107 | DEBUG("include_file(): Whitelisting: "+compiled_file+"\n"); |
| 108 | m_add(whitelist, compiled_file); |
| 109 | m_add(targets, file); |
| 110 | call_sefun("log_file", "PLAYERSWHITELIST", |
| 111 | sprintf("%s (inkludiert %s)\n",compiled_file, file), |
| 112 | 1000000); |
| 113 | #else |
| 114 | // verweigern. |
| 115 | return -1; |
| 116 | #endif |
| 117 | } |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | mixed inherit_file(string file, string compiled_file) { |
| 122 | |
| 123 | // Loggen, wenn Files ausserhalb /players/ Kram aus /players/ |
| 124 | // inkludieren/erben. |
| 125 | if (strstr(file, "/players/") == 0 |
| 126 | && (strstr(compiled_file,"/players/") == -1 |
| 127 | && !member(whitelist, compiled_file) )) { |
| 128 | #ifdef PLDENY_LEARNMODE |
| 129 | DEBUG("include_file(): Whitelisting: "+compiled_file+"\n"); |
| 130 | m_add(whitelist, compiled_file); |
| 131 | m_add(targets, file); |
| 132 | call_sefun("log_file", "PLAYERSWHITELIST", |
| 133 | sprintf("%s (erbt %s)\n",compiled_file, file), |
| 134 | 1000000); |
| 135 | #else |
| 136 | // verweigern. |
| 137 | return -1; |
| 138 | #endif |
| 139 | } |
| 140 | return 0; |
| 141 | } |
| 142 | |