]> git.sur5r.net Git - openldap/blob - servers/slapd/modrdn.c
slapi header cleanup
[openldap] / servers / slapd / modrdn.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  * Copyright (c) 1995 Regents of the University of Michigan.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms are permitted
11  * provided that this notice is preserved and that due credit is given
12  * to the University of Michigan at Ann Arbor. The name of the University
13  * may not be used to endorse or promote products derived from this
14  * software without specific prior written permission. This software
15  * is provided ``as is'' without express or implied warranty.
16  */
17
18 /*
19  * LDAP v3 newSuperior support.
20  *
21  * Copyright 1999, Juan C. Gomez, All rights reserved.
22  * This software is not subject to any license of Silicon Graphics 
23  * Inc. or Purdue University.
24  *
25  * Redistribution and use in source and binary forms are permitted
26  * without restriction or fee of any kind as long as this notice
27  * is preserved.
28  *
29  */
30
31 #include "portable.h"
32
33 #include <stdio.h>
34
35 #include <ac/socket.h>
36 #include <ac/string.h>
37
38 #include "ldap_pvt.h"
39 #include "slap.h"
40 #include "slapi.h"
41
42 int
43 do_modrdn(
44     Connection  *conn,
45     Operation   *op
46 )
47 {
48         struct berval dn = { 0, NULL };
49         struct berval newrdn = { 0, NULL };
50         struct berval newSuperior = { 0, NULL };
51         ber_int_t       deloldrdn;
52
53         struct berval pdn = { 0, NULL };
54         struct berval pnewrdn = { 0, NULL };
55         struct berval pnewSuperior = { 0, NULL }, *pnewS = NULL;
56
57         struct berval ndn = { 0, NULL };
58         struct berval nnewrdn = { 0, NULL };
59         struct berval nnewSuperior = { 0, NULL }, *nnewS = NULL;
60
61         Backend *be;
62         Backend *newSuperior_be = NULL;
63         ber_len_t       length;
64         int rc;
65         const char *text;
66         int manageDSAit;
67
68         Slapi_PBlock *pb = op->o_pb;
69
70 #ifdef NEW_LOGGING
71         LDAP_LOG( OPERATION, ENTRY, "do_modrdn: begin\n", 0, 0, 0 );
72 #else
73         Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
74 #endif
75
76
77         /*
78          * Parse the modrdn request.  It looks like this:
79          *
80          *      ModifyRDNRequest := SEQUENCE {
81          *              entry   DistinguishedName,
82          *              newrdn  RelativeDistinguishedName
83          *              deleteoldrdn    BOOLEAN,
84          *              newSuperior     [0] LDAPDN OPTIONAL (v3 Only!)
85          *      }
86          */
87
88         if ( ber_scanf( op->o_ber, "{mmb", &dn, &newrdn, &deloldrdn )
89             == LBER_ERROR )
90         {
91 #ifdef NEW_LOGGING
92                 LDAP_LOG( OPERATION, ERR, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
93 #else
94                 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
95 #endif
96
97                 send_ldap_disconnect( conn, op,
98                         LDAP_PROTOCOL_ERROR, "decoding error" );
99                 return SLAPD_DISCONNECT;
100         }
101
102         /* Check for newSuperior parameter, if present scan it */
103
104         if ( ber_peek_tag( op->o_ber, &length ) == LDAP_TAG_NEWSUPERIOR ) {
105                 if ( op->o_protocol < LDAP_VERSION3 ) {
106                         /* Conection record indicates v2 but field 
107                          * newSuperior is present: report error.
108                          */
109 #ifdef NEW_LOGGING
110                         LDAP_LOG( OPERATION, ERR,
111                                 "do_modrdn: (v2) invalid field newSuperior.\n", 0, 0, 0 );
112 #else
113                         Debug( LDAP_DEBUG_ANY,
114                             "modrdn(v2): invalid field newSuperior!\n",
115                             0, 0, 0 );
116 #endif
117
118                         send_ldap_disconnect( conn, op,
119                                 LDAP_PROTOCOL_ERROR, "newSuperior requires LDAPv3" );
120                         rc = SLAPD_DISCONNECT;
121                         goto cleanup;
122                 }
123
124                 if ( ber_scanf( op->o_ber, "m", &newSuperior ) 
125                      == LBER_ERROR ) {
126
127 #ifdef NEW_LOGGING
128                         LDAP_LOG( OPERATION, ERR,
129                                 "do_modrdn: ber_scanf(\"m\") failed\n", 0, 0, 0 );
130 #else
131                         Debug( LDAP_DEBUG_ANY, "ber_scanf(\"m\") failed\n",
132                                 0, 0, 0 );
133 #endif
134
135                         send_ldap_disconnect( conn, op,
136                                 LDAP_PROTOCOL_ERROR, "decoding error" );
137                         rc = SLAPD_DISCONNECT;
138                         goto cleanup;
139                 }
140                 pnewS = &pnewSuperior;
141                 nnewS = &nnewSuperior;
142         }
143
144 #ifdef NEW_LOGGING
145         LDAP_LOG( OPERATION, ARGS, 
146                 "do_modrdn: dn (%s) newrdn (%s) newsuperior(%s)\n",
147                 dn.bv_val, newrdn.bv_val,
148                 newSuperior.bv_len ? newSuperior.bv_val : "" );
149 #else
150         Debug( LDAP_DEBUG_ARGS,
151             "do_modrdn: dn (%s) newrdn (%s) newsuperior (%s)\n",
152                 dn.bv_val, newrdn.bv_val,
153                 newSuperior.bv_len ? newSuperior.bv_val : "" );
154 #endif
155
156         if ( ber_scanf( op->o_ber, /*{*/ "}") == LBER_ERROR ) {
157 #ifdef NEW_LOGGING
158                 LDAP_LOG( OPERATION, ERR, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
159 #else
160                 Debug( LDAP_DEBUG_ANY, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
161 #endif
162
163                 send_ldap_disconnect( conn, op,
164                         LDAP_PROTOCOL_ERROR, "decoding error" );
165                 rc = SLAPD_DISCONNECT;
166                 goto cleanup;
167         }
168
169         if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
170 #ifdef NEW_LOGGING
171                 LDAP_LOG( OPERATION, ERR, "do_modrdn: get_ctrls failed\n", 0, 0, 0 );
172 #else
173                 Debug( LDAP_DEBUG_ANY, "do_modrdn: get_ctrls failed\n", 0, 0, 0 );
174 #endif
175
176                 /* get_ctrls has sent results.  Now clean up. */
177                 goto cleanup;
178         } 
179
180         rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
181         if( rc != LDAP_SUCCESS ) {
182 #ifdef NEW_LOGGING
183                 LDAP_LOG( OPERATION, INFO, 
184                         "do_modrdn: conn %d  invalid dn (%s)\n",
185                         conn->c_connid, dn.bv_val, 0 );
186 #else
187                 Debug( LDAP_DEBUG_ANY,
188                         "do_modrdn: invalid dn (%s)\n", dn.bv_val, 0, 0 );
189 #endif
190                 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
191                     "invalid DN", NULL, NULL );
192                 goto cleanup;
193         }
194
195         if( ndn.bv_len == 0 ) {
196 #ifdef NEW_LOGGING
197                 LDAP_LOG( OPERATION, ERR,
198                         "do_modrdn:  attempt to modify root DSE.\n", 0, 0, 0 );
199 #else
200                 Debug( LDAP_DEBUG_ANY, "do_modrdn: root dse!\n", 0, 0, 0 );
201 #endif
202
203                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
204                         NULL, "cannot rename the root DSE", NULL, NULL );
205                 goto cleanup;
206
207         } else if ( bvmatch( &ndn, &global_schemandn ) ) {
208 #ifdef NEW_LOGGING
209                 LDAP_LOG( OPERATION, ERR,
210                         "do_modrdn: attempt to modify subschema subentry: %s (%ld)\n",
211                         global_schemandn.bv_val, (long) global_schemandn.bv_len, 0 );
212 #else
213                 Debug( LDAP_DEBUG_ANY, "do_modrdn: subschema subentry: %s (%ld)\n",
214                         global_schemandn.bv_val, (long) global_schemandn.bv_len, 0 );
215 #endif
216
217                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
218                         NULL, "cannot rename subschema subentry", NULL, NULL );
219                 goto cleanup;
220         }
221
222         /* FIXME: should have/use rdnPretty / rdnNormalize routines */
223
224         rc = dnPrettyNormal( NULL, &newrdn, &pnewrdn, &nnewrdn );
225         if( rc != LDAP_SUCCESS ) {
226 #ifdef NEW_LOGGING
227                 LDAP_LOG( OPERATION, INFO, 
228                         "do_modrdn: conn %d  invalid newrdn (%s)\n",
229                         conn->c_connid, newrdn.bv_val, 0 );
230 #else
231                 Debug( LDAP_DEBUG_ANY,
232                         "do_modrdn: invalid newrdn (%s)\n", newrdn.bv_val, 0, 0 );
233 #endif
234                 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
235                     "invalid new RDN", NULL, NULL );
236                 goto cleanup;
237         }
238
239         if( rdnValidate( &pnewrdn ) != LDAP_SUCCESS ) {
240 #ifdef NEW_LOGGING
241                 LDAP_LOG( OPERATION, ERR, 
242                         "do_modrdn: invalid rdn (%s).\n", pnewrdn.bv_val, 0, 0 );
243 #else
244                 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid rdn (%s)\n",
245                         pnewrdn.bv_val, 0, 0 );
246 #endif
247
248                 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
249                     "invalid new RDN", NULL, NULL );
250                 goto cleanup;
251         }
252
253         if( pnewS ) {
254                 rc = dnPrettyNormal( NULL, &newSuperior, &pnewSuperior,
255                         &nnewSuperior );
256                 if( rc != LDAP_SUCCESS ) {
257 #ifdef NEW_LOGGING
258                         LDAP_LOG( OPERATION, INFO, 
259                                 "do_modrdn: conn %d  invalid newSuperior (%s)\n",
260                                 conn->c_connid, newSuperior.bv_val, 0 );
261 #else
262                         Debug( LDAP_DEBUG_ANY,
263                                 "do_modrdn: invalid newSuperior (%s)\n",
264                                 newSuperior.bv_val, 0, 0 );
265 #endif
266                         send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
267                                 "invalid newSuperior", NULL, NULL );
268                         goto cleanup;
269                 }
270         }
271
272         Statslog( LDAP_DEBUG_STATS, "conn=%lu op=%lu MODRDN dn=\"%s\"\n",
273             op->o_connid, op->o_opid, pdn.bv_val, 0, 0 );
274
275         manageDSAit = get_manageDSAit( op );
276
277         /*
278          * We could be serving multiple database backends.  Select the
279          * appropriate one, or send a referral to our "referral server"
280          * if we don't hold it.
281          */
282         if ( (be = select_backend( &ndn, manageDSAit, 0 )) == NULL ) {
283                 BerVarray ref = referral_rewrite( default_referral,
284                         NULL, &pdn, LDAP_SCOPE_DEFAULT );
285
286                 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
287                         NULL, NULL, ref ? ref : default_referral, NULL );
288
289                 ber_bvarray_free( ref );
290                 goto cleanup;
291         }
292
293         /* check restrictions */
294         rc = backend_check_restrictions( be, conn, op, NULL, &text ) ;
295         if( rc != LDAP_SUCCESS ) {
296                 send_ldap_result( conn, op, rc,
297                         NULL, text, NULL, NULL );
298                 goto cleanup;
299         }
300
301         /* check for referrals */
302         rc = backend_check_referrals( be, conn, op, &pdn, &ndn );
303         if ( rc != LDAP_SUCCESS ) {
304                 goto cleanup;
305         }
306
307         /* Make sure that the entry being changed and the newSuperior are in 
308          * the same backend, otherwise we return an error.
309          */
310         if( pnewS ) {
311                 newSuperior_be = select_backend( &nnewSuperior, 0, 0 );
312
313                 if ( newSuperior_be != be ) {
314                         /* newSuperior is in same backend */
315                         rc = LDAP_AFFECTS_MULTIPLE_DSAS;
316
317                         send_ldap_result( conn, op, rc,
318                                 NULL, "cannot rename between DSAa", NULL, NULL );
319
320                         goto cleanup;
321                 }
322
323                 /* deref suffix alias if appropriate */
324                 suffix_alias( be, &nnewSuperior );
325         }
326
327         /* deref suffix alias if appropriate */
328         suffix_alias( be, &ndn );
329
330 #if defined( LDAP_SLAPI )
331         slapi_x_backend_set_pb( pb, be );
332         slapi_x_connection_set_pb( pb, conn );
333         slapi_x_operation_set_pb( pb, op );
334         slapi_pblock_set( pb, SLAPI_MODRDN_TARGET, (void *)dn.bv_val );
335         slapi_pblock_set( pb, SLAPI_MODRDN_NEWRDN, (void *)newrdn.bv_val );
336         slapi_pblock_set( pb, SLAPI_MODRDN_NEWSUPERIOR,
337                         (void *)newSuperior.bv_val );
338         slapi_pblock_set( pb, SLAPI_MODRDN_DELOLDRDN, (void *)deloldrdn );
339         slapi_pblock_set( pb, SLAPI_MANAGEDSAIT, (void *)manageDSAit );
340
341         rc = doPluginFNs( be, SLAPI_PLUGIN_PRE_MODRDN_FN, pb );
342         if ( rc != 0 ) {
343                 /*
344                  * A preoperation plugin failure will abort the
345                  * entire operation.
346                  */
347 #ifdef NEW_LOGGING
348                 LDAP_LOG( OPERATION, INFO, "do_modrdn: modrdn preoperation plugin "
349                                 "failed\n", 0, 0, 0 );
350 #else
351                 Debug(LDAP_DEBUG_TRACE, "do_modrdn: modrdn preoperation plugin "
352                                 "failed.\n", 0, 0, 0);
353 #endif
354                 if ( slapi_pblock_get( pb, SLAPI_RESULT_CODE, (void *)&rc ) != 0)
355                         rc = LDAP_OTHER;
356                 goto cleanup;
357         }
358 #endif /* defined( LDAP_SLAPI ) */
359
360         /*
361          * do the add if 1 && (2 || 3)
362          * 1) there is an add function implemented in this backend;
363          * 2) this backend is master for what it holds;
364          * 3) it's a replica and the dn supplied is the update_ndn.
365          */
366         if ( be->be_modrdn ) {
367                 /* do the update here */
368                 int repl_user = be_isupdate( be, &op->o_ndn );
369 #ifndef SLAPD_MULTIMASTER
370                 if ( !be->be_update_ndn.bv_len || repl_user )
371 #endif
372                 {
373                         if ( (*be->be_modrdn)( be, conn, op, &pdn, &ndn,
374                                 &pnewrdn, &nnewrdn, deloldrdn,
375                                 pnewS, nnewS ) == 0
376 #ifdef SLAPD_MULTIMASTER
377                                 && ( !be->be_update_ndn.bv_len || !repl_user )
378 #endif
379                         ) {
380                                 struct slap_replog_moddn moddn;
381                                 moddn.newrdn = &pnewrdn;
382                                 moddn.deloldrdn = deloldrdn;
383                                 moddn.newsup = &pnewSuperior;
384
385                                 replog( be, op, &pdn, &ndn, &moddn );
386                         }
387 #ifndef SLAPD_MULTIMASTER
388                 } else {
389                         BerVarray defref = be->be_update_refs
390                                 ? be->be_update_refs : default_referral;
391                         BerVarray ref = referral_rewrite( defref,
392                                 NULL, &pdn, LDAP_SCOPE_DEFAULT );
393
394                         send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
395                                 ref ? ref : defref, NULL );
396
397                         ber_bvarray_free( ref );
398 #endif
399                 }
400         } else {
401                 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
402                         NULL, "operation not supported within namingContext",
403                         NULL, NULL );
404         }
405
406 #if defined( LDAP_SLAPI )
407         if ( doPluginFNs( be, SLAPI_PLUGIN_POST_MODRDN_FN, pb ) != 0 ) {
408 #ifdef NEW_LOGGING
409                 LDAP_LOG( OPERATION, INFO, "do_modrdn: modrdn postoperation plugins "
410                                 "failed\n", 0, 0, 0 );
411 #else
412                 Debug(LDAP_DEBUG_TRACE, "do_modrdn: modrdn postoperation plugins "
413                                 "failed.\n", 0, 0, 0);
414 #endif
415         }
416 #endif /* defined( LDAP_SLAPI ) */
417
418 cleanup:
419         free( pdn.bv_val );
420         free( ndn.bv_val );
421
422         free( pnewrdn.bv_val ); 
423         free( nnewrdn.bv_val ); 
424
425         if ( pnewSuperior.bv_val ) free( pnewSuperior.bv_val );
426         if ( nnewSuperior.bv_val ) free( nnewSuperior.bv_val );
427
428         return rc;
429 }
430
431 int
432 slap_modrdn2mods(
433         Backend         *be,
434         Connection      *conn,
435         Operation       *op,
436         Entry           *e,
437         LDAPRDN         *old_rdn,
438         LDAPRDN         *new_rdn,
439         int             deleteoldrdn,
440         Modifications   **pmod )
441 {
442         int             rc = LDAP_SUCCESS;
443         const char      *text;
444         Modifications   *mod = NULL;
445         int             a_cnt, d_cnt;
446
447         assert( new_rdn != NULL );
448         assert( !deleteoldrdn || old_rdn != NULL );
449
450         /* Add new attribute values to the entry */
451         for ( a_cnt = 0; new_rdn[ 0 ][ a_cnt ]; a_cnt++ ) {
452                 AttributeDescription    *desc = NULL;
453                 Modifications           *mod_tmp;
454
455                 rc = slap_bv2ad( &new_rdn[ 0 ][ a_cnt ]->la_attr, 
456                                 &desc, &text );
457
458                 if ( rc != LDAP_SUCCESS ) {
459 #ifdef NEW_LOGGING
460                         LDAP_LOG ( OPERATION, ERR, 
461                                 "slap_modrdn2modlist: %s: %s (new)\n", 
462                                 text, 
463                                 new_rdn[ 0 ][ a_cnt ]->la_attr.bv_val, 0 );
464 #else
465                         Debug( LDAP_DEBUG_TRACE,
466                                 "slap_modrdn2modlist: %s: %s (new)\n",
467                                 text, 
468                                 new_rdn[ 0 ][ a_cnt ]->la_attr.bv_val, 0 );
469 #endif
470                         goto done;              
471                 }
472
473                 /* ACL check of newly added attrs */
474                 if ( be && !access_allowed( be, conn, op, e, desc,
475                         &new_rdn[ 0 ][ a_cnt ]->la_value, ACL_WRITE, NULL ) ) {
476 #ifdef NEW_LOGGING
477                         LDAP_LOG ( OPERATION, ERR, 
478                                 "slap_modrdn2modlist: access to attr \"%s\" "
479                                 "(new) not allowed\n", 
480                                 new_rdn[ 0 ][a_cnt]->la_attr.bv_val, 0, 0 );
481 #else
482                         Debug( LDAP_DEBUG_TRACE,
483                                 "slap_modrdn2modlist: access to attr \"%s\" "
484                                 "(new) not allowed\n", 
485                                 new_rdn[ 0 ][ a_cnt ]->la_attr.bv_val, 0, 0 );
486 #endif
487                         rc = LDAP_INSUFFICIENT_ACCESS;
488                         goto done;
489                 }
490
491                 /* Apply modification */
492                 mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
493                         + 2 * sizeof( struct berval ) );
494                 mod_tmp->sml_desc = desc;
495                 mod_tmp->sml_bvalues = ( BerVarray )( mod_tmp + 1 );
496                 mod_tmp->sml_bvalues[ 0 ] = new_rdn[ 0 ][ a_cnt ]->la_value;
497                 mod_tmp->sml_bvalues[ 1 ].bv_val = NULL;
498                 mod_tmp->sml_op = SLAP_MOD_SOFTADD;
499                 mod_tmp->sml_next = mod;
500                 mod = mod_tmp;
501         }
502
503         /* Remove old rdn value if required */
504         if ( deleteoldrdn ) {
505                 for ( d_cnt = 0; old_rdn[ 0 ][ d_cnt ]; d_cnt++ ) {
506                         AttributeDescription    *desc = NULL;
507                         Modifications           *mod_tmp;
508
509                         rc = slap_bv2ad( &old_rdn[ 0 ][ d_cnt ]->la_attr,
510                                         &desc, &text );
511
512                         if ( rc != LDAP_SUCCESS ) {
513 #ifdef NEW_LOGGING
514                                 LDAP_LOG ( OPERATION, ERR, 
515                                         "slap_modrdn2modlist: %s: %s (old)\n", 
516                                         text, 
517                                         old_rdn[ 0 ][ d_cnt ]->la_attr.bv_val, 
518                                         0 );
519 #else
520                                 Debug( LDAP_DEBUG_TRACE,
521                                         "slap_modrdn2modlist: %s: %s (old)\n",
522                                         text, 
523                                         old_rdn[ 0 ][ d_cnt ]->la_attr.bv_val, 
524                                         0 );
525 #endif
526                                 goto done;              
527                         }
528
529                         /* ACL check of newly added attrs */
530                         if ( be && !access_allowed( be, conn, op, e, desc,
531                                 &old_rdn[ 0 ][ d_cnt ]->la_value, ACL_WRITE, 
532                                 NULL ) ) {
533 #ifdef NEW_LOGGING
534                                 LDAP_LOG ( OPERATION, ERR, 
535                                         "slap_modrdn2modlist: access "
536                                         "to attr \"%s\" (old) not allowed\n", 
537                                         old_rdn[ 0 ][ d_cnt ]->la_attr.bv_val, 
538                                         0, 0 );
539 #else
540                                 Debug( LDAP_DEBUG_TRACE,
541                                         "slap_modrdn2modlist: access "
542                                         "to attr \"%s\" (old) not allowed\n", 
543                                         old_rdn[ 0 ][ d_cnt ]->la_attr.bv_val,
544                                         0, 0 );
545 #endif
546                                 rc = LDAP_INSUFFICIENT_ACCESS;
547                                 goto done;
548                         }
549
550                         /* Apply modification */
551                         mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications )
552                                 + 2 * sizeof ( struct berval ) );
553                         mod_tmp->sml_desc = desc;
554                         mod_tmp->sml_bvalues = ( BerVarray )(mod_tmp+1);
555                         mod_tmp->sml_bvalues[ 0 ] 
556                                 = old_rdn[ 0 ][ d_cnt ]->la_value;
557                         mod_tmp->sml_bvalues[ 1 ].bv_val = NULL;
558                         mod_tmp->sml_op = LDAP_MOD_DELETE;
559                         mod_tmp->sml_next = mod;
560                         mod = mod_tmp;
561                 }
562         }
563         
564 done:
565         /* LDAP v2 supporting correct attribute handling. */
566         if ( rc != LDAP_SUCCESS && mod != NULL ) {
567                 Modifications *tmp;
568                 for ( ; mod; mod = tmp ) {
569                         tmp = mod->sml_next;
570                         ch_free( mod );
571                 }
572         }
573
574         *pmod = mod;
575
576         return rc;
577 }