File: realm-options.c

package info (click to toggle)
realmd 0.16.3-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,600 kB
  • sloc: ansic: 16,614; xml: 1,560; sh: 1,317; makefile: 565; python: 395
file content (200 lines) | stat: -rw-r--r-- 4,797 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/* realmd -- Realm configuration service
 *
 * Copyright 2012 Red Hat Inc
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2 of the licence or (at
 * your option) any later version.
 *
 * See the included COPYING file for more information.
 *
 * Author: Stef Walter <stefw@gnome.org>
 */

#include "config.h"

#include "realm-dbus-constants.h"
#include "realm-options.h"
#include "realm-settings.h"

#include <string.h>

gboolean
realm_options_automatic_install (void)
{
	return realm_settings_boolean ("service", "automatic-install", TRUE);
}

gboolean
realm_options_manage_system (GVariant *options,
                             const gchar *realm_name)
{
	gboolean manage;
	gchar *section;

	section = g_utf8_casefold (realm_name, -1);
	if (realm_settings_value (section, REALM_DBUS_OPTION_MANAGE_SYSTEM))
		manage = realm_settings_boolean (section, REALM_DBUS_OPTION_MANAGE_SYSTEM, TRUE);
	else if (!g_variant_lookup (options, REALM_DBUS_OPTION_MANAGE_SYSTEM, "b", &manage))
		manage = TRUE;
	g_free (section);

	return manage;
}

const gchar *
realm_options_user_principal (GVariant *options,
                              const gchar *realm_name)
{
	const gchar *principal;
	gchar *section;

	if (!g_variant_lookup (options, REALM_DBUS_OPTION_USER_PRINCIPAL, "&s", &principal))
		principal = NULL;

	if (!principal) {
		section = g_utf8_casefold (realm_name, -1);
		if (realm_settings_boolean (section, REALM_DBUS_OPTION_USER_PRINCIPAL, FALSE))
			principal = ""; /* auto-generate */
		g_free (section);
	}

	return principal;
}

const gchar *
realm_options_computer_ou (GVariant *options,
                           const gchar *realm_name)
{
	const gchar *computer_ou = NULL;
	gchar *section;

	if (options) {
		if (!g_variant_lookup (options, REALM_DBUS_OPTION_COMPUTER_OU, "&s", &computer_ou))
			computer_ou = NULL;
	}

	if (realm_name && !computer_ou) {
		section = g_utf8_casefold (realm_name, -1);
		computer_ou = realm_settings_value (section, REALM_DBUS_OPTION_COMPUTER_OU);
		g_free (section);
	}

	return g_strdup (computer_ou);
}

gboolean
realm_options_automatic_mapping (GVariant *options,
                                 const gchar *realm_name)
{
	gboolean mapping = FALSE;
	gboolean option = FALSE;
	gchar *section;

	if (options) {
		option = g_variant_lookup (options, REALM_DBUS_OPTION_AUTOMATIC_ID_MAPPING, "b", &mapping);
	}

	if (realm_name && !option) {
		section = g_utf8_casefold (realm_name, -1);
		mapping = realm_settings_boolean (realm_name, REALM_DBUS_OPTION_AUTOMATIC_ID_MAPPING, TRUE);
		g_free (section);
	}

	return mapping;
}

gboolean
realm_options_automatic_join (const gchar *realm_name)
{
	gchar *section;
	gboolean mapping;

	section = g_utf8_casefold (realm_name, -1);
	mapping = realm_settings_boolean (realm_name, "automatic-join", FALSE);
	g_free (section);

	return mapping;
}

gboolean
realm_options_qualify_names (const gchar *realm_name)
{
	gchar *section;
	gboolean qualify;

	section = g_utf8_casefold (realm_name, -1);
	qualify = realm_settings_boolean (realm_name, "fully-qualified-names", TRUE);
	g_free (section);

	return qualify;
}

gboolean
realm_options_check_domain_name (const gchar *name)
{
	/*
	 * DNS Domain names are pretty liberal (internet domain names
	 * are more restrictive) See RFC 2181 section 11
	 *
	 * http://www.ietf.org/rfc/rfc2181.txt
	 *
	 * However we cannot consume names with whitespace and problematic
	 * punctuation, due to the various programs that parse the
	 * configuration files we set up.
	 */

	gsize i, len;
	static const gchar *invalid = "=[]:";

	g_return_val_if_fail (name != NULL, FALSE);

	for (i = 0, len = strlen (name); i < len; i++) {
		if (name[i] <= ' ')
			return FALSE;
		if (strchr (invalid, name[i]))
			return FALSE;
	}

	return TRUE;
}

const gchar *
realm_options_computer_name (GVariant *options,
                           const gchar *realm_name)
{
	const gchar *computer_name = NULL;
	gchar *section;

	if (options) {
		if (!g_variant_lookup (options, REALM_DBUS_OPTION_COMPUTER_NAME, "&s", &computer_name))
			computer_name = NULL;
	}

	if (realm_name && !computer_name) {
		section = g_utf8_casefold (realm_name, -1);
		computer_name = realm_settings_value (section, REALM_DBUS_OPTION_COMPUTER_NAME);
		g_free (section);
	}

	return g_strdup (computer_name);
}

const gchar *
realm_options_ad_specific (GVariant *options,
                           const gchar *option_name)
{
	const gchar *value = NULL;

	if (options) {
		if (!g_variant_lookup (options, option_name, "&s", &value))
			value = NULL;
	}

	if (!value) {
		value = realm_settings_value ("active-directory", option_name);
	}

	return g_strdup (value);
}