libgpo/gpo_fetch.c

説明を見る。
00001 /* 
00002  *  Unix SMB/CIFS implementation.
00003  *  Group Policy Object Support
00004  *  Copyright (C) Guenther Deschner 2005-2006
00005  *  
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *  
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *  
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #include "includes.h"
00022 
00023 /****************************************************************
00024  explode the GPO CIFS URI into their components
00025 ****************************************************************/
00026 
00027 NTSTATUS ads_gpo_explode_filesyspath(ADS_STRUCT *ads, 
00028                                      TALLOC_CTX *mem_ctx, 
00029                                      const char *file_sys_path, 
00030                                      char **server, 
00031                                      char **service, 
00032                                      char **nt_path,
00033                                      char **unix_path)
00034 {
00035         fstring tok;
00036         pstring path;
00037 
00038         *server = NULL;
00039         *service = NULL;
00040         *nt_path = NULL;
00041         *unix_path = NULL;
00042 
00043         if (!next_token(&file_sys_path, tok, "\\", sizeof(tok))) {
00044                 return NT_STATUS_INVALID_PARAMETER;
00045         }
00046 
00047         if ((*server = talloc_strdup(mem_ctx, tok)) == NULL) {
00048                 return NT_STATUS_NO_MEMORY;
00049         }
00050 
00051         if (!next_token(&file_sys_path, tok, "\\", sizeof(tok))) {
00052                 return NT_STATUS_INVALID_PARAMETER;
00053         }
00054 
00055         if ((*service = talloc_strdup(mem_ctx, tok)) == NULL) {
00056                 return NT_STATUS_NO_MEMORY;
00057         }
00058 
00059         if ((*nt_path = talloc_asprintf(mem_ctx, "\\%s", file_sys_path)) == NULL) {
00060                 return NT_STATUS_NO_MEMORY;
00061         }
00062 
00063         pstrcpy(path, lock_path(GPO_CACHE_DIR));
00064         pstrcat(path, "/");
00065         pstrcat(path, file_sys_path);
00066         pstring_sub(path, "\\", "/");
00067 
00068         if ((*unix_path = talloc_strdup(mem_ctx, path)) == NULL) {
00069                 return NT_STATUS_NO_MEMORY;
00070         }
00071 
00072         return NT_STATUS_OK;
00073 }
00074 
00075 /****************************************************************
00076  prepare the local disc storage for "unix_path"
00077 ****************************************************************/
00078 
00079 NTSTATUS ads_gpo_prepare_local_store(ADS_STRUCT *ads, 
00080                                      TALLOC_CTX *mem_ctx, 
00081                                      const char *unix_path)
00082 {
00083         const char *top_dir = lock_path(GPO_CACHE_DIR);
00084         char *current_dir;
00085         fstring tok;
00086 
00087         current_dir = talloc_strdup(mem_ctx, top_dir);
00088         NT_STATUS_HAVE_NO_MEMORY(current_dir);
00089 
00090         if ((mkdir(top_dir, 0644)) < 0 && errno != EEXIST) {
00091                 return NT_STATUS_ACCESS_DENIED;
00092         }
00093 
00094         while (next_token(&unix_path, tok, "/", sizeof(tok))) {
00095         
00096                 if (strequal(tok, GPO_CACHE_DIR)) {
00097                         break;
00098                 }
00099         }
00100 
00101         while (next_token(&unix_path, tok, "/", sizeof(tok))) {
00102 
00103                 current_dir = talloc_asprintf_append(current_dir, "/%s", tok);
00104                 NT_STATUS_HAVE_NO_MEMORY(current_dir);
00105 
00106                 if ((mkdir(current_dir, 0644)) < 0 && errno != EEXIST) {
00107                         return NT_STATUS_ACCESS_DENIED;
00108                 }
00109         }
00110 
00111         return NT_STATUS_OK;
00112 }
00113 
00114 /****************************************************************
00115  download a full GPO via CIFS
00116 ****************************************************************/
00117 
00118 NTSTATUS ads_fetch_gpo_files(ADS_STRUCT *ads, 
00119                             TALLOC_CTX *mem_ctx, 
00120                             struct cli_state *cli, 
00121                             struct GROUP_POLICY_OBJECT *gpo)
00122 {
00123         NTSTATUS result;
00124         char *server, *service, *nt_path, *unix_path, *nt_ini_path, *unix_ini_path;
00125 
00126         result = ads_gpo_explode_filesyspath(ads, mem_ctx, gpo->file_sys_path, 
00127                                              &server, &service, &nt_path, &unix_path);
00128         if (!NT_STATUS_IS_OK(result)) {
00129                 goto out;
00130         }
00131 
00132         result = ads_gpo_prepare_local_store(ads, mem_ctx, unix_path);
00133         if (!NT_STATUS_IS_OK(result)) {
00134                 goto out;
00135         }
00136 
00137         unix_ini_path = talloc_asprintf(mem_ctx, "%s/%s", unix_path, GPT_INI);
00138         nt_ini_path = talloc_asprintf(mem_ctx, "%s\\%s", nt_path, GPT_INI);
00139         if (!unix_path || !nt_ini_path) {
00140                 result = NT_STATUS_NO_MEMORY;
00141                 goto out;
00142         }
00143 
00144         result = gpo_copy_file(mem_ctx, cli, nt_ini_path, unix_ini_path);
00145         if (!NT_STATUS_IS_OK(result)) {
00146                 goto out;
00147         }
00148 
00149         result = gpo_sync_directories(mem_ctx, cli, nt_path, unix_path);
00150         if (!NT_STATUS_IS_OK(result)) {
00151                 goto out;
00152         }
00153 
00154         result = NT_STATUS_OK;
00155 
00156  out:
00157         return result;
00158 }
00159 
00160 /****************************************************************
00161  get the locally stored gpt.ini version number
00162 ****************************************************************/
00163 
00164 NTSTATUS ads_gpo_get_sysvol_gpt_version(ADS_STRUCT *ads, 
00165                                         TALLOC_CTX *mem_ctx, 
00166                                         const char *unix_path, 
00167                                         uint32 *sysvol_version,
00168                                         char **display_name)
00169 {
00170         NTSTATUS status;
00171         uint32 version;
00172         char *local_path = NULL;
00173         char *name = NULL;
00174 
00175         local_path = talloc_asprintf(mem_ctx, "%s/%s", unix_path, GPT_INI);
00176         NT_STATUS_HAVE_NO_MEMORY(local_path);
00177 
00178         status = parse_gpt_ini(mem_ctx, local_path, &version, &name);
00179         if (!NT_STATUS_IS_OK(status)) {
00180                 DEBUG(10,("ads_gpo_get_sysvol_gpt_version: failed to parse ini [%s]: %s\n", 
00181                         unix_path, nt_errstr(status)));
00182                 return status;
00183         }
00184 
00185         if (sysvol_version) {
00186                 *sysvol_version = version;
00187         }
00188 
00189         if (name && *display_name) {
00190                 *display_name = talloc_strdup(mem_ctx, name);
00191                 NT_STATUS_HAVE_NO_MEMORY(*display_name);
00192         }
00193 
00194         return NT_STATUS_OK;
00195 }

Sambaに対してSat Aug 29 21:23:01 2009に生成されました。  doxygen 1.4.7