Difference between
modified post 411360b by Anonymous on Fri 10th May 2024 14:41
original post c02 by Anonymous on Fri 10th May 2024 14:04
Download diff
Show
old version |
new version |
both versions
| 1 | 1 | /* | |
| 2 | 2 | * MIT License | |
| 3 | 3 | * | |
| 4 | 4 | * Copyright (c) 2024 Roland Mainz <roland.mainz@nrubsig.org> | |
| 5 | 5 | * | |
| 6 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
| 7 | 7 | * of this software and associated documentation files (the "Software"), to deal | |
| 8 | 8 | * in the Software without restriction, including without limitation the rights | |
| 9 | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| 10 | 10 | * copies of the Software, and to permit persons to whom the Software is | |
| 11 | 11 | * furnished to do so, subject to the following conditions: | |
| 12 | 12 | * | |
| 13 | 13 | * The above copyright notice and this permission notice shall be included in all | |
| 14 | 14 | * copies or substantial portions of the Software. | |
| 15 | 15 | * | |
| 16 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| 17 | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| 18 | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| 19 | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 20 | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| 22 | 22 | * SOFTWARE. | |
| 23 | 23 | */ | |
| 24 | 24 | ||
| 25 | 25 | /* | |
| 26 | 26 | * winsystemfilecachesize.c - get/set Win32 system file cache | |
| 27 | 27 | * | |
| 28 | 28 | * Written by Roland Mainz <roland.mainz@nrubsig.org> | |
| 29 | 29 | */ | |
| 30 | 30 | ||
| 31 | 31 | #include <windows.h> | |
| 32 | 32 | #include <memoryapi.h> | |
| 33 | 33 | #include <securitybaseapi.h> | |
| 34 | 34 | #include <stdlib.h> | |
| 35 | 35 | #include <stdbool.h> | |
| 36 | + | #include <ctype.h> | |
| 36 | 37 | #include <stdio.h> | |
| 37 | 38 | ||
| 38 | 39 | static int _dprint_level = 2; | |
| 39 | 40 | ||
| 40 | 41 | #define DPRINTF(level, fmt) \ | |
| 41 | 42 | if ((level) <= _dprint_level) { \ | |
| 42 | 43 | (void)printf fmt ; \ | |
| 43 | 44 | } | |
| 44 | 45 | ||
| 45 | 46 | static | |
| 46 | 47 | bool set_token_privilege(HANDLE tok, const char *seprivname, bool enable_priv) | |
| 47 | 48 | { | |
| 48 | 49 | TOKEN_PRIVILEGES tp; | |
| 49 | 50 | LUID luid; | |
| 50 | 51 | bool res; | |
| 51 | 52 | ||
| 52 | 53 | if(!LookupPrivilegeValueA(NULL, seprivname, &luid)) { | |
| 53 | 54 | DPRINTF(1, ("set_token_privilege: " | |
| 54 | 55 | "LookupPrivilegeValue(seprivname='%s') failed, " | |
| 55 | 56 | "status=%d\n", | |
| 56 | 57 | seprivname, | |
| 57 | 58 | (int)GetLastError())); | |
| 58 | 59 | res = false; | |
| 59 | 60 | goto out; | |
| 60 | 61 | } | |
| 61 | 62 | ||
| 62 | 63 | tp.PrivilegeCount = 1; | |
| 63 | 64 | tp.Privileges[0].Luid = luid; | |
| 64 | 65 | tp.Privileges[0].Attributes = enable_priv?(SE_PRIVILEGE_ENABLED):0; | |
| 65 | 66 | ||
| 66 | 67 | if(!AdjustTokenPrivileges(tok, | |
| 67 | 68 | FALSE, &tp, sizeof(TOKEN_PRIVILEGES), | |
| 68 | 69 | NULL, NULL)) { | |
| 69 | 70 | DPRINTF(1, ("set_token_privilege: " | |
| 70 | 71 | "AdjustTokenPrivileges() for '%s' failed, status=%d\n", | |
| 71 | 72 | seprivname, | |
| 72 | 73 | (int)GetLastError())); | |
| 73 | 74 | res = false; | |
| 74 | 75 | goto out; | |
| 75 | 76 | } | |
| 76 | 77 | ||
| 77 | 78 | res = true; | |
| 78 | 79 | out: | |
| 79 | 80 | DPRINTF(0, | |
| 80 | 81 | ("set_token_privilege(seprivname='%s',enable_priv=%d), res=%d\n", | |
| 81 | 82 | seprivname, (int)enable_priv, (int)res)); | |
| 82 | 83 | ||
| 83 | 84 | return res; | |
| 84 | 85 | } | |
| 85 | 86 | ||
| 87 | + | #if 0 | |
| 86 | 88 | static | |
| 87 | - | int get_sysfscachesize(void) | |
| 89 | + | bool tagvalue_istagvalue(const char *str) | |
| 88 | 90 | { | |
| 89 | - | SIZE_T minimumFileCacheSize; | |
| 91 | + | return strstr(str, "=")?true:false; | |
| 90 | - | SIZE_T maximumFileCacheSize; | |
| 92 | + | } | |
| 91 | - | DWORD flags; | |
| 93 | + | #endif | |
| 92 | 94 | ||
| 93 | - | if (GetSystemFileCacheSize(&minimumFileCacheSize, | |
| 95 | + | static | |
| 94 | - | &maximumFileCacheSize, | |
| 96 | + | bool tagvalue_getsize_tvalue(const char *str, SIZE_T *dest) | |
| 95 | - | &flags)) { | |
| 97 | + | { | |
| 96 | - | (void)printf("minimumFileCacheSize=%lld\n" | |
| 98 | + | const char *s; | |
| 97 | - | "maximumFileCacheSize=%lld\n" | |
| 99 | + | ||
| 98 | - | "flags=0x%x\n", | |
| 100 | + | s=strstr(str, "="); | |
| 99 | - | (long long)minimumFileCacheSize, | |
| 101 | + | if (s != NULL) { | |
| 100 | - | (long long)maximumFileCacheSize, | |
| 102 | + | s++; | |
| 101 | - | (int)flags); | |
| 103 | + | if (isdigit((int)(*s))) { | |
| 104 | + | *dest = atoll(s); | |
| 102 | 106 | } | |
| 107 | 107 | } | |
| 108 | + |
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
nrubsig.kpaste.net RSS