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
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.
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.
[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
149#/**
[bf18bcbd]150#         ogDeleteRegistryValue path_mountpoint str_hive str_valuename
[1b804cc]151#@brief   Elimina un valor del registro de Windows.
[bf18bcbd]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.
[1b804cc]161#@version 1.0.1 - Nueva función
162#@author  Ramon Gomez, ETSII Universidad de Sevilla
[cd2ae87]163#@date    2011-05-25
[1b804cc]164#*/ ##
165function ogDeleteRegistryValue ()
166{
[cd2ae87]167# Variables locales.
168local FILE
169
170# Si se solicita, mostrar ayuda.
171if [ "$*" == "help" ]; then
[bf18bcbd]172    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename" \
173           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1'"
[cd2ae87]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)
[367e04d]183chntpw "$FILE" << EOT &> /dev/null
[cd2ae87]184cd ${3%\\*}
185dv ${3##*\\}
186q
187y
188EOT
189# (comentario Doxygen) */
[1b804cc]190}
191
192
193#/**
194#         ogGetHivePath path_mountpoint str_hive
[9f577259]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.
[bf18bcbd]200#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
[9f577259]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#*/ ##
[1b804cc]207function ogGetHivePath ()
[9f577259]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"
[bf18bcbd]215           "$FUNCNAME /mnt/sda1 SOFTWARE"
[9f577259]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.
[bf18bcbd]240#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
[9f577259]241#@note    hive = { default, sam, security, software, system, components }
242#@warning Requisitos: chntpw, awk
[bf18bcbd]243#@warning El sistema de archivos de Windows debe estar montado previamente.
[9f577259]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
[bf18bcbd]255    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_valuename" \
256           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1'  ==>  1"
[9f577259]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.
[1b804cc]262FILE=$(ogGetHivePath "$1" "$2") || return $?
[9f577259]263
264# Devolver el dato del valor de registro.
265# /* (comentario Doxygen)
[367e04d]266chntpw "$FILE" << EOT 2> /dev/null | awk '/> Value/ {getline;print $0;}'
[9f577259]267cd ${3%\\*}
268cat ${3##*\\}
269q
[cd2ae87]270EOT
[9f577259]271# (comentario Doxygen) */
272}
273
274
275#/**
[3907aaf]276#         ogListRegistryKeys path_mountpoint str_hive str_key
277#@brief   Lista los nombres de subclaves de una determinada clave del registro de Windows.
[9f577259]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.
[bf18bcbd]283#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
[9f577259]284#@note    hive = { default, sam, security, software, system, components }
285#@warning Requisitos: chntpw, awk
[bf18bcbd]286#@warning El sistema de archivos de Windows debe estar montado previamente.
[9f577259]287#@version 0.9 - Adaptación para OpenGNSys.
288#@author  Ramon Gomez, ETSII Universidad de Sevilla
289#@date    2009-09-23
290#*/ ##
[3907aaf]291function ogListRegistryKeys ()
[9f577259]292{
293# Variables locales.
294local FILE
295
296# Si se solicita, mostrar ayuda.
297if [ "$*" == "help" ]; then
[bf18bcbd]298    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \
299           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\Windows\CurrentVersion'"
[9f577259]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.
[1b804cc]306FILE=$(ogGetHivePath "$1" "$2") || return $?
[9f577259]307
308# Devolver la lista de claves de registro.
[367e04d]309chntpw "$FILE" << EOT 2> /dev/null | awk 'BEGIN {FS="[<>]"} $1~/^  $/ {print $2}'
[9f577259]310ls $3
311q
[9570719]312EOT
[9f577259]313}
314
315
316#/**
[3907aaf]317#         ogListRegistryValues path_mountpoint str_hive str_key
318#@brief   Lista los nombres de valores de una determinada clave del registro de Windows.
[bf18bcbd]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.
[3907aaf]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
[bf18bcbd]339    ogHelp "$FUNCNAME" "$FUNCNAME path_mountpoint str_hive str_key" \
340           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\Windows\CurrentVersion'"
[3907aaf]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.
[367e04d]349chntpw "$FILE" << EOT 2> /dev/null | awk 'BEGIN {FS="[<>]"} $1~/REG_/ {print $2}'
[3907aaf]350ls $3
351q
352EOT
353}
354
355
356#/**
[9f577259]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
[bf18bcbd]360#@param   str_hive         sección del registro
[9f577259]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.
[bf18bcbd]365#@exception OG_ERR_NOTFOUND  Fichero de registro no encontrado.
[9f577259]366#@note    hive = { default, sam, security, software, system, components }
[bf18bcbd]367#@warning Requisitos: chntpw
368#@warning El sistema de archivos de Windows debe estar montado previamente.
[9f577259]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"
[bf18bcbd]381           "$FUNCNAME /mnt/sda1 SOFTWARE '\Microsoft\NewKey\Value1' 1"
[9f577259]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.
[1b804cc]387FILE=$(ogGetHivePath "$1" "$2") || return $?
[9f577259]388
389# Cambiar el dato del valor de registro.
[367e04d]390chntpw "$FILE" << EOT &> /dev/null
391cd ${3%\\*}
392ed ${3##*\\}
[9f577259]393$4
394q
395y
[9570719]396EOT
[9f577259]397}
398
Note: See TracBrowser for help on using the repository browser.