Annotation of truecrypt/common/registry.c, revision 1.1.1.13

1.1.1.7   root        1: /*
1.1.1.12  root        2:  Copyright (c) 2004-2009 TrueCrypt Foundation. All rights reserved.
1.1.1.4   root        3: 
1.1.1.13! root        4:  Governed by the TrueCrypt License 2.7 the full text of which is contained
1.1.1.7   root        5:  in the file License.txt included in TrueCrypt binary and source code
                      6:  distribution packages.
1.1.1.4   root        7: */
1.1       root        8: 
1.1.1.4   root        9: #include "Tcdefs.h"
                     10: #include "Registry.h"
1.1       root       11: 
1.1.1.9   root       12: BOOL ReadLocalMachineRegistryDword (char *subKey, char *name, DWORD *value)
                     13: {
                     14:        HKEY hkey = 0;
                     15:        DWORD size = sizeof (*value);
1.1.1.10  root       16:        DWORD type;
1.1.1.9   root       17: 
                     18:        if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
                     19:                return FALSE;
                     20: 
1.1.1.10  root       21:        if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) value, &size) != ERROR_SUCCESS)
1.1.1.9   root       22:        {
                     23:                RegCloseKey (hkey);
                     24:                return FALSE;
                     25:        }
                     26: 
                     27:        RegCloseKey (hkey);
1.1.1.10  root       28:        return type == REG_DWORD;
                     29: }
                     30: 
                     31: BOOL ReadLocalMachineRegistryMultiString (char *subKey, char *name, char *value, DWORD *size)
                     32: {
                     33:        HKEY hkey = 0;
                     34:        DWORD type;
                     35: 
                     36:        if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
                     37:                return FALSE;
                     38: 
                     39:        if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) value, size) != ERROR_SUCCESS)
                     40:        {
                     41:                RegCloseKey (hkey);
                     42:                return FALSE;
                     43:        }
                     44: 
                     45:        RegCloseKey (hkey);
                     46:        return type == REG_MULTI_SZ;
1.1.1.9   root       47: }
                     48: 
1.1.1.12  root       49: BOOL ReadLocalMachineRegistryString (char *subKey, char *name, char *str, DWORD *size)
                     50: {
                     51:        HKEY hkey = 0;
                     52:        DWORD type;
                     53: 
                     54:        if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
                     55:                return FALSE;
                     56: 
                     57:        if (RegQueryValueEx (hkey, name, NULL, &type, (BYTE *) str, size) != ERROR_SUCCESS)
                     58:        {
                     59:                RegCloseKey (hkey);
                     60:                return FALSE;
                     61:        }
                     62: 
                     63:        RegCloseKey (hkey);
                     64:        return type == REG_SZ;
                     65: }
                     66: 
1.1.1.4   root       67: int ReadRegistryInt (char *subKey, char *name, int defaultValue)
1.1       root       68: {
                     69:        HKEY hkey = 0;
                     70:        DWORD value, size = sizeof (DWORD);
                     71: 
1.1.1.4   root       72:        if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
1.1       root       73:                0, KEY_READ, &hkey) != ERROR_SUCCESS)
                     74:                return defaultValue;
                     75: 
                     76:        if (RegQueryValueEx (hkey, name, 0,     0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
                     77:                value = defaultValue;
                     78: 
                     79:        RegCloseKey (hkey);
                     80:        return value;
                     81: }
                     82: 
1.1.1.4   root       83: char *ReadRegistryString (char *subKey, char *name, char *defaultValue, char *str, int maxLen)
1.1       root       84: {
                     85:        HKEY hkey = 0;
1.1.1.4   root       86:        char value[MAX_PATH*4];
1.1       root       87:        DWORD size = sizeof (value);
                     88: 
                     89:        strncpy (str, defaultValue, maxLen-1);
                     90: 
                     91:        ZeroMemory (value, sizeof value);
1.1.1.4   root       92:        if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey,
1.1       root       93:                0, KEY_READ, &hkey) == ERROR_SUCCESS)
                     94:                if (RegQueryValueEx (hkey, name, 0,     0, (LPBYTE) &value,     &size) == ERROR_SUCCESS)
                     95:                        strncpy (str, value, maxLen-1);
                     96: 
                     97:        RegCloseKey (hkey);
                     98:        return str;
                     99: }
                    100: 
1.1.1.4   root      101: DWORD ReadRegistryBytes (char *path, char *name, char *value, int maxLen)
                    102: {
                    103:        HKEY hkey = 0;
                    104:        DWORD size = maxLen;
                    105:        BOOL success = FALSE;
                    106: 
                    107:        if (RegOpenKeyEx (HKEY_CURRENT_USER, path, 0, KEY_READ, &hkey) != ERROR_SUCCESS)
                    108:                return 0;
                    109: 
                    110:        success = (RegQueryValueEx (hkey, name, 0,      0, (LPBYTE) value,      &size) == ERROR_SUCCESS);
                    111:        RegCloseKey (hkey);
                    112: 
                    113:        return success ? size : 0;
                    114: }
                    115: 
                    116: void WriteRegistryInt (char *subKey, char *name, int value)
