2011-07-14 09:23:44 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
2011-08-17 03:40:55 +04:00
|
|
|
* Registry Utils
|
2011-07-14 09:23:44 +04:00
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-08-17 03:40:55 +04:00
|
|
|
#include <freerdp/utils/registry.h>
|
2011-08-17 01:40:29 +04:00
|
|
|
|
2011-08-17 04:49:46 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2011-07-27 03:14:11 +04:00
|
|
|
static char registry_dir[] = "freerdp";
|
|
|
|
static char registry_file[] = "config.txt";
|
2011-07-14 09:23:44 +04:00
|
|
|
|
2011-07-14 20:52:37 +04:00
|
|
|
static REG_SECTION global[] =
|
2011-07-14 09:23:44 +04:00
|
|
|
{
|
2011-07-27 03:14:11 +04:00
|
|
|
{ REG_TYPE_SECTION, "global", 0, NULL },
|
|
|
|
{ REG_TYPE_BOOLEAN, "fast_path", 1, "1" },
|
|
|
|
{ REG_TYPE_STRING, "resolution", 8, "1024x768" },
|
|
|
|
{ REG_TYPE_INTEGER, "performance_flags", 4, "0xFFFF" },
|
|
|
|
{ REG_TYPE_NONE, "", 0, NULL }
|
2011-07-14 09:23:44 +04:00
|
|
|
};
|
|
|
|
|
2011-07-14 20:52:37 +04:00
|
|
|
static REG_SECTION licensing[] =
|
2011-07-14 09:23:44 +04:00
|
|
|
{
|
2011-07-27 03:14:11 +04:00
|
|
|
{ REG_TYPE_SECTION, "licensing", 0, NULL },
|
|
|
|
{ REG_TYPE_STRING, "platform_id", 1, "0x000201" },
|
|
|
|
{ REG_TYPE_STRING, "hardware_id", 16, "0xe107d9d372bb6826bd81d3542a419d6" },
|
|
|
|
{ REG_TYPE_NONE, "", 0, NULL }
|
2011-07-14 09:23:44 +04:00
|
|
|
};
|
|
|
|
|
2011-07-14 20:52:37 +04:00
|
|
|
static REG_SECTION* sections[] =
|
2011-07-14 09:23:44 +04:00
|
|
|
{
|
2011-07-14 20:52:37 +04:00
|
|
|
(REG_SECTION*) &global,
|
|
|
|
(REG_SECTION*) &licensing,
|
|
|
|
(REG_SECTION*) NULL
|
2011-07-14 09:23:44 +04:00
|
|
|
};
|
|
|
|
|
2011-07-14 20:52:37 +04:00
|
|
|
void registry_print_entry(REG_ENTRY* entry, FILE* fp)
|
2011-07-14 09:23:44 +04:00
|
|
|
{
|
|
|
|
uint8* value;
|
|
|
|
value = (uint8*) entry->value;
|
2011-07-14 20:52:37 +04:00
|
|
|
fprintf(fp, "%s = %s\n", entry->name, value);
|
2011-07-14 09:23:44 +04:00
|
|
|
}
|
|
|
|
|
2011-07-14 20:52:37 +04:00
|
|
|
void registry_print_section(REG_SECTION* section, FILE* fp)
|
2011-07-14 09:23:44 +04:00
|
|
|
{
|
2011-07-14 20:52:37 +04:00
|
|
|
int i = 0;
|
|
|
|
REG_ENTRY* entries = (REG_ENTRY*) §ion[1];
|
|
|
|
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
fprintf(fp, "[%s]\n", section->name);
|
|
|
|
|
|
|
|
while (entries[i].type != REG_TYPE_NONE)
|
|
|
|
{
|
|
|
|
registry_print_entry(&entries[i], fp);
|
|
|
|
i++;
|
|
|
|
}
|
2011-07-14 09:23:44 +04:00
|
|
|
}
|
|
|
|
|
2011-07-14 20:52:37 +04:00
|
|
|
void registry_print(rdpRegistry* registry, FILE* fp)
|
2011-07-14 09:23:44 +04:00
|
|
|
{
|
2011-07-14 20:52:37 +04:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
fprintf(fp, "# FreeRDP Configuration Registry\n");
|
|
|
|
|
|
|
|
while (sections[i] != NULL)
|
|
|
|
{
|
|
|
|
registry_print_section(sections[i], fp);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(fp, "\n");
|
2011-07-14 09:23:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void registry_create(rdpRegistry* registry)
|
|
|
|
{
|
2011-07-27 03:14:11 +04:00
|
|
|
registry->fp = fopen((char*)registry->file, "w+");
|
|
|
|
|
2011-07-26 00:50:00 +04:00
|
|
|
if (registry->fp == NULL)
|
|
|
|
{
|
|
|
|
printf("registry_create: error opening [%s] for writing\n", registry->file);
|
|
|
|
return;
|
|
|
|
}
|
2011-07-14 20:52:37 +04:00
|
|
|
registry_print(registry, registry->fp);
|
|
|
|
fflush(registry->fp);
|
2011-07-14 09:23:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void registry_load(rdpRegistry* registry)
|
|
|
|
{
|
2011-07-27 03:14:11 +04:00
|
|
|
registry->fp = fopen((char*)registry->file, "r+");
|
2011-07-14 09:23:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void registry_open(rdpRegistry* registry)
|
|
|
|
{
|
|
|
|
struct stat stat_info;
|
|
|
|
|
2011-07-27 03:14:11 +04:00
|
|
|
if (stat((char*)registry->file, &stat_info) != 0)
|
2011-07-14 09:23:44 +04:00
|
|
|
registry_create(registry);
|
|
|
|
else
|
|
|
|
registry_load(registry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void registry_close(rdpRegistry* registry)
|
|
|
|
{
|
|
|
|
if (registry->fp != NULL)
|
|
|
|
fclose(registry->fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void registry_init(rdpRegistry* registry)
|
|
|
|
{
|
|
|
|
int length;
|
|
|
|
char* home_path;
|
|
|
|
struct stat stat_info;
|
|
|
|
|
|
|
|
home_path = getenv("HOME");
|
|
|
|
registry->available = True;
|
|
|
|
|
|
|
|
if (home_path == NULL)
|
|
|
|
{
|
|
|
|
printf("could not get home path\n");
|
|
|
|
registry->available = False;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-27 03:14:11 +04:00
|
|
|
registry->home = (char*) xstrdup(home_path);
|
2011-07-14 09:23:44 +04:00
|
|
|
printf("home path: %s\n", registry->home);
|
|
|
|
|
2011-07-27 03:14:11 +04:00
|
|
|
registry->path = (char*) xmalloc(strlen(registry->home) + strlen("/.") + strlen(registry_dir) + 1);
|
2011-07-14 09:23:44 +04:00
|
|
|
sprintf(registry->path, "%s/.%s", registry->home, registry_dir);
|
|
|
|
printf("registry path: %s\n", registry->path);
|
|
|
|
|
|
|
|
if (stat(registry->path, &stat_info) != 0)
|
|
|
|
{
|
2011-08-17 01:40:29 +04:00
|
|
|
#ifndef _WIN32
|
2011-07-14 09:23:44 +04:00
|
|
|
mkdir(registry->path, S_IRUSR | S_IWUSR | S_IXUSR);
|
2011-08-17 01:40:29 +04:00
|
|
|
#else
|
|
|
|
CreateDirectory(registry->path, 0);
|
|
|
|
#endif
|
2011-07-14 09:23:44 +04:00
|
|
|
printf("creating directory %s\n", registry->path);
|
|
|
|
}
|
|
|
|
|
|
|
|
length = strlen(registry->path);
|
2011-07-27 03:14:11 +04:00
|
|
|
registry->file = (char*) xmalloc(strlen(registry->path) + strlen("/") + strlen(registry_file) + 1);
|
2011-07-14 09:23:44 +04:00
|
|
|
sprintf(registry->file, "%s/%s", registry->path, registry_file);
|
|
|
|
printf("registry file: %s\n", registry->file);
|
|
|
|
|
|
|
|
registry_open(registry);
|
|
|
|
}
|
|
|
|
|
|
|
|
rdpRegistry* registry_new(rdpSettings* settings)
|
|
|
|
{
|
|
|
|
rdpRegistry* registry = (rdpRegistry*) xzalloc(sizeof(rdpRegistry));
|
|
|
|
|
|
|
|
if (registry != NULL)
|
|
|
|
{
|
|
|
|
registry->settings = settings;
|
|
|
|
registry_init(registry);
|
|
|
|
}
|
|
|
|
|
|
|
|
return registry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void registry_free(rdpRegistry* registry)
|
|
|
|
{
|
|
|
|
if (registry != NULL)
|
|
|
|
{
|
|
|
|
registry_close(registry);
|
|
|
|
xfree(registry->path);
|
|
|
|
xfree(registry->file);
|
|
|
|
xfree(registry->home);
|
|
|
|
xfree(registry);
|
|
|
|
}
|
|
|
|
}
|