sssd_upgrade_config.py revision 87ff519b472568b19809963ca860d2182e874fcd
#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
from optparse import OptionParser
from ipachangeconf import openLocked
from ipachangeconf import SSSDChangeConf
class SSSDConfigFile(SSSDChangeConf):
f.close()
" Copy the file we operate on to a backup location "
# make sure we don't leak data, force permissions on the backup
def get_version(self):
if not ver:
return 1
try:
except ValueError:
raise SyntaxError, 'config_file_version not an integer'
if item:
'name' : 'dns_discovery_domain',
return
return
def _do_v2_changes(self):
# remove Data Provider
if srvlist:
if 'dp' in services:
# remove magic_private_groups from all domains
# check if we need to add dns_domain
for v in vals:
if v['type'] == 'empty':
continue
# if already in list, just update
if o['name'] == v['name']:
o['value'] = v['value']
# not in list, add there
if not updated:
" Enumerate was special as it turned into bool from (0,1,2,3) enum "
if enum:
try:
except ValueError:
else:
# rename the section
# 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',
'store_legacy_passwords' : 'store-legacy-passwords',
}
# 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',
'ldap_netgroup_search_base' : 'netgroupSearchBase',
'ldap_netgroup_object_class' : 'netgroupObjectClass',
'ldap_netgroup_name' : 'netgroupName',
'ldap_netgroup_member' : 'netgroupMember',
'ldap_netgroup_triple' : 'netgroupTriple',
'ldap_netgroup_modify_timestamp' : 'netgroupModifyTimestamp',
}
'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',
}
# remove obsolete libPath option
# configuration files before 0.5.0 did not enforce provider= in local domains
# it did special-case by domain name (LOCAL)
'name' : 'id_provider',
'value' : 'local',
}
# if domain was local, update with parameters from [user_defaults]
# if domain had provider = files, unroll that into provider=proxy, proxy_lib_name=files
'name' : 'proxy_lib_name',
'value' : 'files',
}
def _migrate_domains(self):
if item:
def _migrate_services(self):
# [service] - options common to all services, no section as in v1
'debug_level' : 'debug-level',
'debug_timestamps' : 'debug-timestamps',
'command' : 'command',
'timeout' : 'timeout',
}
# rename services sections
}
# [sssd] - monitor service
sssd_kw = [
{ 'type' : 'option',
'name' : 'config_file_version',
'value' : '2',
'action': 'set',
}
]
'domains', 'domains')
'services', 'activeServices')
'names', 're-expression')
'names', 'full-name-format')
# update from general services section and monitor
# [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 = {}
# remove obsolete sections
# read in the old file, make backup if needed
if backup:
# all done, write the file
# make sure it has the right permissions too
# read in the old file, make backup if needed
if backup:
# do the migration to v2 format
# do the upgrade
# also include any changes in the v2 format
# all done, write the file
# 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 SyntaxError:
return 1
except Exception, e:
print "ERROR: %s" % e
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__":