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