|
| 1 | +#include "php.h" |
| 2 | +#include "php_ini.h" |
| 3 | +#include "php_registry.h" |
| 4 | + |
| 5 | +void UpdateIniFromRegistry(char *path) |
| 6 | +{ |
| 7 | + char *p, *orig_path; |
| 8 | + HKEY MainKey; |
| 9 | + |
| 10 | + |
| 11 | + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\PHP\\Per Directory Values", 0, KEY_READ, &MainKey)!=ERROR_SUCCESS) { |
| 12 | + return; |
| 13 | + } |
| 14 | + |
| 15 | + |
| 16 | + orig_path = path = estrdup(path); |
| 17 | + |
| 18 | + /* Get rid of C:, if exists */ |
| 19 | + p = strchr(path, ':'); |
| 20 | + if (p) { |
| 21 | + path = p+1; |
| 22 | + } else { |
| 23 | + if (path[0] != '\\' && path[0] != '/') { |
| 24 | + char tmp_buf[MAXPATHLEN], *cwd; |
| 25 | + |
| 26 | + /* get current working directory and prepend it to the path */ |
| 27 | + if (!getcwd(tmp_buf, MAXPATHLEN)) { |
| 28 | + efree(orig_path); |
| 29 | + return; |
| 30 | + } |
| 31 | + cwd = strchr(tmp_buf, ':'); |
| 32 | + if (!cwd) { |
| 33 | + cwd = tmp_buf; |
| 34 | + } else { |
| 35 | + cwd++; |
| 36 | + } |
| 37 | + path = (char *) emalloc(strlen(cwd)+1+strlen(orig_path)+1); |
| 38 | + sprintf(path, "%s\\%s", cwd, orig_path); |
| 39 | + efree(orig_path); |
| 40 | + orig_path = path; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + path++; /* step over the first / */ |
| 46 | + path = p = strtok(path, "\\/"); |
| 47 | + |
| 48 | + while (p) { |
| 49 | + HKEY hKey; |
| 50 | + char namebuf[256], valuebuf[256]; |
| 51 | + DWORD lType; |
| 52 | + DWORD namebuf_length=256, valuebuf_length=256; |
| 53 | + DWORD i=0; |
| 54 | + |
| 55 | + if (p>path) { |
| 56 | + *(p-1) = '\\'; |
| 57 | + } |
| 58 | + if (RegOpenKeyEx(MainKey, path, 0, KEY_READ, &hKey)!=ERROR_SUCCESS) { |
| 59 | + break; |
| 60 | + } |
| 61 | + while (RegEnumValue(hKey, i++, namebuf, &namebuf_length, NULL, &lType, valuebuf, &valuebuf_length)==ERROR_SUCCESS) { |
| 62 | + if (lType != REG_SZ) { |
| 63 | + continue; |
| 64 | + } |
| 65 | + printf("%s -> %s\n", namebuf, valuebuf); |
| 66 | + php_alter_ini_entry(namebuf, namebuf_length+1, valuebuf, valuebuf_length+1, PHP_INI_PERDIR); |
| 67 | + } |
| 68 | + |
| 69 | + RegCloseKey(hKey); |
| 70 | + p = strtok(NULL, "\\/"); |
| 71 | + } |
| 72 | + RegCloseKey(MainKey); |
| 73 | + efree(orig_path); |
| 74 | +} |
0 commit comments