Close to working passwd and shadow files. STill need md5 hash, and for that we need logins to work properly via json
This commit is contained in:
parent
ed7c65a0e1
commit
144cd1cc62
3 changed files with 98 additions and 17 deletions
102
fas/client/fasClient.py
Normal file → Executable file
102
fas/client/fasClient.py
Normal file → Executable file
|
@ -19,25 +19,81 @@
|
||||||
# Red Hat Author(s): Mike McGrath <mmcgrath@redhat.com>
|
# Red Hat Author(s): Mike McGrath <mmcgrath@redhat.com>
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
from fedora.tg.client import BaseClient, AuthError, ServerError
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from shutil import move
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
FAS_URL = 'http://localhost:8080/fas/json/'
|
from fedora.tg.client import BaseClient, AuthError, ServerError
|
||||||
|
from optparse import OptionParser
|
||||||
|
from shutil import move
|
||||||
|
from rhpl.translate import _
|
||||||
|
|
||||||
|
FAS_URL = 'http://localhost:8080/fas/'
|
||||||
|
|
||||||
|
|
||||||
|
parser = OptionParser()
|
||||||
|
|
||||||
|
parser.add_option('--nogroup',
|
||||||
|
dest = 'no_group',
|
||||||
|
default = False,
|
||||||
|
action = 'store_true',
|
||||||
|
help = _('Do not sync group information'))
|
||||||
|
parser.add_option('--nopasswd',
|
||||||
|
dest = 'no_passwd',
|
||||||
|
default = False,
|
||||||
|
action = 'store_true',
|
||||||
|
help = _('Do not sync passwd information'))
|
||||||
|
parser.add_option('--noshadow',
|
||||||
|
dest = 'no_shadow',
|
||||||
|
default = False,
|
||||||
|
action = 'store_true',
|
||||||
|
help = _('Do not sync shadow information'))
|
||||||
|
parser.add_option('-s', '--server',
|
||||||
|
dest = 'FAS_URL',
|
||||||
|
default = FAS_URL,
|
||||||
|
metavar = 'FAS_URL',
|
||||||
|
help = _('Specify URL of fas server (default "%default")'))
|
||||||
|
|
||||||
|
|
||||||
class MakeShellAccounts(BaseClient):
|
class MakeShellAccounts(BaseClient):
|
||||||
def group_list(self, search='*'):
|
def group_list(self, search='*'):
|
||||||
params = {'search' : search}
|
params = {'search' : search}
|
||||||
data = self.send_request('group_list', auth=False, input=params)
|
data = self.send_request('json/group_list', auth=False, input=params)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def shadow_text(self, people=None):
|
||||||
|
i = 0
|
||||||
|
file = open('/tmp/shadow.txt', 'w')
|
||||||
|
if not people:
|
||||||
|
people = self.people_list()
|
||||||
|
for person in people:
|
||||||
|
uid = person['id']
|
||||||
|
username = person['username']
|
||||||
|
password = person['password']
|
||||||
|
file.write("=%i %s:%s:99999:0:99999:7:::\n" % (uid, username, password))
|
||||||
|
file.write("0%i %s:%s:99999:0:99999:7:::\n" % (i, username, password))
|
||||||
|
file.write(".%s %s:%s:99999:0:99999:7:::\n" % (username, username, password))
|
||||||
|
i = i + 1
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
|
def passwd_text(self, people=None):
|
||||||
|
i = 0
|
||||||
|
file = open('/tmp/passwd.txt', 'w')
|
||||||
|
if not people:
|
||||||
|
people = self.people_list()
|
||||||
|
for person in people:
|
||||||
|
uid = person['id']
|
||||||
|
username = person['username']
|
||||||
|
human_name = person['human_name']
|
||||||
|
home_dir = "/home/fedora/%s" % username
|
||||||
|
shell = "/bin/bash"
|
||||||
|
file.write("=%s %s:x:%i:%i:%s:%s:%s\n" % (uid, username, uid, uid, human_name, home_dir, shell))
|
||||||
|
file.write("0%i %s:x:%i:%i:%s:%s:%s\n" % (i, username, uid, uid, human_name, home_dir, shell))
|
||||||
|
file.write(".%s %s:x:%i:%i:%s:%s:%s\n" % (username, username, uid, uid, human_name, home_dir, shell))
|
||||||
|
i = i + 1
|
||||||
|
file.close()
|
||||||
|
|
||||||
def groups_text(self, groups=None, people=None):
|
def groups_text(self, groups=None, people=None):
|
||||||
i = 0
|
i = 0
|
||||||
file = open('/tmp/group.txt', 'w')
|
file = open('/tmp/group.txt', 'w')
|
||||||
|
@ -60,8 +116,6 @@ class MakeShellAccounts(BaseClient):
|
||||||
for group in groups['groups']:
|
for group in groups['groups']:
|
||||||
gid = group['id']
|
gid = group['id']
|
||||||
name = group['name']
|
name = group['name']
|
||||||
# print groups['memberships'][m]
|
|
||||||
# print groups['memberships'][1228]
|
|
||||||
memberships = ''
|
memberships = ''
|
||||||
try:
|
try:
|
||||||
''' Shoot me now I know this isn't right '''
|
''' Shoot me now I know this isn't right '''
|
||||||
|
@ -79,22 +133,48 @@ class MakeShellAccounts(BaseClient):
|
||||||
|
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
def people_list(self, search='*'):
|
def people_list(self, search='*'):
|
||||||
params = {'search' : search}
|
params = {'search' : search}
|
||||||
data = self.send_request('people_list', auth=False, input=params)
|
data = self.send_request('json/people_list', auth=False, input=params)
|
||||||
return data['people']
|
return data['people']
|
||||||
|
|
||||||
def make_group_db(self):
|
def make_group_db(self):
|
||||||
self.groups_text()
|
self.groups_text()
|
||||||
os.system('makedb -o /tmp/group.db /tmp/group.txt')
|
os.system('makedb -o /tmp/group.db /tmp/group.txt')
|
||||||
|
|
||||||
|
def make_passwd_db(self):
|
||||||
|
self.passwd_text()
|
||||||
|
os.system('makedb -o /tmp/passwd.db /tmp/passwd.txt')
|
||||||
|
|
||||||
|
def make_shadow_db(self):
|
||||||
|
self.shadow_text()
|
||||||
|
os.system('makedb -o /tmp/passwd.db /tmp/shadow.txt')
|
||||||
|
|
||||||
|
def install_passwd_db(self):
|
||||||
|
try:
|
||||||
|
move('/tmp/passwd.db', '/var/db/passwd.db')
|
||||||
|
except IOError, e:
|
||||||
|
print "ERROR: Could not write passwd db - %s" % e
|
||||||
|
|
||||||
|
def install_shadow_db(self):
|
||||||
|
try:
|
||||||
|
move('/tmp/shadow.db', '/var/db/shadow.db')
|
||||||
|
except IOError, e:
|
||||||
|
print "ERROR: Could not write shadow db - %s" % e
|
||||||
|
|
||||||
def install_group_db(self):
|
def install_group_db(self):
|
||||||
|
try:
|
||||||
move('/tmp/group.db', '/var/db/group.db')
|
move('/tmp/group.db', '/var/db/group.db')
|
||||||
|
except IOError, e:
|
||||||
|
print "ERROR: Could not write group db - %s" % e
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
fas = MakeShellAccounts(FAS_URL, None, None, None)
|
fas = MakeShellAccounts(FAS_URL, 'admin', None, None)
|
||||||
fas.make_group_db()
|
fas.make_group_db()
|
||||||
|
fas.make_passwd_db()
|
||||||
|
fas.make_shadow_db()
|
||||||
fas.install_group_db()
|
fas.install_group_db()
|
||||||
|
fas.install_passwd_db()
|
||||||
|
fas.install_shadow_db()
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ class Root(controllers.RootController):
|
||||||
# TODO: Find a better place for this.
|
# TODO: Find a better place for this.
|
||||||
os.environ['GNUPGHOME'] = config.get('gpghome')
|
os.environ['GNUPGHOME'] = config.get('gpghome')
|
||||||
|
|
||||||
@expose(template="fas.templates.welcome")
|
@expose(template="fas.templates.welcome", allow_json=True)
|
||||||
def index(self):
|
def index(self):
|
||||||
if turbogears.identity.not_anonymous():
|
if turbogears.identity.not_anonymous():
|
||||||
turbogears.redirect('/home')
|
turbogears.redirect('/home')
|
||||||
|
|
|
@ -2,6 +2,8 @@ import turbogears
|
||||||
from turbogears import controllers, expose, paginate, identity, redirect, widgets, validate, validators, error_handler
|
from turbogears import controllers, expose, paginate, identity, redirect, widgets, validate, validators, error_handler
|
||||||
from turbogears.database import session
|
from turbogears.database import session
|
||||||
|
|
||||||
|
from cherrypy import request, response
|
||||||
|
|
||||||
import cherrypy
|
import cherrypy
|
||||||
|
|
||||||
from fas.auth import *
|
from fas.auth import *
|
||||||
|
@ -33,4 +35,3 @@ class JsonRequest(controllers.Controller):
|
||||||
re_search = re.sub(r'\*', r'%', search).lower()
|
re_search = re.sub(r'\*', r'%', search).lower()
|
||||||
people = People.query.filter(People.username.like(re_search)).order_by('username')
|
people = People.query.filter(People.username.like(re_search)).order_by('username')
|
||||||
return dict(people=people)
|
return dict(people=people)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue