Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iml-backup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
iml-backup
Commits
e078010e
Commit
e078010e
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add validation of ini files
parent
b191c47d
Branches
Branches containing commit
No related tags found
1 merge request
!129
Db Profiles
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
includes/dbdetect.class.sh
+16
-13
16 additions, 13 deletions
includes/dbdetect.class.sh
includes/dbdetect_validate_profile_ini.sh
+52
-0
52 additions, 0 deletions
includes/dbdetect_validate_profile_ini.sh
vendor/ini.class.sh
+86
-0
86 additions, 0 deletions
vendor/ini.class.sh
with
154 additions
and
13 deletions
includes/dbdetect.class.sh
+
16
−
13
View file @
e078010e
...
...
@@ -77,9 +77,12 @@ function dbdetect.exists(){
local
_found
=
0
# show errors in profile ini files
ini.validate
"
$_config
"
"
$(
dirname
$0
)
/includes/dbdetect_validate_profile_ini.sh"
&&
dbdetect._wd
"Ini validation OK"
# set file and inisection we read values from
ini.set
"
$_config
"
"detect"
# --- check tcp
local
tcpport
;
tcpport
=
$(
ini.value
"tcp"
)
if
[
-n
"
$tcpport
"
]
;
then
...
...
@@ -104,18 +107,6 @@ function dbdetect.exists(){
dbdetect._wd
"... tcp
$tcpport
is used by
$tcpprocess
."
fi
# --- check binaries
local
binary
;
binary
=
$(
ini.value
"binary"
)
if
[
-n
"
${
binary
}
"
]
;
then
for
mybinary
in
$(
echo
"
${
binary
}
"
|
tr
","
" "
)
;
do
if
!
which
"
$mybinary
"
>
/dev/null 2>&1
;
then
dbdetect._wd
"... Missing binary:
${
mybinary
}
"
return
1
fi
dbdetect._wd
"... Binary:
${
mybinary
}
was found"
done
fi
# --- check process
local
process
;
process
=
$(
ini.value
"process"
)
if
[
-n
"
${
process
}
"
]
;
then
...
...
@@ -150,6 +141,18 @@ function dbdetect.exists(){
fi
fi
# --- check binaries
local
binary
;
binary
=
$(
ini.value
"binary"
)
if
[
-n
"
${
binary
}
"
]
;
then
for
mybinary
in
$(
echo
"
${
binary
}
"
|
tr
","
" "
)
;
do
if
!
which
"
$mybinary
"
>
/dev/null 2>&1
;
then
dbdetect._wd
"... Missing binary:
${
mybinary
}
"
return
1
fi
dbdetect._wd
"... Binary:
${
mybinary
}
was found"
done
fi
# --- OK, everything was found ... we initialize it
dbdetect._wd
"OK, match:
$_config
"
...
...
This diff is collapsed.
Click to expand it.
includes/dbdetect_validate_profile_ini.sh
0 → 100644
+
52
−
0
View file @
e078010e
# ----------------------------------------------------------------------
#
# VALIDATE PROFILE INI
#
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
# section names
#
# SYNTAX:
# comma separated list of sections
# ----------------------------------------------------------------------
# sections that MUST be present
sectionsMust
=
"detect,set"
# sections that CAN be present
sectionsCan
=
""
# ----------------------------------------------------------------------
# variables
#
# SYNTAX:
# - one line per ini entry.
# - <section>.<variable> OR <section>.<variable>:<regex-to-match>
# The regey is applied with grep -E parameter for extended regex
# and "^<regex-to-match>$" for complete value
# ----------------------------------------------------------------------
varsMust
=
""
varsCan
=
"
detect.binary
detect.process
detect.tcp:[0-9]*
detect.tcp-target
detect.tcp-process
detect.type:sqlite
detect.file[]
set.dbuser
set.dbpassword
set.env
set.params
set.su
"
# ----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
vendor/ini.class.sh
+
86
−
0
View file @
e078010e
...
...
@@ -241,4 +241,90 @@ function ini.varexport(){
done
}
# validate the ini file
function
ini.validate
(){
local
myinifile
=
"
$1
"
local
myvalidationfile
=
"
$2
"
local
bShowAll
=
"
${
3
:-
0
}
"
local
ERROR
=
"
\e
[1;31mERROR
\e
[0m"
local
iErr
;
typeset
-i
iErr
=
0
if
[
!
-f
"
${
myvalidationfile
}
"
]
;
then
echo
-e
"
$ERROR
: Validation file '
${
myvalidationfile
}
' does not exist."
return
1
fi
.
"
${
myvalidationfile
}
"
||
return
1
if
[
-n
"
$sectionsMust
"
]
;
then
test
$bShowAll
-ne
0
&&
echo
"--- Validate MUST sections
$sectionsMust
"
for
section
in
$(
tr
","
" "
<<<
"
$sectionsMust
"
)
;
do
if
ini.sections
"
$myinifile
"
|
grep
-q
"^
$section
$"
;
then
test
$bShowAll
-ne
0
&&
echo
"OK: Section
$section
is present."
else
echo
-e
"
$ERROR
: Section
$section
is not present."
iErr+
=
1
fi
done
fi
test
$bShowAll
-ne
0
&&
echo
"--- Validate section names"
for
section
in
$(
ini.sections
"
$myinifile
"
)
do
if
!
grep
-Fq
",
${
section
}
,"
<<<
",
${
sectionsMust
}
,
${
sectionsCan
}
,"
;
then
echo
-e
"
$ERROR
: unknown section name: [
$section
]"
iErr+
=
1
else
test
$bShowAll
-ne
0
&&
echo
"OK: [
$section
] ... checking its keys..."
# TODO: verify values
for
mustkey
in
$(
echo
"
${
varsMust
}
"
|
grep
"^[/t ]*
${
section
}
\.
"
|
cut
-f
2
-d
'.'
|
cut
-f
1
-d
':'
)
;
do
if
ini.keys
"
$myinifile
"
"
$section
"
|
grep
"^
${
mustkey
}
$"
;
then
test
$bShowAll
-ne
0
&&
echo
" OK:
$section
.
$mustkey
"
else
echo
-e
"
$ERROR
: A MUST key '
$mustkey
' was not found im section [
$section
]."
iErr+
=
1
fi
done
for
mykey
in
$(
ini.keys
"
$myinifile
"
"
$section
"
)
;
do
if
!
echo
"
${
varsMust
}
${
varsCan
}
"
|
cut
-f
1
-d
':'
|
grep
-q
"^[/t ]*
${
section
}
\.
${
mykey
}
$"
;
then
echo
-e
"
$ERROR
: invald key name:
$section
.
$mykey
"
iErr+
=
1
else
check
=
$(
echo
"
${
varsMust
}
${
varsCan
}
"
|
grep
"^[/t ]*
${
section
}
\.
${
mykey
}
[:
$]
"
|
cut
-f
2
-d
':'
)
if
[
-n
"
$check
"
]
;
then
value
=
"
$(
ini.value
"
$myinifile
"
"
$section
"
"
$mykey
"
)
"
if
!
grep
-Eq
"^
${
check
}
$"
<<<
"
$value
"
;
then
echo
-e
"
$ERROR
: key name
$section
.
$mykey
is valid but value '
$value
' does NOT match '
$check
'"
else
test
$bShowAll
-ne
0
&&
echo
" OK: key name
$mykey
is valid and value matches '
$check
'"
fi
else
test
$bShowAll
-ne
0
&&
echo
" OK: key name
$mykey
is valid"
fi
fi
done
fi
done
if
[
$iErr
-gt
0
]
;
then
echo
"RESULT: Errors were found for
$myinifile
"
else
test
$bShowAll
-ne
0
&&
echo
"RESULT: OK, Ini file
$myinifile
looks fine."
fi
return
$iErr
}
# ----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment