Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

# Authors: 

#   Rob Crittenden <rcritten@redhat.com> 

#   Pavel Zuna <pzuna@redhat.com> 

# 

# Copyright (C) 2008  Red Hat 

# see file 'COPYING' for use and warranty information 

# 

# This program is free software; you can redistribute it and/or modify 

# 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/>. 

 

from ipalib import api 

from ipalib import Bool, Int, Str, IA5Str, StrEnum 

from ipalib.plugins.baseldap import * 

from ipalib import _ 

from ipalib.errors import ValidationError 

 

# 389-ds attributes that should be skipped in attribute checks 

OPERATIONAL_ATTRIBUTES = ('nsaccountlock', 'member', 'memberof', 

    'memberindirect', 'memberofindirect',) 

 

__doc__ = _(""" 

Server configuration 

 

Manage the default values that IPA uses and some of its tuning parameters. 

 

NOTES: 

 

The password notification value (--pwdexpnotify) is stored here so it will 

be replicated. It is not currently used to notify users in advance of an 

expiring password. 

 

Some attributes are read-only, provided only for information purposes. These 

include: 

 

Certificate Subject base: the configured certificate subject base, 

  e.g. O=EXAMPLE.COM.  This is configurable only at install time. 

Password plug-in features: currently defines additional hashes that the 

  password will generate (there may be other conditions). 

 

When setting the order list for mapping SELinux users you may need to 

quote the value so it isn't interpreted by the shell. 

 

EXAMPLES: 

 

Show basic server configuration: 

   ipa config-show 

 

Show all configuration options: 

   ipa config-show --all 

 

Change maximum username length to 99 characters: 

   ipa config-mod --maxusername=99 

 

Increase default time and size limits for maximum IPA server search: 

   ipa config-mod --searchtimelimit=10 --searchrecordslimit=2000 

 

Set default user e-mail domain: 

   ipa config-mod --emaildomain=example.com 

 

Enable migration mode to make "ipa migrate-ds" command operational: 

   ipa config-mod --enable-migration=TRUE 

 

Define SELinux user map order: 

   ipa config-mod --ipaselinuxusermaporder='guest_u:s0$xguest_u:s0$user_u:s0-s0:c0.c1023$staff_u:s0-s0:c0.c1023$unconfined_u:s0-s0:c0.c1023' 

""") 

 

def validate_searchtimelimit(ugettext, limit): 

    if limit == 0: 

        raise ValidationError(name='ipasearchtimelimit', error=_('searchtimelimit must be -1 or > 1.')) 

    return None 

 

class config(LDAPObject): 

    """ 

    IPA configuration object 

    """ 

    object_name = _('configuration options') 

    default_attributes = [ 

        'ipamaxusernamelength', 'ipahomesrootdir', 'ipadefaultloginshell', 

        'ipadefaultprimarygroup', 'ipadefaultemaildomain', 'ipasearchtimelimit', 

        'ipasearchrecordslimit', 'ipausersearchfields', 'ipagroupsearchfields', 

        'ipamigrationenabled', 'ipacertificatesubjectbase', 

        'ipapwdexpadvnotify', 'ipaselinuxusermaporder', 

        'ipaselinuxusermapdefault', 'ipaconfigstring', 

    ] 

 

    label = _('Configuration') 

    label_singular = _('Configuration') 

 

    takes_params = ( 

        Int('ipamaxusernamelength', 

            cli_name='maxusername', 

            label=_('Maximum username length'), 

            minvalue=1, 

        ), 

        IA5Str('ipahomesrootdir', 

            cli_name='homedirectory', 

            label=_('Home directory base'), 

            doc=_('Default location of home directories'), 

        ), 

        Str('ipadefaultloginshell', 

            cli_name='defaultshell', 

            label=_('Default shell'), 

            doc=_('Default shell for new users'), 

        ), 

        Str('ipadefaultprimarygroup', 

            cli_name='defaultgroup', 

            label=_('Default users group'), 

            doc=_('Default group for new users'), 

        ), 

        Str('ipadefaultemaildomain?', 

            cli_name='emaildomain', 

            label=_('Default e-mail domain'), 

            doc=_('Default e-mail domain'), 

        ), 

        Int('ipasearchtimelimit', validate_searchtimelimit, 

            cli_name='searchtimelimit', 

            label=_('Search time limit'), 

            doc=_('Maximum amount of time (seconds) for a search (> 0, or -1 for unlimited)'), 

            minvalue=-1, 

        ), 

        Int('ipasearchrecordslimit', 

            cli_name='searchrecordslimit', 

            label=_('Search size limit'), 

            doc=_('Maximum number of records to search (-1 is unlimited)'), 

            minvalue=-1, 

        ), 

        IA5Str('ipausersearchfields', 

            cli_name='usersearch', 

            label=_('User search fields'), 

            doc=_('A comma-separated list of fields to search in when searching for users'), 

        ), 

        IA5Str('ipagroupsearchfields', 

            cli_name='groupsearch', 

            label='Group search fields', 

            doc=_('A comma-separated list of fields to search in when searching for groups'), 

        ), 

        Bool('ipamigrationenabled', 

            cli_name='enable_migration', 

            label=_('Enable migration mode'), 

            doc=_('Enable migration mode'), 

        ), 

        Str('ipacertificatesubjectbase', 

            cli_name='subject', 

            label=_('Certificate Subject base'), 

            doc=_('Base for certificate subjects (OU=Test,O=Example)'), 

            flags=['no_update'], 

        ), 

        Str('ipagroupobjectclasses+', 

            cli_name='groupobjectclasses', 

            label=_('Default group objectclasses'), 

            doc=_('Default group objectclasses (comma-separated list)'), 

            csv=True, 

        ), 

        Str('ipauserobjectclasses+', 

            cli_name='userobjectclasses', 

            label=_('Default user objectclasses'), 

            doc=_('Default user objectclasses (comma-separated list)'), 

            csv=True, 

        ), 

        Int('ipapwdexpadvnotify', 

            cli_name='pwdexpnotify', 

            label=_('Password Expiration Notification (days)'), 

            doc=_('Number of days\'s notice of impending password expiration'), 

            minvalue=0, 

        ), 

        StrEnum('ipaconfigstring*', 

            cli_name='ipaconfigstring', 

            label=_('Password plugin features'), 

            doc=_('Extra hashes to generate in password plug-in'), 

            values=(u'AllowLMhash', u'AllowNThash'), 

            csv=True, 

        ), 

        Str('ipaselinuxusermaporder', 

            label=_('SELinux user map order'), 

            doc=_('Order in increasing priority of SELinux users, delimited by $'), 

        ), 

        Str('ipaselinuxusermapdefault', 

            label=_('Default SELinux user'), 

            doc=_('Default SELinux user when no match is found in SELinux map rule'), 

        ), 

    ) 

 

    def get_dn(self, *keys, **kwargs): 

        return 'cn=ipaconfig,cn=etc' 

 

