Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
f757d659
Commit
f757d659
authored
Aug 08, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #804 from sfromm/issue789
Abstract how to look up user password to be more flexible
parents
ae7e1928
49f3ab67
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
8 deletions
+29
-8
library/user
+29
-8
No files found.
library/user
View file @
f757d659
...
...
@@ -18,6 +18,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import
os
import
pwd
import
grp
try
:
...
...
@@ -26,6 +27,14 @@ try:
except
:
HAVE_SPWD
=
False
SHADOWFILE
=
'/etc/shadow'
if
os
.
path
.
exists
(
'/etc/master.passwd'
):
SHADOWFILE
=
'/etc/master.passwd'
# FreeBSD passwd
# Note: while the above has the correct location for where
# encrypted passwords are stored on FreeBSD, the code below doesn't
# invoke adduser in lieu of useradd, nor pw in lieu of usermod.
# That is, this won't work on FreeBSD.
def
get_bin_path
(
module
,
arg
):
if
os
.
path
.
exists
(
'/usr/sbin/
%
s'
%
arg
):
return
'/usr/sbin/
%
s'
%
arg
...
...
@@ -198,16 +207,28 @@ def get_pwd_info(user):
def
user_info
(
user
):
if
not
user_exists
(
user
):
return
False
try
:
info
=
get_pwd_info
(
user
)
if
HAVE_SPWD
:
sinfo
=
spwd
.
getspnam
(
user
)
except
KeyError
:
return
False
if
HAVE_SPWD
:
info
[
1
]
=
sinfo
[
1
]
info
=
get_pwd_info
(
user
)
if
len
(
info
[
1
])
==
1
or
len
(
info
[
1
])
==
0
:
info
[
1
]
=
user_password
(
user
)
return
info
def
user_password
(
user
):
passwd
=
''
if
not
user_exists
(
user
):
return
passwd
if
HAVE_SPWD
:
try
:
passwd
=
spwd
.
getspnam
(
user
)[
1
]
except
KeyError
:
return
passwd
else
:
# Read shadow file for user's encrypted password string
if
os
.
path
.
exists
(
SHADOWFILE
)
and
os
.
access
(
SHADOWFILE
,
os
.
R_OK
):
for
line
in
open
(
SHADOWFILE
)
.
readlines
():
if
line
.
startswith
(
'
%
s:'
%
user
):
passwd
=
line
.
split
(
':'
)[
1
]
return
passwd
# ===========================================
def
main
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment