Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
isgphys
python
Commits
763207d9
Commit
763207d9
authored
6 years ago
by
Sven Mäder
Browse files
Options
Downloads
Patches
Plain Diff
Add home owner and permission check
parent
214b0ac8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/check-home-permissions.py
+99
-0
99 additions, 0 deletions
bin/check-home-permissions.py
with
99 additions
and
0 deletions
bin/check-home-permissions.py
0 → 100755
+
99
−
0
View file @
763207d9
#!/usr/bin/env python3
import
os
import
sys
import
pwd
import
grp
import
stat
owner
=
[]
permission
=
[]
class
Home
(
object
):
"""
Holds info about a home directory
"""
def
__init__
(
self
,
name
,
path
,
st
):
self
.
name
=
name
self
.
path
=
path
self
.
st
=
st
@property
def
uid
(
self
):
return
self
.
st
.
st_uid
@property
def
gid
(
self
):
return
self
.
st
.
st_gid
@property
def
uname
(
self
):
return
pwd
.
getpwuid
(
self
.
uid
).
pw_name
@property
def
gname
(
self
):
return
grp
.
getgrgid
(
self
.
gid
).
gr_name
@property
def
filemode
(
self
):
return
stat
.
filemode
(
self
.
st
.
st_mode
)
def
__str__
(
self
):
return
'
'
.
join
([
self
.
filemode
,
self
.
uname
,
self
.
gname
,
self
.
path
])
def
check_homes
(
top
):
for
f
in
os
.
listdir
(
top
):
pathname
=
os
.
path
.
join
(
top
,
f
)
st
=
os
.
stat
(
pathname
)
home
=
Home
(
f
,
pathname
,
st
)
if
bad_owner
(
home
):
owner
.
append
(
home
)
if
bad_permission
(
home
):
permission
.
append
(
home
)
def
bad_owner
(
home
):
if
home
.
name
==
home
.
uname
and
home
.
name
==
home
.
gname
:
return
False
return
True
def
bad_permission
(
home
):
# d---------
if
home
.
st
.
st_mode
==
stat
.
S_IFDIR
:
return
False
# drwx------
elif
home
.
st
.
st_mode
==
stat
.
S_IFDIR
|
stat
.
S_IRUSR
|
stat
.
S_IWUSR
|
stat
.
S_IXUSR
:
return
False
return
True
def
list_homes
(
homes
):
for
home
in
homes
:
print
(
home
)
if
__name__
==
'
__main__
'
:
arg_count
=
len
(
sys
.
argv
)
-
1
for
i
,
arg
in
enumerate
(
sys
.
argv
):
if
i
==
0
:
continue
check_homes
(
arg
)
if
owner
:
print
(
'
bad owner or group:
'
)
print
(
'
-------------------
'
)
list_homes
(
owner
)
print
()
if
permission
:
print
(
'
bad permission:
'
)
print
(
'
---------------
'
)
list_homes
(
permission
)
print
()
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