libgpo/gpo_parse.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 #include "iniparser/src/iniparser.h"
00023 
00024 /****************************************************************
00025  parse the local gpt.ini file
00026 ****************************************************************/
00027 
00028 #define GPT_INI_SECTION_GENERAL "General"
00029 #define GPT_INI_PARAMETER_VERSION "Version"
00030 #define GPT_INI_PARAMETER_DISPLAYNAME "displayName"
00031 
00032 NTSTATUS parse_gpt_ini(TALLOC_CTX *mem_ctx, const char *filename, uint32 *version, char **display_name)
00033 {
00034         NTSTATUS result;
00035         uint32 v;
00036         char *name = NULL;
00037         dictionary *d;
00038 
00039         d = iniparser_load(filename);
00040         if (d == NULL) {
00041                 return NT_STATUS_NO_SUCH_FILE;
00042         }
00043 
00044         if ((name = iniparser_getstring(d, GPT_INI_SECTION_GENERAL
00045                         ":"GPT_INI_PARAMETER_DISPLAYNAME, NULL)) == NULL) {
00046                 /* the default domain policy and the default domain controller
00047                  * policy never have a displayname in their gpt.ini file */
00048                 DEBUG(10,("parse_gpt_ini: no name in %s\n", filename));
00049         }
00050 
00051         if (name && display_name) {
00052                 *display_name = talloc_strdup(mem_ctx, name);
00053                 if (*display_name == NULL) {
00054                         result = NT_STATUS_NO_MEMORY;
00055                         goto out;
00056                 }
00057         }
00058 
00059         if ((v = iniparser_getint(d, GPT_INI_SECTION_GENERAL
00060                         ":"GPT_INI_PARAMETER_VERSION, Undefined)) == Undefined) {
00061                 DEBUG(10,("parse_gpt_ini: no version\n"));
00062                 result = NT_STATUS_INTERNAL_DB_CORRUPTION;
00063                 goto out;
00064         }
00065 
00066         if (version) {
00067                 *version = v;
00068         }
00069 
00070         result = NT_STATUS_OK;
00071  out:
00072         if (d) {
00073                 iniparser_freedict(d);
00074         }
00075 
00076         return result;
00077 }
00078 
00079 #if 0 /* not yet */
00080 
00081 /****************************************************************
00082  parse the Version section from gpttmpl file
00083 ****************************************************************/
00084 
00085 #define GPTTMPL_SECTION_VERSION "Version"
00086 #define GPTTMPL_PARAMETER_REVISION "Revision"
00087 #define GPTTMPL_PARAMETER_SIGNATURE "signature"
00088 #define GPTTMPL_CHICAGO "$CHICAGO$" /* whatever this is good for... */
00089 #define GPTTMPL_SECTION_UNICODE "Unicode"
00090 #define GPTTMPL_PARAMETER_UNICODE "Unicode"
00091 
00092 static NTSTATUS parse_gpttmpl(dictionary *d, uint32 *version_out)
00093 {
00094         const char *signature = NULL;
00095         uint32 version;
00096 
00097         if ((signature = iniparser_getstring(d, GPTTMPL_SECTION_VERSION
00098                         ":"GPTTMPL_PARAMETER_SIGNATURE, NULL)) == NULL) {
00099                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
00100         }
00101 
00102         if (!strequal(signature, GPTTMPL_CHICAGO)) {
00103                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
00104         }
00105 
00106         if ((version = iniparser_getint(d, GPTTMPL_SECTION_VERSION
00107                         ":"GPTTMPL_PARAMETER_REVISION, Undefined)) == Undefined) {
00108                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
00109         }
00110 
00111         if (version_out) {
00112                 *version_out = version;
00113         }
00114 
00115         /* treat that as boolean */
00116         if ((!iniparser_getboolean(d, GPTTMPL_SECTION_UNICODE
00117                         ":"GPTTMPL_PARAMETER_UNICODE, Undefined)) == Undefined) {
00118                 return NT_STATUS_INTERNAL_DB_CORRUPTION;
00119         }
00120 
00121         return NT_STATUS_OK;
00122 }
00123 
00124 /****************************************************************
00125  parse the "System Access" section from gpttmpl file
00126 ****************************************************************/
00127 
00128 #define GPTTMPL_SECTION_SYSTEM_ACCESS "System Access"
00129 #define GPTTMPL_PARAMETER_MINPWDAGE "MinimumPasswordAge"
00130 #define GPTTMPL_PARAMETER_MAXPWDAGE "MaximumPasswordAge"
00131 #define GPTTMPL_PARAMETER_MINPWDLEN "MinimumPasswordLength"
00132 #define GPTTMPL_PARAMETER_PWDCOMPLEX "PasswordComplexity"
00133 #define GPTTMPL_PARAMETER_PWDHISTORY "PasswordHistorySize"
00134 #define GPTTMPL_PARAMETER_LOCKOUTCOUNT "LockoutBadCount"
00135 
00136 static NTSTATUS parse_gpttmpl_system_access(const char *filename)
00137 {
00138         NTSTATUS status;
00139         dictionary *d = NULL;
00140         uint32 pwd_min_age, pwd_max_age, pwd_min_len, pwd_history;
00141         uint32 lockout_count;
00142         BOOL pwd_complex;
00143         uint32 version;
00144 
00145         d = iniparser_load(filename);
00146         if (d == NULL) {
00147                 return NT_STATUS_NO_SUCH_FILE;
00148         }
00149 
00150         status = parse_gpttmpl(d, &version);
00151         if (!NT_STATUS_IS_OK(status)) {
00152                 goto out;
00153         }
00154 
00155         status = NT_STATUS_INVALID_PARAMETER;
00156 
00157         if ((pwd_min_age = iniparser_getint(d, GPTTMPL_SECTION_SYSTEM_ACCESS
00158                         ":"GPTTMPL_PARAMETER_MINPWDAGE, Undefined)) == Undefined) {
00159                 goto out;
00160         }
00161 
00162         if ((pwd_max_age = iniparser_getint(d, GPTTMPL_SECTION_SYSTEM_ACCESS
00163                         ":"GPTTMPL_PARAMETER_MINPWDAGE, Undefined)) == Undefined) {
00164                 goto out;
00165         }
00166 
00167         if ((pwd_min_len = iniparser_getint(d, GPTTMPL_SECTION_SYSTEM_ACCESS
00168                         ":"GPTTMPL_PARAMETER_MINPWDLEN, Undefined)) == Undefined) {
00169                 goto out;
00170         }
00171 
00172         if ((pwd_complex = iniparser_getboolean(d, GPTTMPL_SECTION_SYSTEM_ACCESS
00173                         ":"GPTTMPL_PARAMETER_PWDCOMPLEX, Undefined)) == Undefined) {
00174                 goto out;
00175         }
00176 
00177         if ((pwd_history = iniparser_getint(d, GPTTMPL_SECTION_SYSTEM_ACCESS
00178                         ":"GPTTMPL_PARAMETER_PWDHISTORY, Undefined)) == Undefined) {
00179                 goto out;
00180         }
00181 
00182         if ((lockout_count = iniparser_getint(d, GPTTMPL_SECTION_SYSTEM_ACCESS
00183                         ":"GPTTMPL_PARAMETER_LOCKOUTCOUNT, Undefined)) == Undefined) {
00184                 goto out;
00185         }
00186 
00187         /* TODO ? 
00188         RequireLogonToChangePassword = 0
00189         ForceLogoffWhenHourExpire = 0
00190         ClearTextPassword = 0
00191         */
00192 
00193         status = NT_STATUS_OK;
00194 
00195  out:
00196         if (d) {
00197                 iniparser_freedict(d);
00198         }
00199 
00200         return status;
00201 }
00202 
00203 /****************************************************************
00204  parse the "Kerberos Policy" section from gpttmpl file
00205 ****************************************************************/
00206 
00207 #define GPTTMPL_SECTION_KERBEROS_POLICY "Kerberos Policy"
00208 #define GPTTMPL_PARAMETER_MAXTKTAGE "MaxTicketAge"
00209 #define GPTTMPL_PARAMETER_MAXRENEWAGE "MaxRenewAge"
00210 #define GPTTMPL_PARAMETER_MAXTGSAGE "MaxServiceAge"
00211 #define GPTTMPL_PARAMETER_MAXCLOCKSKEW "MaxClockSkew"
00212 #define GPTTMPL_PARAMETER_TKTVALIDATECLIENT "TicketValidateClient"
00213 
00214 static NTSTATUS parse_gpttmpl_kerberos_policy(const char *filename)
00215 {
00216         NTSTATUS status;
00217         dictionary *d = NULL;
00218         uint32 tkt_max_age, tkt_max_renew, tgs_max_age, max_clock_skew;
00219         BOOL tkt_validate;
00220         uint32 version;
00221 
00222         d = iniparser_load(filename);
00223         if (d == NULL) {
00224                 return NT_STATUS_NO_SUCH_FILE;
00225         }
00226 
00227         status = parse_gpttmpl(d, &version);
00228         if (!NT_STATUS_IS_OK(status)) {
00229                 goto out;
00230         }
00231 
00232         status = NT_STATUS_INVALID_PARAMETER;
00233 
00234         if ((tkt_max_age = iniparser_getint(d, GPTTMPL_SECTION_KERBEROS_POLICY
00235                         ":"GPTTMPL_PARAMETER_MAXTKTAGE, Undefined)) != Undefined) {
00236                 goto out;
00237         }
00238 
00239         if ((tkt_max_renew = iniparser_getint(d, GPTTMPL_SECTION_KERBEROS_POLICY
00240                         ":"GPTTMPL_PARAMETER_MAXRENEWAGE, Undefined)) != Undefined) {
00241                 goto out;
00242         }
00243 
00244         if ((tgs_max_age = iniparser_getint(d, GPTTMPL_SECTION_KERBEROS_POLICY
00245                         ":"GPTTMPL_PARAMETER_MAXTGSAGE, Undefined)) != Undefined) {
00246                 goto out;
00247         }
00248 
00249         if ((max_clock_skew = iniparser_getint(d, GPTTMPL_SECTION_KERBEROS_POLICY
00250                         ":"GPTTMPL_PARAMETER_MAXCLOCKSKEW, Undefined)) != Undefined) {
00251                 goto out;
00252         }
00253 
00254         if ((tkt_validate = iniparser_getboolean(d, GPTTMPL_SECTION_KERBEROS_POLICY
00255                         ":"GPTTMPL_PARAMETER_TKTVALIDATECLIENT, Undefined)) != Undefined) {
00256                 goto out;
00257         }
00258 
00259         status = NT_STATUS_OK;
00260 
00261  out:
00262         if (d) {
00263                 iniparser_freedict(d);
00264         }
00265 
00266         return status;
00267 }
00268 
00269 #endif
00270 
00271 /*
00272 
00273 perfectly parseable with iniparser:
00274 
00275 {GUID}/Machine/Microsoft/Windows NT/SecEdit/GptTmpl.inf
00276 
00277 
00278 [Unicode]
00279 Unicode=yes
00280 [System Access]
00281 MinimumPasswordAge = 1
00282 MaximumPasswordAge = 42
00283 MinimumPasswordLength = 7
00284 PasswordComplexity = 1
00285 PasswordHistorySize = 24
00286 LockoutBadCount = 0
00287 RequireLogonToChangePassword = 0
00288 ForceLogoffWhenHourExpire = 0
00289 ClearTextPassword = 0
00290 [Kerberos Policy]
00291 MaxTicketAge = 10
00292 MaxRenewAge = 7
00293 MaxServiceAge = 600
00294 MaxClockSkew = 5
00295 TicketValidateClient = 1
00296 [Version]
00297 signature="$CHICAGO$"
00298 Revision=1
00299 */

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