Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snf-image-creator
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
itminedu
snf-image-creator
Commits
09fe8f9e
Commit
09fe8f9e
authored
10 years ago
by
Nikos Skalkotos
Browse files
Options
Downloads
Patches
Plain Diff
Create REMOTE_CONNECTION property for FreeBSD
parent
f8d60861
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
image_creator/os_type/freebsd.py
+47
-2
47 additions, 2 deletions
image_creator/os_type/freebsd.py
image_creator/os_type/unix.py
+31
-0
31 additions, 0 deletions
image_creator/os_type/unix.py
with
78 additions
and
2 deletions
image_creator/os_type/freebsd.py
+
47
−
2
View file @
09fe8f9e
...
...
@@ -53,7 +53,10 @@ class Freebsd(Unix):
def
_do_collect_metadata
(
self
):
"""
Collect metadata about the OS
"""
super
(
Freebsd
,
self
).
_do_collect_metadata
()
self
.
meta
[
"
USERS
"
]
=
"
"
.
join
(
self
.
_get_passworded_users
())
users
=
self
.
_get_passworded_users
()
self
.
meta
[
"
USERS
"
]
=
"
"
.
join
(
users
)
# The original product name key is long and ugly
self
.
meta
[
'
DESCRIPTION
'
]
=
\
...
...
@@ -64,6 +67,44 @@ class Freebsd(Unix):
self
.
out
.
warn
(
"
No passworded users found!
"
)
del
self
.
meta
[
'
USERS
'
]
# Check if ssh is enabled
sshd_enabled
=
False
sshd_service
=
re
.
compile
(
r
'
^sshd_enable=.+$
'
)
# Freebsd has a checkyesno() functions that tests the service variable
# against all those different values in a case insensitive manner!!!
sshd_yes
=
re
.
compile
(
r
"
^sshd_enable=([
'
\"]?)(YES|TRUE|ON|1)\1$
"
,
re
.
IGNORECASE
)
for
rc_conf
in
(
'
/etc/rc.conf
'
,
'
/etc/rc.conf.local
'
):
if
not
self
.
image
.
g
.
is_file
(
rc_conf
):
continue
for
line
in
self
.
image
.
g
.
cat
(
rc_conf
).
splitlines
():
line
=
line
.
split
(
'
#
'
)[
0
].
strip
()
# Be paranoid. Don't stop examining lines after a match. This
# is a shell variable and can be overwritten many times. Only
# the last match counts.
if
sshd_service
.
match
(
line
):
sshd_enabled
=
sshd_yes
.
match
(
line
)
is
not
None
if
sshd_enabled
:
ssh
=
[]
opts
=
self
.
ssh_connection_options
(
users
)
for
user
in
opts
[
'
users
'
]:
ssh
.
append
(
"
ssh:port=%d,user=%s
"
%
(
opts
[
'
port
'
],
user
))
if
'
REMOTE_CONNECTION
'
not
in
self
.
meta
:
self
.
meta
[
'
REMOTE_CONNECTION
'
]
=
""
else
:
self
.
meta
[
'
REMOTE_CONNECTION
'
]
+=
"
"
if
len
(
users
):
self
.
meta
[
'
REMOTE_CONNECTION
'
]
+=
"
"
.
join
(
ssh
)
else
:
self
.
meta
[
'
REMOTE_CONNECTION
'
]
+=
"
ssh:port=%d
"
%
opts
[
'
port
'
]
else
:
self
.
out
.
warn
(
"
OpenSSH Daemon is not configured to run on boot
"
)
def
_do_inspect
(
self
):
"""
Run various diagnostics to check if media is supported
"""
...
...
@@ -93,7 +134,11 @@ class Freebsd(Unix):
if
len
(
passwd
)
>
0
and
passwd
[
0
]
==
'
!
'
:
self
.
out
.
warn
(
"
Ignoring locked %s account.
"
%
user
)
else
:
users
.
append
(
user
)
# Put root in the beginning.
if
user
==
'
root
'
:
users
.
insert
(
0
,
user
)
else
:
users
.
append
(
user
)
return
users
...
...
This diff is collapsed.
Click to expand it.
image_creator/os_type/unix.py
+
31
−
0
View file @
09fe8f9e
...
...
@@ -70,6 +70,37 @@ class Unix(OSBase):
return
True
def
ssh_connection_options
(
self
,
users
):
"""
Returns a list of valid ssh connection options
"""
def
sshd_config
():
"""
Read /etc/ssh/sshd_config and return it as a dictionary
"""
config
=
{}
fname
=
'
/etc/ssh/sshd_config
'
if
not
self
.
image
.
g
.
is_file
(
fname
):
return
{}
for
line
in
self
.
image
.
g
.
cat
(
fname
).
splitlines
():
line
=
line
.
split
(
'
#
'
)[
0
].
strip
()
if
not
len
(
line
):
continue
line
=
line
.
split
()
config
[
line
[
0
]]
=
line
[
1
:]
return
config
config
=
sshd_config
()
try
:
port
=
int
(
config
[
'
Port
'
][
0
])
except
:
port
=
22
if
'
PermitRootLogin
'
in
config
and
config
[
'
PermitRootLogin
'
]
==
'
no
'
:
if
'
root
'
in
users
:
users
.
remove
(
'
root
'
)
return
{
'
port
'
:
port
,
'
users
'
:
users
}
@sysprep
(
'
Removing files under /var/cache
'
)
def
_cleanup_cache
(
self
):
"""
Remove all regular files under /var/cache
"""
...
...
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