source: client/engine/Registry.lib @ cd95622

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 cd95622 was 367e04d, checked in by ramon <ramongomez@…>, 14 years ago

Corregir erratas en Registry.lib

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

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