VirtualBox

source: vbox/trunk/src/VBox/Main/include/UnattendedScript.h@ 107044

Last change on this file since 107044 was 106061, checked in by vboxsync, 2 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/* $Id: UnattendedScript.h 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * Classes for reading/parsing/saving scripts for unattended installation.
4 */
5
6/*
7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#ifndef MAIN_INCLUDED_UnattendedScript_h
29#define MAIN_INCLUDED_UnattendedScript_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include "TextScript.h"
35#include "iprt/expreval.h"
36
37using namespace xml;
38
39class Unattended;
40
41
42/**
43 * Generic unattended text script template editor.
44 *
45 * This just perform variable replacements, no other editing possible.
46 *
47 * Everything happens during saveToString, parse is a noop.
48 */
49class UnattendedScriptTemplate : public BaseTextScript
50{
51protected:
52 /** Where to get the replacement strings from. */
53 Unattended *mpUnattended;
54
55public:
56 DECLARE_TRANSLATE_METHODS(UnattendedScriptTemplate)
57
58 UnattendedScriptTemplate(Unattended *pUnattended, const char *pszDefaultTemplateFilename, const char *pszDefaultFilename);
59 virtual ~UnattendedScriptTemplate() {}
60
61 HRESULT parse() { return S_OK; }
62 HRESULT saveToString(Utf8Str &rStrDst);
63
64protected:
65 typedef enum
66 {
67 kValueEscaping_None,
68 kValueEscaping_Bourne,
69 kValueEscaping_XML_Element,
70 kValueEscaping_XML_Attribute_Double_Quotes
71 } kEvalEscaping_T;
72
73 /**
74 * Gets the replacement value for the given placeholder.
75 *
76 * @returns COM status code.
77 * @param pachPlaceholder The placholder string. Not zero terminated.
78 * @param cchPlaceholder The length of the placeholder.
79 * @param fOutputting Indicates whether we actually need the correct value
80 * or is just syntax checking excluded template parts.
81 * @param rValue Where to return the value.
82 */
83 HRESULT getReplacement(const char *pachPlaceholder, size_t cchPlaceholder, bool fOutputting, RTCString &rValue);
84
85 /**
86 * Gets the replacement value for the given expression placeholder
87 * (@@VBOX_INSERT[expr]@@ and friends).
88 *
89 * @returns COM status code.
90 * @param hEvaluator The evaluator to use for the expression.
91 * @param pachPlaceholder The placholder string. Not zero terminated.
92 * @param cchPlaceholder The length of the placeholder.
93 * @param fOutputting Indicates whether we actually need the correct value
94 * or is just syntax checking excluded template parts.
95 * @param ppszValue Where to return the value. Free by calling
96 * RTStrFree. Set to NULL for empty string.
97 */
98 HRESULT getReplacementForExpr(RTEXPREVAL hEvaluator, const char *pachPlaceholder, size_t cchPlaceholder,
99 bool fOutputting, char **ppszValue) RT_NOEXCEPT;
100
101 /**
102 * Resolves a conditional expression.
103 *
104 * @returns COM status code.
105 * @param hEvaluator The evaluator to use for the expression.
106 * @param pachPlaceholder The placholder string. Not zero terminated.
107 * @param cchPlaceholder The length of the placeholder.
108 * @param pfOutputting Where to return the result of the conditional. This
109 * holds the current outputting state on input in case
110 * someone want to sanity check anything.
111 */
112 HRESULT resolveConditionalExpr(RTEXPREVAL hEvaluator, const char *pachPlaceholder, size_t cchPlaceholder,
113 bool *pfOutputting) RT_NOEXCEPT;
114
115 /** @callback_method_impl{FNRTEXPREVALQUERYVARIABLE} */
116 static DECLCALLBACK(int) queryVariableForExpr(const char *pchName, size_t cchName, void *pvUser,
117 char **ppszValue) RT_NOEXCEPT;
118
119 /**
120 * Gets a variable.
121 *
122 * This is used both for getting replacements (@@VBOX_INSERT_XXX@@) and in
123 * expressions (@@VBOX_INSERT[expr]@@, @@VBOX_COND[expr]@@).
124 *
125 * @returns VBox status code.
126 * @retval VERR_NOT_FOUND if variable does not exist.
127 *
128 * @param pchName The variable name. Not zero terminated.
129 * Will return hashed values if the variable name ends with
130 * "_MD5", _SHA1", "_SHA256" or "_SHA512".
131 * @param cchName The length of the name.
132 * @param rstrTmp String object that can be used for keeping the
133 * value returned via @a *ppszValue.
134 * @param ppszValue If a value is desired, this is where to return
135 * it. This points to a string that should be
136 * accessible for a little while after the function
137 * returns. Use @a rstrTmp for storage if
138 * necessary.
139 *
140 * This will be NULL when called from the 'defined'
141 * operator. In which case no errors should be
142 * set.
143 * @throws std::bad_alloc
144 * @see FNRTEXPREVALQUERYVARIABLE
145 */
146 virtual int queryVariable(const char *pchName, size_t cchName, Utf8Str &rstrTmp, const char **ppszValue);
147
148 /**
149 * Get the result of a conditional.
150 *
151 * @returns COM status code.
152 * @param pachPlaceholder The placholder string. Not zero terminated.
153 * @param cchPlaceholder The length of the placeholder.
154 * @param pfOutputting Where to return the result of the conditional.
155 * This holds the current outputting state on input
156 * in case someone want to sanity check anything.
157 */
158 virtual HRESULT getConditional(const char *pachPlaceholder, size_t cchPlaceholder, bool *pfOutputting);
159
160 /**
161 * Static function to generate a salt for the RTShaCryptXXX functions.
162 *
163 * @returns VBox status code.
164 * @param pszSalt Where to store the salt on success.
165 * @param cchSalt Size (in characters) of \a pszSalt. Not including terminator.
166 * This also specifies how long the generated salt will be.
167 * Must be >= RT_SHACRYPT_MIN_SALT_LEN and <= RT_SHACRYPT_MAX_SALT_LEN.
168 */
169 static int shaCryptGenerateSalt(char *pszSalt, size_t cchSalt);
170};
171
172#if 0 /* convert when we fix SUSE */
173/**
174 * SUSE unattended XML file editor.
175 */
176class UnattendedSUSEXMLScript : public UnattendedXMLScript
177{
178public:
179 DECLARE_TRANSLATE_METHODS(UnattendedSUSEXMLScript)
180
181 UnattendedSUSEXMLScript(VirtualBoxBase *pSetError, const char *pszDefaultFilename = "autoinst.xml")
182 : UnattendedXMLScript(pSetError, pszDefaultFilename) {}
183 ~UnattendedSUSEXMLScript() {}
184
185 HRESULT parse();
186
187protected:
188 HRESULT setFieldInElement(xml::ElementNode *pElement, const DataId enmDataId, const Utf8Str &rStrValue);
189
190private:
191 //////////////////New functions//////////////////////////////
192 /** @throws std::bad_alloc */
193 HRESULT LoopThruSections(const xml::ElementNode *pelmRoot);
194 /** @throws std::bad_alloc */
195 HRESULT HandleUserAccountsSection(const xml::ElementNode *pelmSection);
196 /** @throws std::bad_alloc */
197 Utf8Str createProbableValue(const DataId enmDataId, const xml::ElementNode *pCurElem);
198 /** @throws std::bad_alloc */
199 Utf8Str createProbableUserHomeDir(const xml::ElementNode *pCurElem);
200 //////////////////New functions//////////////////////////////
201};
202#endif
203
204
205#endif /* !MAIN_INCLUDED_UnattendedScript_h */
206
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette