upgrade_config.py revision 0922a8897a6ae1ce7b7c994df0a5cb99c36bfd9c
#coding=utf-8
# SSSD
#
#
# Copyright (C) Jakub Hrozek <jhrozek@redhat.com> 2009
#
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import shutil
import traceback
import copy
from ConfigParser import RawConfigParser
from ConfigParser import NoOptionError
from optparse import OptionParser
class SSSDConfigParser(RawConfigParser):
" set without interpolation "
pass
" get without interpolation "
if key != "__name__":
"""
SSSD Config file uses a logical order of sections
ConfigParser does not allow sorting the sections, so
we hackishly sort them here..
"""
# Write SSSD first
else:
#There were no active domains configured
active_domains = []
# Write the other services
# Write the domains in the order that is specified in domains =
for dom in active_domains:
# Write inactive domains
class SSSDConfigFile(object):
def get_version(self):
" Guess if we are looking at v1 config file "
return 1
return 1
def _backup_file(self):
" Copy the file we operate on to a backup location "
# make sure we don't leak data, force permissions on the backup
"""
Move value of parameter from one section to another, renaming the parameter
"""
"""
Move value of parameter from one section to another according to
mapping in ``new_old_dict``
"""
" Enumerate was special as it turned into bool from (0,1,2,3) enum "
else:
try:
except ValueError:
if enumvalue == 0:
elif enumvalue > 0:
else:
# Generic options - new:old
'max_id': 'maxID',
'timeout': 'timeout',
'magic_private_groups' : 'magicPrivateGroups',
'cache_credentials' : 'cache-credentials',
'id_provider' : 'provider',
'auth_provider' : 'auth-module',
'access_provider' : 'access-module',
'chpass_provider' : 'chpass-module',
'use_fully_qualified_names' : 'useFullyQualifiedNames',
}
# Proxy options
'proxy_lib_name' : 'libName',
}
# LDAP options - new:old
'ldap_schema' : 'ldapSchema',
'ldap_default_bind_dn' : 'defaultBindDn',
'ldap_default_authtok_type' : 'defaultAuthtokType',
'ldap_default_authtok' : 'defaultAuthtok',
'ldap_user_search_base' : 'userSearchBase',
'ldap_user_search_scope' : 'userSearchScope',
'ldap_user_search_filter' : 'userSearchFilter',
'ldap_user_object_class' : 'userObjectClass',
'ldap_user_name' : 'userName',
'ldap_user_pwd' : 'userPassword',
'ldap_user_uid_number' : 'userUidNumber',
'ldap_user_gid_number' : 'userGidNumber',
'ldap_user_gecos' : 'userGecos',
'ldap_user_home_directory' : 'userHomeDirectory',
'ldap_user_shell' : 'userShell',
'ldap_user_uuid' : 'userUUID',
'ldap_user_principal' : 'userPrincipal',
'ldap_force_upper_case_realm' : 'force_upper_case_realm',
'ldap_user_fullname' : 'userFullname',
'ldap_user_member_of' : 'userMemberOf',
'ldap_user_modify_timestamp' : 'modifyTimestamp',
'ldap_group_search_base' : 'groupSearchBase',
'ldap_group_search_scope' : 'groupSearchScope',
'ldap_group_search_filter' : 'groupSearchFilter',
'ldap_group_object_class' : 'groupObjectClass',
'ldap_group_name' : 'groupName',
'ldap_group_pwd' : 'userPassword',
'ldap_group_gid_number' : 'groupGidNumber',
'ldap_group_member' : 'groupMember',
'ldap_group_uuid' : 'groupUUID',
'ldap_group_modify_timestamp' : 'modifyTimestamp',
'ldap_network_timeout' : 'network_timeout',
'ldap_offline_timeout' : 'offline_timeout',
'ldap_enumeration_refresh_timeout' : 'enumeration_refresh_timeout',
'ldap_stale_time' : 'stale_time',
'ldap_opt_timeout' : 'opt_timeout',
'ldap_tls_reqcert' : 'tls_reqcert',
}
'krb5_realm' : 'krb5REALM',
'krb5_try_simple_upn' : 'krb5try_simple_upn',
'krb5_changepw_principal' : 'krb5changepw_principle',
'krb5_ccachedir' : 'krb5ccache_dir',
'krb5_auth_timeout' : 'krb5auth_timeout',
'krb5_ccname_template' : 'krb5ccname_template',
}
'base_directory' : 'baseDirectory',
}
# configuration files before 0.5.0 did not enforce provider= in local domains
# it did special-case by domain name (LOCAL)
try:
except NoOptionError:
if old_domsec == 'domains/LOCAL':
prv = 'local'
# if domain was local, update with parameters from [user_defaults]
if prv == 'local':
def _migrate_domains(self):
for domain in [ s.replace('domains/','') for s in self._config.sections() if s.startswith("domains/") ]:
def _remove_dp(self):
# If data provider is in the list of active services, remove it
if 'dp' in services:
# also remove the [dp] section
def _do_v2_changes(self):
# the changes themselves
"""
Check for needed changes in V2 format and write the result into
``out_file_name```.
"""
# basically a wrapper around _do_v2_changes
if backup:
# all done, open the file for writing
# make sure it has the right permissions too
"""
Upgrade the config file to V2 format and write the result into
``out_file_name```.
"""
if backup:
# [service] - options common to all services, no section as in v1
'debug_level' : 'debug-level',
'debug_timestamps' : 'debug-timestamps',
'command' : 'command',
'timeout' : 'timeout',
}
# [sssd] - monitor service
'domains', 'domains')
'services', 'activeServices')
'names', 're-expression')
'names', 'full-name-format')
# [nss] - Name service
'entry_cache_timeout' : 'EntryCacheTimeout',
'entry_cache_nowait_timeout' : 'EntryCacheNoWaitRefreshTimeout',
'entry_negative_timeout ' : 'EntryNegativeTimeout',
'filter_users' : 'filterUsers',
'filter_groups' : 'filterGroups',
'filter_users_in_groups' : 'filterUsersInGroups',
}
# [pam] - Authentication service
pam_kw = {}
# Migrate domains
# Perform neccessary changes
# all done, open the file for writing
# make sure it has the right permissions too
def parse_options():
parser = OptionParser()
help="""Do not provide backup file after conversion.
The script copies the original file with the suffix .bak
by default""")
help="Be verbose")
return None
# do the conversion in place by default
return options
if verbose:
print msg
def main():
options = parse_options()
if not options:
return 1
try:
except SSSDConfigParser.ParsingError:
return 1
# make sure we keep strict settings when creating new files
if version == 2:
try:
except Exception, e:
print "ERROR: %s" % e
return 1
elif version == 1:
try:
except Exception, e:
print "ERROR: %s" % e
return 1
else:
print >>sys.stderr, "Can only upgrade from v1 to v2, file %s looks like version %d" % (options.filename, config.get_version())
return 1
return 0
if __name__ == "__main__":