source: client/engine/Registry.lib @ 18679ed

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 18679ed was 1cd64e6, checked in by ramon <ramongomez@…>, 14 years ago

Versión 1.0.2: Continuar depurando el motor de clonación:

  • Revisar variables locales.
  • Ayudas de las funciones.
  • Incluir fecha y hora en mensajes de logs.

Modifica ticket #446.

git-svn-id: https://opengnsys.es/svn/branches/version1.0@2348 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 12.8 KB
RevLine 
[9f577259]1#!/bin/bash
2#/**
3#@file    Registry.lib
4#@brief   Librería o clase Registry
5#@class   Boot
6#@brief   Funciones para gestión del registro de Windows.
7#@version 1.0.1
8#@warning License: GNU GPLv3+
9#*/
10
11
12#/**
13#         ogAddRegistryKey path_mountpoint str_hive str_keyname
14#@brief   Añade una nueva clave al registro de Windows.
[bf18bcbd]15#@param   path_mountpoint  directorio donde está montado el sistema Windows
16#@param   str_hive         sección del registro
17#@param   str_keyname      nombre de la clave
18#@return  (nada)
19#@exception OG_ERR_FORMAT    Formato incorrecto.
20#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
21#@note    hive = { default, sam, security, software, system, components }
22#@warning Requisitos: chntpw
23#@warning El sistema de archivos de Windows debe estar montada previamente.
[9f577259]24#@version 1.0.1 - Nueva función
25#@author  Ramon Gomez, ETSII Universidad de Sevilla
[cd2ae87]26#@date    2011-05-25
[9f577259]27#*/ ##
[1b804cc]28function ogAddRegistryKey ()
[9f577259]29{
[cd2ae87]30# Variables locales.
31local FILE
[9f577259]32
[cd2ae87]33# Si se solicita, mostrar ayuda.
34if [ "$*" == "help" ]; then
[bf18bcbd]35    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \
36           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey'"
[cd2ae87]37    return
38fi
39# Error si no se reciben 3 parámetros.
40[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
41# Camino del fichero de registro.
42FILE=$(ogGetHivePath "$1" "$2") || return $?
[9f577259]43
[cd2ae87]44# Añadir nueva clave.
[367e04d]45chntpw "$FILE" << EOT &> /dev/null
[3907aaf]46cd ${3%\\*}
47nk ${3##*\\}
[cd2ae87]48q
49y
50EOT
[1b804cc]51}
52
53#/**
[9570719]54#         ogAddRegistryValue path_mountpoint str_hive str_valuename [str_valuetype]
55#@brief   Añade un nuevo valor al registro de Windows, indicando su tipo de datos.
[bf18bcbd]56#@param   path_mountpoint  directorio donde está montado el sistema Windows
57#@param   str_hive         sección del registro
58#@param   str_valuename    nombre del valor
59#@param   str_valuetype    tipo de datos del valor (opcional)
60#@return  (nada)
61#@exception OG_ERR_FORMAT    Formato incorrecto.
62#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
[1cd64e6]63#@note    hive = { DEFAULT, SAM, SECURITY, SOFTWARE, SYSTEM, COMPONENTS }
64#@note    valuetype = { STRING, BINARY, DWORD }, por defecto: STRING
[bf18bcbd]65#@warning Requisitos: chntpw
66#@warning El sistema de archivos de Windows debe estar montada previamente.
[1b804cc]67#@version 1.0.1 - Nueva función
68#@author  Ramon Gomez, ETSII Universidad de Sevilla
[9570719]69#@date    2011-05-25
[1b804cc]70#*/ ##
[cd2ae87]71function ogAddRegistryValue ()
[1b804cc]72{
[9570719]73# Variables locales.
74local FILE TYPE
75
76# Si se solicita, mostrar ayuda.
77if [ "$*" == "help" ]; then
[bf18bcbd]78    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename [str_valuetype]" \
79           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1'" \
80           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1' DWORD"
[9570719]81    return
82fi
83# Error si no se reciben 3 o 4 parámetros.
84[ $# == 3 -o $# == 4 ] || ogRaiseError $OG_ERR_FORMAT || return $?
85# Camino del fichero de registro.
86FILE=$(ogGetHivePath "$1" "$2") || return $?
87case "$4" in
88    string|STRING|"")  TYPE=1 ;;
89    binary|BINARY)     TYPE=3 ;;
90    dword|DWORD)       TYPE=4 ;;
91    *)                 ogRaiseError $OG_ERR_OUTOFLIMIT "$4"
[367e04d]92                       return $? ;;
[9570719]93esac
94
95# Devolver el dato del valor de registro.
96# /* (comentario Doxygen)
[367e04d]97chntpw "$FILE" << EOT &> /dev/null
[9570719]98cd ${3%\\*}
99nv $TYPE ${3##*\\}
100q
101y
102EOT
103# (comentario Doxygen) */
[1b804cc]104}
105
106
107#/**
108#         ogDeleteRegistryKey path_mountpoint str_hive str_keyname
109#@brief   Elimina una clave del registro de Windows con todo su contenido.
[bf18bcbd]110#@param   path_mountpoint  directorio donde está montado el sistema Windows
111#@param   str_hive         sección del registro
112#@param   str_keyname      nombre de la clave
113#@return  (nada)
114#@exception OG_ERR_FORMAT    Formato incorrecto.
115#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
116#@note    hive = { default, sam, security, software, system, components }
117#@warning Requisitos: chntpw
118#@warning El sistema de archivos de Windows debe estar montada previamente.
119#@warning La clave debe estar vacía para poder ser borrada.
[1b804cc]120#@version 1.0.1 - Nueva función
121#@author  Ramon Gomez, ETSII Universidad de Sevilla
[cd2ae87]122#@date    2011-05-25
[1b804cc]123#*/ ##
124function ogDeleteRegistryKey ()
125{
[cd2ae87]126# Variables locales.
127local FILE
128
129# Si se solicita, mostrar ayuda.
130if [ "$*" == "help" ]; then
[bf18bcbd]131    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \
132           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey'"
[cd2ae87]133    return
134fi
135# Error si no se reciben 3 parámetros.
136[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
137# Camino del fichero de registro.
138FILE=$(ogGetHivePath "$1" "$2") || return $?
139
140# Añadir nueva clave.
[367e04d]141chntpw "$FILE" << EOT &> /dev/null
[3907aaf]142cd ${3%\\*}
143dk ${3##*\\}
[cd2ae87]144q
145y
146EOT
[1b804cc]147}
148
[1cd64e6]149
[1b804cc]150#/**
[bf18bcbd]151#         ogDeleteRegistryValue path_mountpoint str_hive str_valuename
[1b804cc]152#@brief   Elimina un valor del registro de Windows.
[bf18bcbd]153#@param   path_mountpoint  directorio donde está montado el sistema Windows
154#@param   str_hive         sección del registro
155#@param   str_valuename    nombre del valor
156#@return  (nada)
157#@exception OG_ERR_FORMAT    Formato incorrecto.
158#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
159#@note    hive = { default, sam, security, software, system, components }
160#@warning Requisitos: chntpw
161#@warning El sistema de archivos de Windows debe estar montada previamente.
[1b804cc]162#@version 1.0.1 - Nueva función
163#@author  Ramon Gomez, ETSII Universidad de Sevilla
[cd2ae87]164#@date    2011-05-25
[1b804cc]165#*/ ##
166function ogDeleteRegistryValue ()
167{
[cd2ae87]168# Variables locales.
169local FILE
170
171# Si se solicita, mostrar ayuda.
172if [ "$*" == "help" ]; then
[bf18bcbd]173    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename" \
174           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1'"
[cd2ae87]175    return
176fi
177# Error si no se reciben 3 parámetros.
178[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
179# Camino del fichero de registro.
180FILE=$(ogGetHivePath "$1" "$2") || return $?
181
182# Devolver el dato del valor de registro.
183# /* (comentario Doxygen)
[367e04d]184chntpw "$FILE" << EOT &> /dev/null
[cd2ae87]185cd ${3%\\*}
186dv ${3##*\\}
187q
188y
189EOT
190# (comentario Doxygen) */
[1b804cc]191}
192
193
194#/**
195#         ogGetHivePath path_mountpoint str_hive
[9f577259]196#@brief   Función básica que devuelve el camino del fichero con una sección del registro.
197#@param   path_mountpoint  directorio donde está montado el sistema Windows
198#@param   str_hive         sección del registro
199#@return  str_path - camino del fichero de registro
200#@exception OG_ERR_FORMAT    Formato incorrecto.
[bf18bcbd]201#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
[1cd64e6]202#@note    hive = { DEFAULT, SAM, SECURITY, SOFTWARE, SYSTEM, COMPONENTS }
[9f577259]203#@warning El sistema de archivos de Windows debe estar montada previamente.
204#@version 1.0.1 - Nueva función
205#@author  Ramon Gomez, ETSII Universidad de Sevilla
206#@date    2011-05-18
207#*/ ##
[1b804cc]208function ogGetHivePath ()
[9f577259]209{
210# Variables locales.
211local FILE FILENT FILEXP
212
213# Si se solicita, mostrar ayuda.
214if [ "$*" == "help" ]; then
215    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive"
[1cd64e6]216           "$FUNCNAME /mnt/sda1 SOFTWARE  => /mnt/sda1/WINDOWS/System32/config/SOFTWARE"
[9f577259]217    return
218fi
219# Error si no se reciben 2 parámetros.
220[ $# == 2 ] || ogRaiseError $OG_ERR_FORMAT || return $?
221
222# Camino del fichero de registro en NT/2000 o XP/Vista/7.
223FILENT=$(ogGetPath "/$1/winnt/system32/config/$2")
224[ -f $FILENT ] && FILE="$FILENT"
225FILEXP=$(ogGetPath "/$1/windows/system32/config/$2")
226[ -f $FLEHXP ] && FILE="$FILEXP"
227[ ! -f $FILE ] && ogRaiseError OG_ERR_NOTFOUND "$1,$2" && return $?
228
229echo "$FILE"
230}
231
232
233#/**
234#         ogGetRegistryValue path_mountpoint str_hive str_valuename
235#@brief   Devuelve el dato de un valor del registro de Windows.
236#@param   path_mountpoint  directorio donde está montado el sistema Windows
237#@param   str_hive         sección del registro
238#@param   str_valuename    nombre del valor
239#@return  str_valuedata - datos del valor.
240#@exception OG_ERR_FORMAT    Formato incorrecto.
[bf18bcbd]241#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
[9f577259]242#@note    hive = { default, sam, security, software, system, components }
243#@warning Requisitos: chntpw, awk
[bf18bcbd]244#@warning El sistema de archivos de Windows debe estar montado previamente.
[9f577259]245#@version 0.9 - Adaptación para OpenGNSys.
246#@author  Ramon Gomez, ETSII Universidad de Sevilla
247#@date    2009-09-11
248#*/ ##
249function ogGetRegistryValue ()
250{
251# Variables locales.
252local FILE
253
254# Si se solicita, mostrar ayuda.
255if [ "$*" == "help" ]; then
[bf18bcbd]256    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename" \
257           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1'  ==>  1"
[9f577259]258    return
259fi
260# Error si no se reciben 3 parámetros.
261[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
262# Camino del fichero de registro.
[1b804cc]263FILE=$(ogGetHivePath "$1" "$2") || return $?
[9f577259]264
265# Devolver el dato del valor de registro.
266# /* (comentario Doxygen)
[367e04d]267chntpw "$FILE" << EOT 2> /dev/null | awk '/> Value/ {getline;print $0;}'
[9f577259]268cd ${3%\\*}
269cat ${3##*\\}
270q
[cd2ae87]271EOT
[9f577259]272# (comentario Doxygen) */
273}
274
275
276#/**
[3907aaf]277#         ogListRegistryKeys path_mountpoint str_hive str_key
278#@brief   Lista los nombres de subclaves de una determinada clave del registro de Windows.
[9f577259]279#@param   path_mountpoint  directorio donde está montado el sistema Windows
280#@param   str_hive         sección del registro
281#@param   str_key          clave de registro
282#@return  str_subkey ... - lista de subclaves
283#@exception OG_ERR_FORMAT    Formato incorrecto.
[bf18bcbd]284#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
[9f577259]285#@note    hive = { default, sam, security, software, system, components }
286#@warning Requisitos: chntpw, awk
[bf18bcbd]287#@warning El sistema de archivos de Windows debe estar montado previamente.
[9f577259]288#@version 0.9 - Adaptación para OpenGNSys.
289#@author  Ramon Gomez, ETSII Universidad de Sevilla
290#@date    2009-09-23
291#*/ ##
[3907aaf]292function ogListRegistryKeys ()
[9f577259]293{
294# Variables locales.
295local FILE
296
297# Si se solicita, mostrar ayuda.
298if [ "$*" == "help" ]; then
[bf18bcbd]299    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \
300           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\Windows\CurrentVersion'"
[9f577259]301    return
302fi
303# Error si no se reciben 3 parámetros.
304[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
305
306# Camino del fichero de registro.
[1b804cc]307FILE=$(ogGetHivePath "$1" "$2") || return $?
[9f577259]308
309# Devolver la lista de claves de registro.
[367e04d]310chntpw "$FILE" << EOT 2> /dev/null | awk 'BEGIN {FS="[<>]"} $1~/^  $/ {print $2}'
[9f577259]311ls $3
312q
[9570719]313EOT
[9f577259]314}
315
316
317#/**
[3907aaf]318#         ogListRegistryValues path_mountpoint str_hive str_key
319#@brief   Lista los nombres de valores de una determinada clave del registro de Windows.
[bf18bcbd]320#@param   path_mountpoint  directorio donde está montado el sistema Windows
321#@param   str_hive         sección del registro
322#@param   str_key          clave de registro
323#@return  str_value ... - lista de valores
324#@exception OG_ERR_FORMAT    Formato incorrecto.
325#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
326#@note    hive = { default, sam, security, software, system, components }
327#@warning Requisitos: chntpw, awk
328#@warning El sistema de archivos de Windows debe estar montado previamente.
[3907aaf]329#@version 1.0.1 - Nueva función.
330#@author  Ramon Gomez, ETSII Universidad de Sevilla
331#@date    2011-05-26
332#*/ ##
333function ogListRegistryValues ()
334{
335# Variables locales.
336local FILE
337
338# Si se solicita, mostrar ayuda.
339if [ "$*" == "help" ]; then
[bf18bcbd]340    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \
341           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\Windows\CurrentVersion'"
[3907aaf]342    return
343fi
344# Error si no se reciben 3 parámetros.
345[ $# == 3 ] || ogRaiseError $OG_ERR_FORMAT || return $?
346# Camino del fichero de registro.
347FILE=$(ogGetHivePath "$1" "$2") || return $?
348
349# Devolver la lista de claves de registro.
[367e04d]350chntpw "$FILE" << EOT 2> /dev/null | awk 'BEGIN {FS="[<>]"} $1~/REG_/ {print $2}'
[3907aaf]351ls $3
352q
353EOT
354}
355
356
357#/**
[9f577259]358#         ogSetRegistryValue path_mountpoint str_hive str_valuename str_valuedata
359#@brief   Establece el dato asociado a un valor del registro de Windows.
360#@param   path_mountpoint  directorio donde está montado el sistema Windows
[bf18bcbd]361#@param   str_hive         sección del registro
[9f577259]362#@param   str_valuename    nombre del valor de registro
363#@param   str_valuedata    dato del valor de registro
364#@return  (nada)
365#@exception OG_ERR_FORMAT    Formato incorrecto.
[bf18bcbd]366#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
[9f577259]367#@note    hive = { default, sam, security, software, system, components }
[bf18bcbd]368#@warning Requisitos: chntpw
369#@warning El sistema de archivos de Windows debe estar montado previamente.
[9f577259]370#@version 0.9 - Adaptación para OpenGNSys.
371#@author  Ramon Gomez, ETSII Universidad de Sevilla
372#@date    2009-09-24
373#*/ ##
374function ogSetRegistryValue ()
375{
376# Variables locales.
377local FILE
378
379# Si se solicita, mostrar ayuda.
380if [ "$*" == "help" ]; then
381    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename str_data"
[bf18bcbd]382           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1' 1"
[9f577259]383    return
384fi
385# Error si no se reciben 4 parámetros.
386[ $# == 4 ] || ogRaiseError $OG_ERR_FORMAT || return $?
387# Camino del fichero de registro.
[1b804cc]388FILE=$(ogGetHivePath "$1" "$2") || return $?
[9f577259]389
390# Cambiar el dato del valor de registro.
[367e04d]391chntpw "$FILE" << EOT &> /dev/null
392cd ${3%\\*}
393ed ${3##*\\}
[9f577259]394$4
395q
396y
[9570719]397EOT
[9f577259]398}
399
Note: See TracBrowser for help on using the repository browser.