summaryrefslogtreecommitdiff
path: root/source3/libsmb/gpo.c
blob: 6be2ce2f7958f4019b8377f3bc47d33c6ce0ed00 (plain)
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
/* 
 *  Unix SMB/CIFS implementation.
 *  Group Policy Object Support
 *  Copyright (C) Guenther Deschner 2005
 *  
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "includes.h"

#ifdef HAVE_LDAP

#define GPT_INI_SECTION_GENERAL "General"
#define GPT_INI_PARAMETER_VERSION "Version"
#define GPT_INI_PARAMETER_DISPLAYNAME "displayName"

struct gpt_ini {
	uint32 version;
	const char *display_name;
};

static uint32 version;

static BOOL do_section(const char *section)
{
	DEBUG(10,("do_section: %s\n", section));

	return True;
}

static BOOL do_parameter(const char *parameter, const char *value)
{
	DEBUG(10,("do_parameter: %s, %s\n", parameter, value));
	
	if (strequal(parameter, GPT_INI_PARAMETER_VERSION)) {
		version = atoi(value);
	}
	return True;
}

NTSTATUS ads_gpo_get_sysvol_gpt_version(ADS_STRUCT *ads, 
					TALLOC_CTX *mem_ctx, 
					const char *filesyspath, 
					uint32 *sysvol_version)
{
	NTSTATUS status;
	const char *path;
	struct cli_state *cli;
	int fnum;
	fstring tok;
	static int io_bufsize = 64512;
	int read_size = io_bufsize;
	char *data = NULL;
	off_t start = 0;
	off_t nread = 0;
	int handle = 0;
	const char *local_file;

	*sysvol_version = 0;

	next_token(&filesyspath, tok, "\\", sizeof(tok));
	next_token(&filesyspath, tok, "\\", sizeof(tok));

	path = talloc_asprintf(mem_ctx, "\\%s\\gpt.ini", filesyspath);
	if (path == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	local_file = talloc_asprintf(mem_ctx, "%s/%s", lock_path("gpo_cache"), "gpt.ini");
	if (local_file == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	/* FIXME: walk down the dfs tree instead */
	status = cli_full_connection(&cli, global_myname(), 
				     ads->config.ldap_server_name,
				     NULL, 0,
				     "SYSVOL", "A:",
				     ads->auth.user_name, NULL, ads->auth.password,
				     CLI_FULL_CONNECTION_USE_KERBEROS,
				     Undefined, NULL);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	fnum = cli_open(cli, path, O_RDONLY, DENY_NONE);
	if (fnum == -1) {
		return NT_STATUS_NO_SUCH_FILE;
	}


	data = (char *)SMB_MALLOC(read_size);
	if (data == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	handle = sys_open(local_file, O_WRONLY|O_CREAT|O_TRUNC, 0644);

	if (handle == -1) {
		return NT_STATUS_NO_SUCH_FILE;
	}
	 
	while (1) {

		int n = cli_read(cli, fnum, data, nread + start, read_size);

		if (n <= 0)
			break;

		if (write(handle, data, n) != n) {
			break;
		}

		nread += n;
	}

	cli_close(cli, fnum);

	if (!pm_process(local_file, do_section, do_parameter)) {
		return NT_STATUS_INVALID_PARAMETER;
	}

	*sysvol_version = version;

	SAFE_FREE(data);

	cli_shutdown(cli);

	return NT_STATUS_OK;
}

/*

perfectly parseable with pm_process() :))

[Unicode]
Unicode=yes
[System Access]
MinimumPasswordAge = 1
MaximumPasswordAge = 42
MinimumPasswordLength = 7
PasswordComplexity = 1
PasswordHistorySize = 24
LockoutBadCount = 0
RequireLogonToChangePassword = 0
ForceLogoffWhenHourExpire = 0
ClearTextPassword = 0
[Kerberos Policy]
MaxTicketAge = 10
MaxRenewAge = 7
MaxServiceAge = 600
MaxClockSkew = 5
TicketValidateClient = 1
[Version]
signature="$CHICAGO$"
Revision=1
*/

#endif /* HAVE_LDAP */