r18819: Fix build without LDAP.
[jra/samba/.git] / source / libsmb / gpo.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  Group Policy Object Support
4  *  Copyright (C) Guenther Deschner 2005
5  *  
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 #include "includes.h"
22
23 #ifdef HAVE_LDAP
24
25 #define GPT_INI_SECTION_GENERAL "General"
26 #define GPT_INI_PARAMETER_VERSION "Version"
27 #define GPT_INI_PARAMETER_DISPLAYNAME "displayName"
28
29 struct gpt_ini {
30         uint32 version;
31         const char *display_name;
32 };
33
34 static uint32 version;
35
36 static BOOL do_section(const char *section)
37 {
38         DEBUG(10,("do_section: %s\n", section));
39
40         return True;
41 }
42
43 static BOOL do_parameter(const char *parameter, const char *value)
44 {
45         DEBUG(10,("do_parameter: %s, %s\n", parameter, value));
46         
47         if (strequal(parameter, GPT_INI_PARAMETER_VERSION)) {
48                 version = atoi(value);
49         }
50         return True;
51 }
52
53 NTSTATUS ads_gpo_get_sysvol_gpt_version(ADS_STRUCT *ads, 
54                                         TALLOC_CTX *mem_ctx, 
55                                         const char *filesyspath, 
56                                         uint32 *sysvol_version)
57 {
58         NTSTATUS status;
59         const char *path;
60         struct cli_state *cli;
61         int fnum;
62         fstring tok;
63         static int io_bufsize = 64512;
64         int read_size = io_bufsize;
65         char *data = NULL;
66         off_t start = 0;
67         off_t nread = 0;
68         int handle = 0;
69         const char *local_file;
70
71         *sysvol_version = 0;
72
73         next_token(&filesyspath, tok, "\\", sizeof(tok));
74         next_token(&filesyspath, tok, "\\", sizeof(tok));
75
76         path = talloc_asprintf(mem_ctx, "\\%s\\gpt.ini", filesyspath);
77         if (path == NULL) {
78                 return NT_STATUS_NO_MEMORY;
79         }
80
81         local_file = talloc_asprintf(mem_ctx, "%s/%s", lock_path("gpo_cache"), "gpt.ini");
82         if (local_file == NULL) {
83                 return NT_STATUS_NO_MEMORY;
84         }
85
86         /* FIXME: walk down the dfs tree instead */
87         status = cli_full_connection(&cli, global_myname(), 
88                                      ads->config.ldap_server_name,
89                                      NULL, 0,
90                                      "SYSVOL", "A:",
91                                      ads->auth.user_name, NULL, ads->auth.password,
92                                      CLI_FULL_CONNECTION_USE_KERBEROS,
93                                      Undefined, NULL);
94         if (!NT_STATUS_IS_OK(status)) {
95                 return status;
96         }
97
98         fnum = cli_open(cli, path, O_RDONLY, DENY_NONE);
99         if (fnum == -1) {
100                 return NT_STATUS_NO_SUCH_FILE;
101         }
102
103
104         data = (char *)SMB_MALLOC(read_size);
105         if (data == NULL) {
106                 return NT_STATUS_NO_MEMORY;
107         }
108
109         handle = sys_open(local_file, O_WRONLY|O_CREAT|O_TRUNC, 0644);
110
111         if (handle == -1) {
112                 return NT_STATUS_NO_SUCH_FILE;
113         }
114          
115         while (1) {
116
117                 int n = cli_read(cli, fnum, data, nread + start, read_size);
118
119                 if (n <= 0)
120                         break;
121
122                 if (write(handle, data, n) != n) {
123                         break;
124                 }
125
126                 nread += n;
127         }
128
129         cli_close(cli, fnum);
130
131         if (!pm_process(local_file, do_section, do_parameter)) {
132                 return NT_STATUS_INVALID_PARAMETER;
133         }
134
135         *sysvol_version = version;
136
137         SAFE_FREE(data);
138
139         cli_shutdown(cli);
140
141         return NT_STATUS_OK;
142 }
143
144 /*
145
146 perfectly parseable with pm_process() :))
147
148 [Unicode]
149 Unicode=yes
150 [System Access]
151 MinimumPasswordAge = 1
152 MaximumPasswordAge = 42
153 MinimumPasswordLength = 7
154 PasswordComplexity = 1
155 PasswordHistorySize = 24
156 LockoutBadCount = 0
157 RequireLogonToChangePassword = 0
158 ForceLogoffWhenHourExpire = 0
159 ClearTextPassword = 0
160 [Kerberos Policy]
161 MaxTicketAge = 10
162 MaxRenewAge = 7
163 MaxServiceAge = 600
164 MaxClockSkew = 5
165 TicketValidateClient = 1
166 [Version]
167 signature="$CHICAGO$"
168 Revision=1
169 */
170
171 #endif /* HAVE_LDAP */