pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS

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

    
11
/*
22
 * MIT License
33
 *
44
 * Copyright (c) 2024 Roland Mainz <roland.mainz@nrubsig.org>
55
 *
66
 * Permission is hereby granted, free of charge, to any person obtaining a copy
77
 * of this software and associated documentation files (the "Software"), to deal
88
 * in the Software without restriction, including without limitation the rights
99
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1010
 * copies of the Software, and to permit persons to whom the Software is
1111
 * furnished to do so, subject to the following conditions:
1212
 *
1313
 * The above copyright notice and this permission notice shall be included in all
1414
 * copies or substantial portions of the Software.
1515
 *
1616
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1717
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1818
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1919
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2020
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
 * SOFTWARE.
2323
 */
2424
2525
/*
2626
 * winsystemfilecachesize.c - get/set Win32 system file cache
2727
 *
2828
 * Written by Roland Mainz <roland.mainz@nrubsig.org>
2929
 */
3030
3131
#include <windows.h>
3232
#include <memoryapi.h>
3333
#include <securitybaseapi.h>
3434
#include <stdlib.h>
3535
#include <stdbool.h>
36+
#include <ctype.h>
3637
#include <stdio.h>
3738
3839
static int _dprint_level = 2;
3940
4041
#define DPRINTF(level, fmt) \
4142
    if ((level) <= _dprint_level) { \
4243
        (void)printf fmt ; \
4344
    }
4445
4546
static
4647
bool set_token_privilege(HANDLE tok, const char *seprivname, bool enable_priv)
4748
{
4849
    TOKEN_PRIVILEGES tp;
4950
    LUID luid;
5051
    bool res;
5152
5253
    if(!LookupPrivilegeValueA(NULL, seprivname, &luid)) {
5354
        DPRINTF(1, ("set_token_privilege: "
5455
            "LookupPrivilegeValue(seprivname='%s') failed, "
5556
            "status=%d\n",
5657
            seprivname,
5758
            (int)GetLastError()));
5859
        res = false;
5960
        goto out;
6061
    }
6162
6263
    tp.PrivilegeCount = 1;
6364
    tp.Privileges[0].Luid = luid;
6465
    tp.Privileges[0].Attributes = enable_priv?(SE_PRIVILEGE_ENABLED):0;
6566
6667
    if(!AdjustTokenPrivileges(tok,
6768
        FALSE, &tp, sizeof(TOKEN_PRIVILEGES),
6869
        NULL, NULL)) {
6970
        DPRINTF(1, ("set_token_privilege: "
7071
            "AdjustTokenPrivileges() for '%s' failed, status=%d\n",
7172
            seprivname,
7273
            (int)GetLastError()));
7374
        res = false;
7475
        goto out;
7576
    }
7677
7778
    res = true;
7879
out:
7980
    DPRINTF(0,
8081
        ("set_token_privilege(seprivname='%s',enable_priv=%d), res=%d\n",
8182
        seprivname, (int)enable_priv, (int)res));
8283
8384
    return res;
8485
}
8586
87+
#if 0
8688
static
87-
int get_sysfscachesize(void)
89+
bool tagvalue_istagvalue(const char *str)
8890
{
89-
    SIZE_T minimumFileCacheSize;
91+
    return strstr(str, "=")?true:false;
90-
    SIZE_T maximumFileCacheSize;
92+
}
91-
    DWORD flags;
93+
#endif
9294
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);
102106
    }
107107
    }
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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at