4
4
# --- BEGIN_HEADER ---
5
5
#
6
6
# reqacceptpeer - Forward account request from peer to existing user(s)
7
- # Copyright (C) 2003-2020 The MiG Project lead by Brian Vinter
7
+ # Copyright (C) 2003-2021 The MiG Project lead by Brian Vinter
8
8
#
9
9
# This file is part of MiG.
10
10
#
32
32
or email from Distinguished Name field of employee user entry. If user
33
33
configured additional messaging protocols they can also be used.
34
34
"""
35
+
35
36
from __future__ import print_function
36
37
from __future__ import absolute_import
37
38
48
49
from mig .shared .serial import load , dump
49
50
from mig .shared .useradm import init_user_adm , search_users , default_search , \
50
51
user_account_notify
52
+ from mig .shared .validstring import valid_email_addresses
51
53
52
54
53
55
def usage (name = 'reqacceptpeer.py' ):
@@ -62,7 +64,8 @@ def usage(name='reqacceptpeer.py'):
62
64
-c CONF_FILE Use CONF_FILE as server configuration
63
65
-C Send a copy of notifications to configured site admins
64
66
-d DB_PATH Use DB_PATH as user data base file path
65
- -e EMAIL Send instructions to custom email address
67
+ -e EMAIL Send instructions to custom EMAIL address
68
+ -E EMAIL Forward peer request to user(s) with EMAIL (AUTO to parse Comment)
66
69
-h Show this help
67
70
-I CERT_DN Forward peer request to user(s) with ID (distinguished name)
68
71
-s PROTOCOL Send instructions to notification protocol from settings
@@ -92,8 +95,9 @@ def usage(name='reqacceptpeer.py'):
92
95
# IMPORTANT: Default to nobody to avoid spam if called without -I CLIENT_ID
93
96
search_filter ['distinguished_name' ] = ''
94
97
peer_dict = {}
98
+ regex_keys = []
95
99
exit_code = 0
96
- opt_args = 'ac:Cd:e:hI:s:u:v'
100
+ opt_args = 'ac:Cd:e:E: hI:s:u:v'
97
101
try :
98
102
(opts , args ) = getopt .getopt (args , opt_args )
99
103
except getopt .GetoptError as err :
@@ -114,6 +118,11 @@ def usage(name='reqacceptpeer.py'):
114
118
elif opt == '-e' :
115
119
raw_targets ['email' ] = raw_targets .get ('email' , [])
116
120
raw_targets ['email' ].append (val )
121
+ elif opt == '-E' :
122
+ if val != keyword_auto :
123
+ search_filter ['email' ] = val .lower ()
124
+ else :
125
+ search_filter ['email' ] = keyword_auto
117
126
elif opt == '-h' :
118
127
usage ()
119
128
sys .exit (0 )
@@ -179,24 +188,42 @@ def usage(name='reqacceptpeer.py'):
179
188
fill_distinguished_name (peer_dict )
180
189
peer_id = peer_dict ['distinguished_name' ]
181
190
191
+ if search_filter ['email' ] == keyword_auto :
192
+ peer_emails = valid_email_addresses (
193
+ configuration , peer_dict ['comment' ])
194
+ if peer_emails [1 :]:
195
+ regex_keys .append ('email' )
196
+ search_filter ['email' ] = '(' + '|' .join (peer_emails ) + ')'
197
+ elif peer_emails :
198
+ search_filter ['email' ] = peer_emails [0 ]
199
+ elif search_filter ['distinguished_name' ]:
200
+ search_filter ['email' ] = '*'
201
+ else :
202
+ search_filter ['email' ] = ''
203
+
204
+ # If email is provided or detected DN may be almost anything
205
+ if search_filter ['email' ] and not search_filter ['distinguished_name' ]:
206
+ search_filter ['distinguished_name' ] = '*emailAddress=*'
207
+
182
208
if verbose :
183
- print ('Handling peer %s request to %s' %
184
- (peer_id , search_filter [ 'distinguished_name' ] ))
209
+ print ('Handling peer %s request to users matching %s' %
210
+ (peer_id , search_filter ))
185
211
186
212
# Lookup users to request formal acceptance from
187
- (_ , hits ) = search_users (search_filter , conf_path , db_path , verbose )
213
+ (_ , hits ) = search_users (search_filter , conf_path ,
214
+ db_path , verbose , regex_match = regex_keys )
188
215
logger = configuration .logger
189
216
gdp_prefix = "%s=" % gdp_distinguished_field
190
217
191
218
if len (hits ) < 1 :
192
219
print (
193
220
"Aborting attempt to request peer acceptance without target users" )
194
- print (" ... did you forget or supply too rigid -I CLIENT_ID argument ?" )
221
+ print (" ... did you forget or supply too rigid -E EMAIL or -I DN arg ?" )
195
222
sys .exit (1 )
196
223
elif len (hits ) > 3 :
197
224
print ("Aborting attempt to request peer acceptance from %d users!" %
198
225
len (hits ))
199
- print (" ... did you supply too lax -I CLIENT_ID argument?" )
226
+ print (" ... did you supply too lax -E EMAIL or -I DN argument?" )
200
227
sys .exit (1 )
201
228
else :
202
229
if verbose :
@@ -213,9 +240,12 @@ def usage(name='reqacceptpeer.py'):
213
240
print ("Skip GDP project account: %s" % user_id )
214
241
continue
215
242
243
+ if peer_id == user_id :
244
+ print ("Skip same user account %s as own peer" % user_id )
245
+ continue
246
+
216
247
if not peers_permit_allowed (configuration , user_dict ):
217
- if verbose :
218
- print ("Skip account %s without vouching permission" % user_id )
248
+ print ("Skip account %s without vouching permission" % user_id )
219
249
continue
220
250
221
251
if not manage_pending_peers (configuration , user_id , "add" ,
0 commit comments