api.register(config) 

 

 

class config_mod(LDAPUpdate): 

    __doc__ = _('Modify configuration options.') 

 

    def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options): 

        if 'ipadefaultprimarygroup' in entry_attrs: 

            group=entry_attrs['ipadefaultprimarygroup'] 

            try: 

                api.Command['group_show'](group) 

            except errors.NotFound: 

                raise errors.NotFound(message=_("The group doesn't exist")) 

        kw = {} 

        if 'ipausersearchfields' in entry_attrs: 

            kw['ipausersearchfields'] = 'ipauserobjectclasses' 

        if 'ipagroupsearchfields' in entry_attrs: 

            kw['ipagroupsearchfields']  = 'ipagroupobjectclasses' 

        if kw: 

            config = ldap.get_ipa_config(kw.values()) 

            for (k, v) in kw.iteritems(): 

                allowed_attrs = ldap.get_allowed_attributes(config[1][v]) 

                fields = entry_attrs[k].split(',') 

                for a in fields: 

                    a = a.strip() 

                    if a not in allowed_attrs: 

                        raise errors.ValidationError( 

                            name=k, error=_('attribute "%s" not allowed') % a 

                        ) 

 

        for (attr, obj) in (('ipauserobjectclasses', 'user'), 

                            ('ipagroupobjectclasses', 'group')): 

            if attr in entry_attrs: 

                if not entry_attrs[attr]: 

                    raise errors.ValidationError(name=attr, 

                        error=_('May not be empty')) 

                objectclasses = list(set(entry_attrs[attr]).union( 

                        self.api.Object[obj].possible_objectclasses)) 

                new_allowed_attrs = ldap.get_allowed_attributes(objectclasses, 

                                        raise_on_unknown=True) 

                checked_attrs = self.api.Object[obj].default_attributes 

                if self.api.Object[obj].uuid_attribute: 

                    checked_attrs = checked_attrs + [self.api.Object[obj].uuid_attribute] 

                for obj_attr in checked_attrs: 

                    if obj_attr in OPERATIONAL_ATTRIBUTES: 

                        continue 

                    if obj_attr in self.api.Object[obj].params and \ 

                      'virtual_attribute' in \ 

                      self.api.Object[obj].params[obj_attr].flags: 

                        # skip virtual attributes 

                        continue 

                    if obj_attr not in new_allowed_attrs: 

                        raise errors.ValidationError(name=attr, 

                                error=_('%(obj)s default attribute %(attr)s would not be allowed!') \ 

                                % dict(obj=obj, attr=obj_attr)) 

 

        if 'ipaselinuxusermapdefault' in options and options['ipaselinuxusermapdefault'] is None: 

            raise errors.ValidationError(name='ipaselinuxusermapdefault', 

                error=_('SELinux user map default user may not be empty')) 

 

        # Make sure the default user is in the list 

        if 'ipaselinuxusermapdefault' in options or \ 

          'ipaselinuxusermaporder' in options: 

            config = None 

            if 'ipaselinuxusermapdefault' in options: 

                defaultuser = options['ipaselinuxusermapdefault'] 

            else: 

                config = ldap.get_ipa_config()[1] 

                defaultuser = config['ipaselinuxusermapdefault'] 

 

            if 'ipaselinuxusermaporder' in options: 

                order = options['ipaselinuxusermaporder'] 

            else: 

                if not config: 

                    config = ldap.get_ipa_config()[1] 

                order = config['ipaselinuxusermaporder'] 

            userlist = order[0].split('$') 

            if defaultuser not in userlist: 

                raise errors.ValidationError(name='ipaselinuxusermaporder', 

                    error=_('Default SELinux user map default user not in order list')) 

 

        return dn 

 

api.register(config_mod) 

 

 

class config_show(LDAPRetrieve): 

    __doc__ = _('Show the current configuration.') 

 

api.register(config_show)