1.1       root      117: {
                    118:        HKEY hkey = 0;
                    119:        DWORD disp;
                    120: 
1.1.1.4   root      121:        if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey,
1.1       root      122:                0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
                    123:                return;
                    124: 
                    125:        RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value);
                    126:        RegCloseKey (hkey);
                    127: }
                    128: 
1.1.1.9   root      129: BOOL WriteLocalMachineRegistryDword (char *subKey, char *name, DWORD value)
                    130: {
                    131:        HKEY hkey = 0;
                    132:        DWORD disp;
1.1.1.10  root      133:        LONG status;
1.1.1.9   root      134: 
1.1.1.10  root      135:        if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
                    136:                0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
                    137:        {
                    138:                SetLastError (status);
1.1.1.9   root      139:                return FALSE;
1.1.1.10  root      140:        }
                    141: 
                    142:        if ((status = RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value)) != ERROR_SUCCESS)
                    143:        {
                    144:                RegCloseKey (hkey);
                    145:                SetLastError (status);
                    146:                return FALSE;
                    147:        }
                    148: 
                    149:        RegCloseKey (hkey);
                    150:        return TRUE;
                    151: }
                    152: 
                    153: BOOL WriteLocalMachineRegistryMultiString (char *subKey, char *name, char *multiString, DWORD size)
                    154: {
                    155:        HKEY hkey = 0;
                    156:        DWORD disp;
                    157:        LONG status;
                    158: 
                    159:        if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
                    160:                0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
                    161:        {
                    162:                SetLastError (status);
                    163:                return FALSE;
                    164:        }
1.1.1.9   root      165: 
1.1.1.10  root      166:        if ((status = RegSetValueEx (hkey, name, 0, REG_MULTI_SZ, (BYTE *) multiString, size)) != ERROR_SUCCESS)
1.1.1.9   root      167:        {
                    168:                RegCloseKey (hkey);
1.1.1.10  root      169:                SetLastError (status);
1.1.1.9   root      170:                return FALSE;
                    171:        }
                    172: 
                    173:        RegCloseKey (hkey);
                    174:        return TRUE;
                    175: }
                    176: 
1.1.1.12  root      177: BOOL WriteLocalMachineRegistryString (char *subKey, char *name, char *str, DWORD size)
                    178: {
                    179:        HKEY hkey = 0;
                    180:        DWORD disp;
                    181:        LONG status;
                    182: 
                    183:        if ((status = RegCreateKeyEx (HKEY_LOCAL_MACHINE, subKey,
                    184:                0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp)) != ERROR_SUCCESS)
                    185:        {
                    186:                SetLastError (status);
                    187:                return FALSE;
                    188:        }
                    189: 
                    190:        if ((status = RegSetValueEx (hkey, name, 0, REG_SZ, (BYTE *) str, size)) != ERROR_SUCCESS)
                    191:        {
                    192:                RegCloseKey (hkey);
                    193:                SetLastError (status);
                    194:                return FALSE;
                    195:        }
                    196: 
                    197:        RegCloseKey (hkey);
                    198:        return TRUE;
                    199: }
                    200: 
1.1.1.4   root      201: void WriteRegistryString (char *subKey, char *name, char *str)
1.1       root      202: {
                    203:        HKEY hkey = 0;
                    204:        DWORD disp;
                    205: 
1.1.1.4   root      206:        if (RegCreateKeyEx (HKEY_CURRENT_USER, subKey,
1.1       root      207:                0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
                    208:                return;
                    209: 
                    210:        RegSetValueEx (hkey, name, 0, REG_SZ, (BYTE *) str, strlen (str) + 1);
                    211:        RegCloseKey (hkey);
                    212: }
1.1.1.4   root      213: 
                    214: BOOL WriteRegistryBytes (char *path, char *name, char *str, DWORD size)
                    215: {
                    216:        HKEY hkey = 0;
                    217:        DWORD disp;
                    218:        BOOL res;
                    219: 
                    220:        if (RegCreateKeyEx (HKEY_CURRENT_USER, path,
                    221:                0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
                    222:                return FALSE;
                    223: 
                    224:        res = RegSetValueEx (hkey, name, 0, REG_BINARY, (BYTE *) str, size);
                    225:        RegCloseKey (hkey);
                    226:        return res == ERROR_SUCCESS;
                    227: }
                    228: 
                    229: void DeleteRegistryValue (char *subKey, char *name)
                    230: {
                    231:        HKEY hkey = 0;
                    232: 
                    233:        if (RegOpenKeyEx (HKEY_CURRENT_USER, subKey, 0, KEY_WRITE, &hkey) != ERROR_SUCCESS)
                    234:                return;
                    235: 
                    236:        RegDeleteValue (hkey, name);
                    237:        RegCloseKey (hkey);
                    238: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.