return 0;\r
}\r
\r
-int expand_parameter(HKEY key, char *value, char *data, unsigned long datalen, bool sanitise) {\r
+int expand_parameter(HKEY key, char *value, char *data, unsigned long datalen, bool sanitise, bool must_exist) {\r
unsigned char *buffer = (unsigned char *) HeapAlloc(GetProcessHeap(), 0, datalen);\r
if (! buffer) {\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_OUT_OF_MEMORY, value, "expand_parameter()", 0);\r
return 1;\r
}\r
\r
+ ZeroMemory(data, datalen);\r
+\r
unsigned long type = REG_EXPAND_SZ;\r
unsigned long buflen = datalen;\r
\r
unsigned long ret = RegQueryValueEx(key, value, 0, &type, buffer, &buflen);\r
if (ret != ERROR_SUCCESS) {\r
- if (ret != ERROR_FILE_NOT_FOUND) log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(GetLastError()), 0);\r
+ unsigned long error = GetLastError();\r
HeapFree(GetProcessHeap(), 0, buffer);\r
+\r
+ if (ret == ERROR_FILE_NOT_FOUND) {\r
+ if (! must_exist) return 0;\r
+ }\r
+\r
+ log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_QUERYVALUE_FAILED, value, error_string(error), 0);\r
return 2;\r
}\r
\r
/* Paths aren't allowed to contain quotes. */\r
if (sanitise) PathUnquoteSpaces((LPSTR) buffer);\r
\r
- ZeroMemory(data, datalen);\r
-\r
/* Technically we shouldn't expand environment strings from REG_SZ values */\r
if (type != REG_EXPAND_SZ) {\r
memmove(data, buffer, buflen);\r
return 0;\r
}\r
\r
+int expand_parameter(HKEY key, char *value, char *data, unsigned long datalen, bool sanitise) {\r
+ return expand_parameter(key, value, data, datalen, sanitise, true);\r
+}\r
+\r
/*\r
Query an unsigned long from the registry.\r
Returns: 1 if a number was retrieved.\r
int create_parameters(char *, char *, char *, char *);\r
int create_exit_action(char *, const char *);\r
int set_environment(char *, HKEY, char **);\r
+int expand_parameter(HKEY, char *, char *, unsigned long, bool, bool);\r
int expand_parameter(HKEY, char *, char *, unsigned long, bool);\r
int get_number(HKEY, char *, unsigned long *, bool);\r
int get_number(HKEY, char *, unsigned long *);\r