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