File: globus_oldgaa_utils.c

package info (click to toggle)
globus-gsi-callback 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,756 kB
  • sloc: sh: 11,067; ansic: 5,658; makefile: 161
file content (1496 lines) | stat: -rw-r--r-- 44,747 bytes parent folder | download | duplicates (7)
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
/*
 * Copyright 1999-2006 University of Chicago
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**********************************************************************
 globus_oldgaa-utils.c:

Description:
        Globus-OLDGAA routines
**********************************************************************/


/**********************************************************************
                             Include header files
**********************************************************************/

#include "globus_oldgaa.h"
#include "globus_oldgaa_utils.h" 
#include "oldgaa_gl_internal_err.h"
#include "oldgaa_policy_evaluator.h"

#include "oldgaa_utils.h"
#include "globus_i_gsi_callback_config.h"

#include <string.h>	/* for strerror() */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h> 

/**********************************************************************
                       Define module specific variables
**********************************************************************/

static  int     end_of_file;
static  uint32  m_status     = 0;

/*********************************************************************
                       Declaration of Static Helper Functions
**********************************************************************/
static
int
get_default_policy_file(oldgaa_data_ptr policy_db);

static
int
oldgaa_globus_read_string (policy_file_context_ptr  pcontext,
                           char                    *str,
                           char                    **errstring);

static oldgaa_error_code
oldgaa_globus_parse_principals(policy_file_context_ptr  pcontext,
			       oldgaa_policy_ptr          *policy,
			       char                    *tmp_str /* IN&OUT */,
			       oldgaa_principals_ptr      *start,
			       oldgaa_principals_ptr    *added_principal);

static
int
oldgaa_globus_get_string_with_whitespaces(policy_file_context_ptr  pcontext,
                                          char                    *str);

static
int
oldgaa_globus_omit_comment_line(policy_file_context_ptr  pcontext);

static void
oldgaa_bind_rights_to_condition(oldgaa_rights_ptr        right,
				oldgaa_cond_bindings_ptr cond_bind)
{
    right->cond_bindings = cond_bind;
    cond_bind->reference_count++;
#ifdef DEBUG
    fprintf(stderr,"oldgaa_bind_rights_to_conditions:rights:%p->cond_bind:%p\n",
	    right, cond_bind);
#endif
}  

static void
oldgaa_bind_rights_to_principal(oldgaa_principals_ptr principal, 
                                oldgaa_rights_ptr     rights)
{
    if (principal->rights)
 oldgaa_add_rights(&(principal->rights), rights);
    else {
	principal->rights = rights;
	rights->reference_count++;
    }
}

#ifdef LDEBUG
#define NN(s) ((s) ? (s) : "")
static void
print_condition_binding(oldgaa_cond_bindings_ptr cb)
{
    oldgaa_conditions_ptr c;
    for (; cb; cb = cb->next) {
	fprintf(stderr, "        condition binding %x\n", cb);
	for (c = cb->condition; c; c = c->next) {
	    fprintf(stderr, "            condition (%s, %s, %s)\n",
		    NN(c->type), NN(c->authority), NN(c->value));
	}
    }
}
static void
print_oldgaa_principal_ptr(oldgaa_principals_ptr pr)
{
    oldgaa_rights_ptr r;
    
    for (; pr; pr = pr->next) {
	fprintf(stderr, "principal (%s, %s, %s): %x\n",
		NN(pr->type), NN(pr->authority), NN(pr->value),
		pr->rights);
	for (r = pr->rights; r; r = r->next) {
	    fprintf(stderr, "    right (%s, %s, %s)\n",
		    NN(r->type), NN(r->authority), NN(r->value));
	    print_condition_binding(r->cond_bindings);
	}
    }
}
#endif /* LDEBUG */
/**********************************************************************
  OLDGAA Cleanup Functions 
**********************************************************************/

oldgaa_error_code
oldgaa_globus_cleanup(oldgaa_sec_context_ptr *oldgaa_sc,
                      oldgaa_rights_ptr      *rights,
                      oldgaa_options_ptr      options,
                      oldgaa_answer_ptr      *answer,  
                      oldgaa_data_ptr         policy_db, 
                      oldgaa_sec_attrb_ptr   *attributes)
{
    oldgaa_error_code oldgaa_status = OLDGAA_SUCCESS;
    uint32         minor_status;
        
    if(oldgaa_sc)    oldgaa_status = oldgaa_release_sec_context(&minor_status, oldgaa_sc); 
    if(rights)    oldgaa_status = oldgaa_release_rights(&minor_status, rights);   
    if(options)   oldgaa_status = oldgaa_release_options(&minor_status, options);  
    if(answer)    oldgaa_status = oldgaa_release_answer(&minor_status, answer);
    if(policy_db) oldgaa_status = oldgaa_release_data(&minor_status, policy_db);
    if(attributes)oldgaa_status = oldgaa_release_sec_attrb(&minor_status, attributes); 

    return oldgaa_status;
}



/**********************************************************************
  OLDGAA Initialization Functions 
**********************************************************************/

oldgaa_error_code
oldgaa_globus_initialize(oldgaa_sec_context_ptr *oldgaa_sc,
                         oldgaa_rights_ptr      *rights,
                         oldgaa_options_ptr     *options,
                         oldgaa_data_ptr        *policy_db, 
                         char                *signer, 
                         char                *subject,
                         char                *path)
{ 
    int error=0;

    /* Allocate and fill in OLDGAA-Globus data structures */

    if(oldgaa_sc) *oldgaa_sc = oldgaa_globus_allocate_sec_context(signer); 
    if(rights) *rights = oldgaa_globus_allocate_rights();
    
    if(options) 
    {
        oldgaa_allocate_options(options);
        (*options)->value  = oldgaa_strcopy(subject, (*options)->value);  
        (*options)->length = strlen(subject); 
    }

    if(policy_db)
    {       
        oldgaa_allocate_data(policy_db);
   
        if(path) (*policy_db)->str = oldgaa_strcopy(path,(*policy_db)->str);
        else
 error = get_default_policy_file(*policy_db);
    }

    if(error)return OLDGAA_FAILURE;
    else
 return OLDGAA_SUCCESS;
}


/**********************************************************************

Function: oldgaa_globus_allocate_sec_context

Description:
	Allocates OLDGAA security context and fills in globus-specific 
        information.

Parameters:
	signer, pointer to string with name of credential signer.

Returns:
	Pointer to a oldgaa_sec_context if successful
**********************************************************************/

oldgaa_sec_context_ptr
oldgaa_globus_allocate_sec_context(char *signer)
{
    oldgaa_sec_context_ptr sc = NULL;
  
    oldgaa_allocate_sec_context(&sc);
  
    if(strcmp(signer, OLDGAA_ANYBODY) == 0) 
    {
        sc->identity_cred->principal->type = oldgaa_strcopy(OLDGAA_ANYBODY, 
                                                            sc->identity_cred->principal->type);

        sc->identity_cred->principal->authority = oldgaa_strcopy(" ",
                                                                 sc->identity_cred->principal->authority);

        sc->identity_cred->principal->value = oldgaa_strcopy(" ", 
                                                             sc->identity_cred->principal->value);
    }
    else
    {
        sc->identity_cred->principal->type = oldgaa_strcopy(OLDGAA_CA, 
                                                            sc->identity_cred->principal->type);
   
        sc->identity_cred->principal->authority = oldgaa_strcopy(OLDGAA_X509_AUTHORITY, 
                                                                 sc->identity_cred->principal->authority);
    
        sc->identity_cred->principal->value = oldgaa_strcopy(signer, 
                                                             sc->identity_cred->principal->value); 
    }

    return sc;
}

/**********************************************************************

Function: oldgaa_globus_allocate_rights() 

Description:
	Allocates OLDGAA rights stracture and fills in globus-specific 
        information..

Parameters:
	none

Returns:
	Pointer to a oldgaa_rights if successful
**********************************************************************/

oldgaa_rights_ptr
oldgaa_globus_allocate_rights()
{
    oldgaa_rights_ptr rights = NULL;

    oldgaa_allocate_rights(&rights);
    rights->reference_count++;
      
    rights->type       = oldgaa_strcopy(POSITIVE_RIGHTS,     rights->type);
    rights->authority  = oldgaa_strcopy(AUTH_GLOBUS,         rights->authority);
    rights->value      = oldgaa_strcopy(GLOBUS_RIGHTS_VALUE, rights->value);

    return rights;

}

/**********************************************************************
  Policy Retrieving Functions 
**********************************************************************/

/**********************************************************************

Function: oldgaa_globus_policy_retrieve() 

Description:
        Upcall function for the retrieval of the object policy.

Parameters:
        object,    pointer to string with name of protected object, 
                   can be NULL
	policy_db, pointer to string with name of policy file

Returns:
	Pointer to a policy_file_context_ptr if successful
	NULL on error, setting errno.

**********************************************************************/

oldgaa_policy_ptr 
oldgaa_globus_policy_retrieve(uint32      *minor_status,
                              oldgaa_data_ptr object,
                              oldgaa_data_ptr policy_db, ...)
{ 
    policy_file_context_ptr   pcontext      = NULL; 
    oldgaa_policy_ptr            policy_handle = NULL;
    int                       error_type    =  1;

#ifdef DEBUG
    fprintf(stderr, "\noldgaa_globus_policy_retrieve:\n");
#endif /* DEBUG */

    *minor_status = 0;

    pcontext = (policy_file_context_ptr)oldgaa_globus_policy_file_open(policy_db->str);

    if (pcontext)  /* parse policy */
    {
        if(oldgaa_globus_parse_policy(pcontext, 
                                      &policy_handle) == OLDGAA_SUCCESS)
        {
#ifdef DEBUG
            {
		oldgaa_principals_ptr pp;
		oldgaa_rights_ptr     rp;
		oldgaa_cond_bindings_ptr bp;
		oldgaa_conditions_ptr    cp;

		pp = policy_handle;
		while (pp) {
                    fprintf(stderr,"principal:%p\n",pp);
                    rp = pp->rights;
                    while(rp) {
                        fprintf(stderr,"   rights:%p ref:%d\n", 
                                rp, rp->reference_count);
                        bp = rp->cond_bindings;
                        while(bp) {
                            fprintf(stderr,"      cond_bindings:%p ref:%d\n",
                                    bp, bp->reference_count);
                            cp = bp->condition;
                            while (cp) {
                                fprintf(stderr,"         condition:%p ref:%d\n",
                                        cp, cp->reference_count);
                                cp = cp->next;
                            }
                            bp = bp->next;
                        }
                        rp = rp->next;
                    }
                    pp = pp->next;
		}
            }
#endif

            return policy_handle;
        }
        else error_type = 0; 
    }

    /* error handling */
 
    if(error_type) /* policy retrieve error */
    {
        policy_db->error_code = ERROR_WHILE_RETRIEVING_POLICY;
        policy_db->error_str  = malloc(strlen("error retrieving file ") +
                                       strlen(policy_db->str) + 1);
        if(policy_db->error_str == NULL)
        {
            out_of_memory();
        }
        sprintf(policy_db->error_str,"error retrieving file %s",policy_db->str);
    }
    else          /* policy parsing error */
    { 
        policy_db->error_code = m_status;
    }
  
    *minor_status = m_status;

    return NULL;
}
 
/**********************************************************************/

static
int
get_default_policy_file(oldgaa_data_ptr policy_db)
{
    char *ca_policy_file_path  = NULL;
    char *cert_dir             = NULL;
    char *ca_policy_filename   = GRID_CA_POLICY_FILENAME;
    int  rc                    = 0;

    cert_dir = getenv("X509_CERT_DIR");

    if (cert_dir)
    {
        ca_policy_file_path = malloc(strlen(cert_dir) +
                                     strlen(ca_policy_filename) +
                                     2 /* for '/' and NUL */);

        if(!ca_policy_file_path) out_of_memory();
    }


    if (ca_policy_file_path)
    {
        sprintf(ca_policy_file_path, "%s/%s", cert_dir, ca_policy_filename);

        policy_db->str = oldgaa_strcopy(ca_policy_file_path, policy_db->str) ;

        free(ca_policy_file_path);
    }
    else
    {    	   
        policy_db->error_str = 
            oldgaa_strcopy("Can not find default policy location. X509_CERT_DIR is not defined.\n",
                           policy_db->error_str);
        policy_db->error_code = ERROR_WHILE_GETTING_DEFAULT_POLICY_LOCATION;

        rc = 1;
    }
 
    return rc; 
}



/**********************************************************************

Function: oldgaa_globus_policy_file_open() 

Description:
	Open the specified policy file for reading, returning a
	context.

Parameters:
	filename, pointer to string with name of policy file

Returns:
	Pointer to a policy_file_context if successful
	NULL on error, setting errno.

**********************************************************************/

policy_file_context_ptr 
oldgaa_globus_policy_file_open(const char *filename)
{
    char *		                open_mode = "r";
    policy_file_context_ptr             pcontext  = NULL;
    FILE *                              stream = NULL;
    int                                 rc;

#ifdef DEBUG
    fprintf(stderr, "\noldgaa_globus_policy_file_open:\n");
#endif /* DEBUG */

    /* Check arguments */
    if (filename == NULL)
    {
        errno = ERRNO_INVALID_ARGUMENT;
        pcontext = NULL;

        goto exit;
    }

    /* allocate and fill in pcontext structure */
    pcontext = malloc(sizeof(*pcontext));
    if (!pcontext) out_of_memory();

    pcontext->parse_error = NULL;
    pcontext->str         = NULL;
    pcontext->index       = 0;

    oldgaa_handle_error(&(pcontext->parse_error),"not defined");
    oldgaa_handle_error(&(pcontext->str),"not defined");

    stream = fopen(filename, open_mode);
    if (stream == NULL)
    {
        goto error_exit;
    }
    rc = fseek(stream, 0, SEEK_END);
    if (rc != 0)
    {
        goto error_exit;
    }

    pcontext->buflen = ftell(stream);

    rc = fseek(stream, 0, SEEK_SET);
    if (rc != 0)
    {
        goto error_exit;
    }

    pcontext->buf = malloc(pcontext->buflen + 1);
    if (!pcontext->buf) out_of_memory();
 
    rc = fread(pcontext->buf, pcontext->buflen, 1, stream);
    pcontext->buf[pcontext->buflen] = 0;

    if (rc != 1)
    {
error_exit:
        free(pcontext);
        pcontext = NULL;
    }

exit:
    if (stream)
    {
        fclose(stream);
    }
    return pcontext;
} /* policy_file_open() */


/**********************************************************************

Function: oldgaa_globus_policy_file_close()

Description:
	Close the policy file and deallocate memory assigned to the
	context.

Parameters:
	pcontext, pointer to the context

Returns:
	Nothing

**********************************************************************/

void
oldgaa_globus_policy_file_close(policy_file_context_ptr  pcontext)
{

#ifdef DEBUG
    fprintf(stderr, "\noldgaa_globus_policy_file_close:\n");
#endif /* DEBUG */

    if (pcontext)
    {
        free(pcontext->buf);
        free(pcontext->str);
        free(pcontext->parse_error);
        free(pcontext);
    }
} 


/**********************************************************************
  Policy Parsing Functions 
**********************************************************************/
/**********************************************************************/

static
int
oldgaa_globus_help_read_string(policy_file_context_ptr  pcontext, 
                               char                    *str, 
                               const char              *message)
{

    if (oldgaa_globus_read_string(pcontext, str, NULL)) return 1;

    if (end_of_file == TRUE) 
    {       
        oldgaa_handle_error(&(pcontext->parse_error), message);
        return 1;         
    }  
     	 
    return 0;
}



/**********************************************************************

Function: oldgaa_globus_read_string

Description:
	Read a string from a given stream up to and including the newline
	and return it in an allocated buffer.

Parameters:
	pcontext, handle to a structure, containing the stream to read from.

	str, pointer to string to be filled in.

	errstring, pointer to the pointer to be filled in with
	a pointer to a string describing an error that occurs.
	May be NULL.

Returns:
        0 on success
        1 on error

**********************************************************************/

static
int
oldgaa_globus_read_string (policy_file_context_ptr  pcontext,
                           char                    *str,
                           char                    **errstring)
{   
    int len;
    int rc;

    if (pcontext->index >= (pcontext->buflen - 1))
    {
        end_of_file = TRUE; 
        return 0; 
    }

    rc = sscanf(pcontext->buf + pcontext->index, "%s%n", str, &len);
    if (rc < 1)
    {
        end_of_file = TRUE;
        return 0;
    }

    pcontext->index += len;

    oldgaa_handle_error(&(pcontext->str),str); /* set the string value to
                                                  report it in the case there is an error */

  
    if (str[0]== STRING_DELIMITER) /* get strings with white spaces */
    {
        if(oldgaa_globus_get_string_with_whitespaces(pcontext, str) == -1)
        {
            oldgaa_handle_error(&(pcontext->parse_error),
                                "error while reading string");      
            return 1;
        }
    }


    if (str[0]== COMMENT) /* omit comment line */
    { 
        if(oldgaa_globus_omit_comment_line(pcontext))
        {
            oldgaa_handle_error(&(pcontext->parse_error),
                                "error while reading string"); 
            return 1;
        }

        if(oldgaa_globus_read_string(pcontext, str, errstring))
        {
      
            oldgaa_handle_error(&(pcontext->parse_error),
                                "error while reading string"); 
            return 1;
        }
    } 
  
    return 0;

}

/**********************************************************************

Function: oldgaa_globus_get_string_with_whitespaces

Description:
	Read a string from a given stream up to it finds STRING_DELIMITER.

Parameters:
	pcontext, handle to a structure, containing the stream to read from.

	str, pointer to string to be filled in.

Returns:
        0 on success
       -1 on error

**********************************************************************/
static
int
oldgaa_globus_get_string_with_whitespaces(policy_file_context_ptr  pcontext,
                                          char                    *str)
{
    int  i=0, j=1, len = strlen(str); /* j=1 because ignore first ' */
    int  chr, esc = 0;

    while(i < pcontext->buflen) /* read chars from the stream 
                                  untill see STRING_DELIMITER */
    {  
        chr = (j<len) ? str[j++] : pcontext->buf[pcontext->index++];

        if(pcontext->index == pcontext->buflen)  
        {     
            end_of_file = TRUE;

            oldgaa_handle_error(&(pcontext->parse_error),
                                "oldgaa_globus_get_string_with_white_spaces: Missing string delimiter \'");
            return -1;
        }        
        if (!esc && chr == STRING_DELIMITER) break; /* don't check if escaped*/
        esc = !esc && (chr == ESCAPE_CHARACTER);    /* !esc takes care of \\ */
        if (!esc) { str[i] = chr; i++; }            /* don't print out the \ */
    }

    if(i >= pcontext->buflen)/* string is too long */
    {
        oldgaa_handle_error(&(pcontext->parse_error),
                            "get_string_with_white_spaces: String is too long");
        return -1;
    }

    str[i] = NUL; /* terminate the string */

    return 0;
}

/**********************************************************************

Function: oldgaa_globus_omit_comment_line

Description:
	omit comment from the stream

Parameters:
	pcontext, handle to a structure, containing the stream to read from.

Returns:
        0 on success
       -1 on error

**********************************************************************/

static
int
oldgaa_globus_omit_comment_line(policy_file_context_ptr  pcontext)
{
    int chr;  
 
    while(pcontext->index < pcontext->buflen)
    {
        chr = pcontext->buf[pcontext->index++];
        if (chr == END_OF_LINE) break;
    }

    if (pcontext->index == pcontext->buflen) end_of_file = TRUE;

    return 0;
}   



/**********************************************************************

Function: oldgaa_globus_parse_policy() 

Description:
        Parses the policy file, filling oldgaa_policy structure. The format of
        the [olicy file is described in ?

Parameters:
        minor_status, mechanism-specific status code
        pcontext, handle to a structure, containing the stream to read from.
        policy_handle, pointer to oldgaa_policy structure to be filled in. 
                   
Returns:
	OLDGAA_SUCCESS or OLDGAA_RETREIVE_ERROR

**********************************************************************/

oldgaa_error_code  
oldgaa_globus_parse_policy (policy_file_context_ptr  pcontext,
                            oldgaa_policy_ptr          *policy_handle)

{
    oldgaa_conditions_ptr    all_conditions   = NULL;
    /*
     *DEE all_conditions is only used in this routine to look for
     * duplicate conditions.
     */
    oldgaa_principals_ptr    start_principals = NULL;
    oldgaa_principals_ptr    added_principal = NULL;
    oldgaa_rights_ptr        start_rights     = NULL;
    oldgaa_cond_bindings_ptr cond_bind        = NULL;
    oldgaa_error_code        oldgaa_error;

    char                  *str;
    int                   cond_present     = FALSE;
    int                   new_entry        = TRUE; 
    oldgaa_rights_ptr old_rights = 0;

    str = malloc(pcontext->buflen);
    str[0] = 0;

    end_of_file    = 0;
    *policy_handle = NULL;

#ifdef DEBUG
    fprintf(stderr, "\noldgaa_globus_parse_policy:\n");
#endif /* DEBUG */
 
    while (!end_of_file)    
    { 
        if (new_entry == TRUE) /* start parsing new entry */
        {
            cond_present = FALSE;
            new_entry    = FALSE;

            /* get principals */
                        
            if(oldgaa_globus_parse_principals(pcontext,
                                              policy_handle,
                                              str,
                                              &start_principals,
                                              &added_principal) != OLDGAA_SUCCESS)
            { 
                oldgaa_handle_error(&(pcontext->parse_error),
                                    "oldgaa_globus_parse_policy: error while parsing principal: ");
                m_status = ERROR_WHILE_PARSING_PRINCIPALS;

                goto err;
            }

        }/* if (new_entry == TRUE) */

        /* continue parsing an entry */

        /* get rights */

        old_rights = start_rights;
        oldgaa_error = oldgaa_globus_parse_rights(pcontext,                              
                                                  str,
                                                  &start_rights,         
                                                  &cond_present,
                                                  &new_entry);
        if(oldgaa_error != OLDGAA_SUCCESS)
        {       
            oldgaa_handle_error(&(pcontext->parse_error),
                                "oldgaa_globus_parse_policy: error while parsing right: ");       
            m_status = ERROR_WHILE_PARSING_RIGHTS;
            goto err;

        }

        /* bind paresed rights for this entry to the paresed principals 
           from this entry */
        oldgaa_bind_rights_to_principal(added_principal, start_rights);
 
        /* get conditions, if any */
  
        if(cond_present == TRUE)
        {
            oldgaa_error = oldgaa_globus_parse_conditions(pcontext,
                                                          &all_conditions,
                                                          str,
                                                          &cond_bind,
                                                          &new_entry);

#ifdef LDEBUG
            if (oldgaa_error == OLDGAA_SUCCESS) {
                fprintf(stderr, "parsed condition_binding\n");
                if (cond_bind)
 print_condition_binding(cond_bind);
            } else
 fprintf(stderr, "didn't parse condition binding\n");
#endif /* LDEBUG */
   
            if (oldgaa_error != OLDGAA_SUCCESS)               
            {
                oldgaa_handle_error(&(pcontext->parse_error),
                                    "oldgaa_globus_parse_policy: error while parsing condition: ");
  
                m_status = ERROR_WHILE_PARSING_CONDITIONS; 
                goto err;

            }
  
            /* bind paresed conditions for this entry to the paresed rights 
               from this entry */

            else  oldgaa_bind_rights_to_condition(start_rights, cond_bind);   
   
        } /* if(cond_present == TRUE) */
  
#ifdef LDEBUG
        printf("start_principals:\n");
        if (start_principals)
 print_oldgaa_principal_ptr(start_principals);
#endif  /* LDEBUG */
 
    }/* end of while */

    /* 
     * Since the conditions are now all bound to cond_bindings, 
     * we can remove the next chain pointers so they don't get
     * in the way during free if there are other chains 
     * using conditions. 
     */

    {
	oldgaa_conditions_ptr   c1p, c2p;

	c1p = all_conditions;
        while(c1p)
        {
            c2p = c1p->next;
            c1p->next = NULL;
            c1p = c2p;
        }
    }
	
    if (pcontext) oldgaa_globus_policy_file_close(pcontext);

#ifdef LDEBUG
    printf("policy_handle:\n");
    if (*policy_handle)
 print_oldgaa_principal_ptr(*policy_handle);
#endif  /* LDEBUG */

    free(str);
    return OLDGAA_SUCCESS;

 err:

    oldgaa_release_principals(&m_status, policy_handle);
    oldgaa_globus_policy_file_close(pcontext);

    free(str);
    return OLDGAA_RETRIEVE_ERROR;
}

/**********************************************************************

Function: oldgaa_globus_parse_principals() 

Description:
        Parses the policy file, filling oldgaa_rincipals structure. 

Parameters:
        pcontext, handle to a structure, containing the stream to read from.
        policy, pointer to oldgaa_policy structure to be filled in. 
        tmp_str, contains a string which will be evaluated and in the end,
               new value is stored here.
        start, stores a pointer to oldgaa_principals structure of the set
        of principals which will be read by this invokation. This is needed
        by the  bind_rights_to_principals function.       
Returns:
       OLDGAA_SUCCESS or OLDGAA_PARSE_ERROR

**********************************************************************/


static oldgaa_error_code
oldgaa_globus_parse_principals(policy_file_context_ptr  pcontext,
                               oldgaa_policy_ptr          *policy,
                               char                    *tmp_str /* IN&OUT */,
                               oldgaa_principals_ptr      *start,
                               oldgaa_principals_ptr    *added_principal)
{
    char                                *str, *type;
    uint32                              minor_status; 
    oldgaa_principals_ptr               principal = NULL;
    oldgaa_error_code                   error_code = OLDGAA_SUCCESS;

    str = malloc(pcontext->buflen);
    if (str == NULL)
    {
        out_of_memory();
        return OLDGAA_RETRIEVE_ERROR;
    }

#ifdef DEBUG
    fprintf(stderr, "\noldgaa_globus_parse principals:\n");
#endif /* DEBUG */

    if (*policy == NULL) /* first principal in the policy file */
    {
        if (oldgaa_globus_help_read_string(pcontext, str,
                    "parse principals: Empty policy"))
        {
            error_code = OLDGAA_RETRIEVE_ERROR;   
            goto free_str;
        }
    }
    else 
    {
        /* get the value of read principal from tmp_str */
        strcpy(str, tmp_str);
    }

    do 
    {   /* get principal's type */

        if (strcmp(str, OLDGAA_ANYBODY) == 0)
        {
            /* do not check for authority and value */  
            type = OLDGAA_ANYBODY;        
        }
        else if(strcmp(str,OLDGAA_USER) == 0)
        {
            type = OLDGAA_USER;
        }
        else if(strcmp(str,OLDGAA_CA) == 0)
        {
            type = OLDGAA_CA;
        }
        else if (strcmp(str,OLDGAA_GROUP) == 0)
        {
            type = OLDGAA_GROUP;
        }
        else if (strcmp(str,OLDGAA_HOST) == 0)
        {
            type = OLDGAA_HOST;
        }
        else if(strcmp(str,OLDGAA_APPLICATION) == 0)
        {
            type = OLDGAA_APPLICATION;
        }
        else 
        {
            oldgaa_handle_error(&(pcontext->parse_error), 
                             "parse_principals: Bad principal type");
            error_code = OLDGAA_RETRIEVE_ERROR;
            goto free_str;
        }
          
        oldgaa_allocate_principals(&principal);

        if (type) 
        {
            principal->type  = oldgaa_strcopy(type, principal->type);
        }
        
        if (strcmp(type, OLDGAA_ANYBODY)== 0)
        {
            /* fill in default values */
            principal->authority = oldgaa_strcopy(" ", principal->authority);
            principal->value     = oldgaa_strcopy(" ", principal->value);
        }
        else
        {
            /* read defyining authority and value from the policy */
            if (oldgaa_globus_help_read_string(pcontext, str,
                                               "parse_principals: Missing principal defining authority"))
            {
                error_code = OLDGAA_RETRIEVE_ERROR;
                goto release_principal;
            }
        
            if (str)
            {
                /* expecting defining authority */
                principal->authority = oldgaa_strcopy(str, principal->authority);     
            }

            if (oldgaa_globus_help_read_string(pcontext, str,
                                               "parse_principals: Missing principals value"))
            {
                error_code = OLDGAA_RETRIEVE_ERROR;
                goto release_principal;
            }
        
            if (str)
            {
                /* expecting value */
                principal->value = oldgaa_strcopy(str, principal->value);
            }
        } /* end of if(type != "access_id_ANYBODY")*/ 

        if (*policy == NULL)
        {
            *policy = principal;
        }

        *added_principal = oldgaa_add_principal(policy, principal); /* add new principal to the list */

        if(*start == NULL) { *start = *added_principal;  }

        /* If the principal is already in the list, we get the previous entry
         * returned from the above. We'll discard this copy of the principal
         */
        if (*added_principal != principal)
        {
            oldgaa_release_principals(&minor_status, &principal);
        }
        /* In either case, the principal is now pointed to by either the 
         * *start list or has been freed, so we don't need it any more
         */
        principal = NULL;

        if (oldgaa_globus_help_read_string(pcontext, str,
                                           "parse_principals: Missing rights"))
        {
            error_code = OLDGAA_RETRIEVE_ERROR;

            goto release_principal;
        }

        strcpy(tmp_str, str); /* return the read string */

        if( !strcmp(str,POSITIVE_RIGHTS) ||
            !strcmp(str,NEGATIVE_RIGHTS) )  /* operation set starts */  
        {
            goto release_principal;
        }

    } while(!end_of_file);
   
release_principal:
    if (principal)
    {
        oldgaa_release_principals(&minor_status, &principal);
    }

free_str:
    free(str);

    return error_code;
}


/**********************************************************************

Function: oldgaa_globus_parse_rights() 

Description:
        Parses the policy file, filling oldgaa_rights structure. 

Parameters:
        pcontext, handle to a structure, containing the stream to read from.
        tmp_str,  contains a string which will be evaluated and in the end,
                  new value is stored here.
        start,    stores a pointer to oldgaa_rights structure of the set
                  of rights which will be read by this invokation. This is needed
                  by the  bind_rights_to_conditions function.
                  cond_present, indicates if condition set starts
        end_of_entry, indicates if new entry starts     
Returns:
       OLDGAA_SUCCESS or OLDGAA_RETRIEVE_ERROR

**********************************************************************/

oldgaa_error_code
oldgaa_globus_parse_rights(
    policy_file_context_ptr             pcontext,
    char                                *tmp_str,
    oldgaa_rights_ptr                   *start,
    int                                 *cond_present,
    int                                 *end_of_entry)
{
    char                                *str;
    int                                 first  = TRUE;
    oldgaa_rights_ptr                   rights = NULL;
    oldgaa_error_code                   error_code = OLDGAA_SUCCESS;
    uint32                              minor_status;
  
    str = malloc(pcontext->buflen);
    if (str == NULL)
    {
        error_code = OLDGAA_RETRIEVE_ERROR;

        goto out;
    }

#ifdef DEBUG
    fprintf(stderr, "\noldgaa_globus_parse rights:\n");
#endif /* DEBUG */

    strcpy(str, tmp_str); 

    do {
        if ((oldgaa_strings_match(str,POSITIVE_RIGHTS) ||
             oldgaa_strings_match(str,NEGATIVE_RIGHTS))== FALSE) 
        {
            /* expecting operation set starts */
            error_code = OLDGAA_RETRIEVE_ERROR;
            oldgaa_handle_error(&(pcontext->parse_error), "Bad right type");

            goto free_str;
	}
  
        /* allocate fill in the oldgaa_rights structure */
        oldgaa_allocate_rights(&rights);
        if (str)
        {
            rights->type = oldgaa_strcopy(str, rights->type);
        }
      
        if (oldgaa_globus_help_read_string(pcontext, str,
                                           "parse_rights: Missing right authority"))
        {
            error_code = OLDGAA_RETRIEVE_ERROR;  
            goto free_rights;
        }
 
        if (str)
        {
            /* expecting defining authority */ 
            rights->authority = oldgaa_strcopy(str, rights->authority);
        }
     
        if (oldgaa_globus_help_read_string(pcontext, str,
                                          "parse_rights: Missing right value"))
        {
            error_code = OLDGAA_RETRIEVE_ERROR;  
            goto free_rights;
        }
  
        if (str)
        {
            /* expecting value */      
            rights->value = oldgaa_strcopy(str, rights->value);
        }
       
        if(first == TRUE) { *start = rights; first = FALSE; } 
        else oldgaa_add_rights(start, rights);

        rights = NULL;

        if (oldgaa_globus_read_string(pcontext, str, NULL))     
        {
            error_code = OLDGAA_RETRIEVE_ERROR;
            goto free_str;
        }
      
        strcpy(tmp_str, str); /* return the read string */
       
        if (!strncmp(str,COND_PREFIX, 5))  /* condition set starts */
        {
            *cond_present = TRUE;
            goto free_str;
        }
   
        if(!strncmp(str,PRINCIPAL_ACCESS_PREFIX, 6) ||
           !strncmp(str,PRINCIPAL_GRANTOR_PREFIX, 7))  /* new entry starts */        
        {
            *end_of_entry = TRUE;      

            goto free_str;
        }     

    } while(!end_of_file);

free_rights:
    if (rights != NULL)
    {
        oldgaa_release_rights(&minor_status, &rights);
    }

free_str:
    free(str);

out:
    return error_code;
}


/**********************************************************************
Function: oldgaa_globus_parse_conditions() 

Description:
        Parses the policy file, filling oldgaa_conditions structure. 

Parameters:
        pcontext,   handle to a structure, containing the stream to read from.
        conditions, pointer to oldgaa_conditions structure to be filled in. 
        tmp_str,    contains a string which will be evaluated and in the end,
                    new value is stored here.
        list,       stores a pointer to oldgaa_cond_bindings structure of the set
                    of conditions which will be read by this invokation. 
                    This is needed by the bind_rights_to_conditions function.
        end_of_entry, indicates if new entry starts     
Returns:
       OLDGAA_SUCCESS or OLDGAA_RETRIEVE_ERROR


**********************************************************************/

oldgaa_error_code
oldgaa_globus_parse_conditions(
    policy_file_context_ptr             pcontext,
    oldgaa_conditions_ptr               *conditions,                  
    char                                *tmp_str,
    oldgaa_cond_bindings_ptr            *list,
    int                                 *end_of_entry)
{
    char *                              str;
    int                                 first = TRUE;
    oldgaa_conditions_ptr               cond = NULL;
    oldgaa_cond_bindings_ptr            cond_bind;
    uint32                              inv_minor_status = 0;
    oldgaa_error_code                   error_code = OLDGAA_SUCCESS;

    str = malloc(pcontext->buflen);
    if (str == NULL)
    {
        out_of_memory();
        return OLDGAA_RETRIEVE_ERROR;
    }

#ifdef DEBUG
    fprintf(stderr, "\noldgaa_globus_parse conditions:\n");
#endif /* DEBUG */

    strcpy(str, tmp_str); 
  
    do
    {
        if(strncmp(str,"cond_", 5) != 0)/* expecting condition set starts */
        {
            oldgaa_handle_error(&(pcontext->parse_error),"Bad condition type");
            error_code = OLDGAA_RETRIEVE_ERROR;

            goto free_str;
        }

        /* allocate fill in the oldgaa_conditions structure */
        oldgaa_allocate_conditions(&cond);
        if (str) 
        {
            cond->type = oldgaa_strcopy(str,cond->type) ;
        }
    
        if (oldgaa_globus_help_read_string(pcontext, str,
                                           "parse_conditions: Missing condition authority"))
        {
            error_code = OLDGAA_RETRIEVE_ERROR;
            goto release_conditions;
        }

        if (str)
        {
            cond->authority = oldgaa_strcopy(str, cond->authority);
        }
   
        if (oldgaa_globus_help_read_string(pcontext, str,
                                           "parse_conditions: Missing condition value"))
        {
            error_code = OLDGAA_RETRIEVE_ERROR;
            goto release_conditions;
        }

        if (str)
        {
            cond->value = oldgaa_strcopy(str, cond->value);
        }
    
        oldgaa_allocate_cond_bindings(&cond_bind);

        if(*conditions == NULL) { *conditions = cond; }
        cond_bind->condition = oldgaa_add_condition(conditions, cond);
        cond_bind->condition->reference_count++;
#ifdef DEBUG
        fprintf(stderr,"binding cond_bind:%p->conditions:%p\n",
                cond_bind, cond_bind->condition);
#endif
        /* If we don't add it to the list, then we need to free it! */
        if (cond_bind->condition != cond)
        {
#ifdef DEBUG
            fprintf(stderr,"Duplicate conditions, free:%p\n",cond);
#endif
            cond->reference_count++; /* keep all the ducks in a row */
            oldgaa_release_conditions(&inv_minor_status, &cond);
        }
        cond = NULL;

        if(first == TRUE){ *list = cond_bind; first = FALSE; } 
        else  oldgaa_add_cond_binding(list, cond_bind);
 
        if (oldgaa_globus_read_string(pcontext, str, NULL))    
        {
            error_code = OLDGAA_RETRIEVE_ERROR;
            goto release_conditions;
        }
      
        if(end_of_file == TRUE)
        {
            goto release_conditions;
        }
    
        strcpy(tmp_str, str); /* return the read string */

        if(!strncmp(str,PRINCIPAL_ACCESS_PREFIX, 6) ||
           !strncmp(str,PRINCIPAL_GRANTOR_PREFIX, 7))  /* new entry starts */        
        {
            *end_of_entry = TRUE;      

            goto release_conditions;
        }  

        if(!strncmp(str,POS_RIGHTS_PREFIX, 3) ||
           !strncmp(str,NEG_RIGHTS_PREFIX, 3)) /* new rights set starts */
        {
            goto release_conditions;
        }
    } while (!end_of_file);

release_conditions:
    if (cond != NULL)
    {
        oldgaa_release_conditions(&inv_minor_status, &cond);
    }
free_str:
    free(str);
    return error_code;
}


/*****************************************************************************/
  
void
oldgaa_globus_print_rights(oldgaa_rights_ptr rights)
{
    oldgaa_rights_ptr        ptr = rights;
    oldgaa_cond_bindings_ptr cond;

    while(ptr != NULL)
    {  
        fprintf(stderr, "ACCESS RIGHT\n");
        fprintf(stderr, "type      : %s\n",   ptr->type);   
        fprintf(stderr, "authority : %s\n",   ptr->authority);
        fprintf(stderr, "value     : %s\n\n", ptr->value);

        cond = ptr->cond_bindings; 

        while(cond != NULL)
        {
            fprintf(stderr, "CONDITION\n");
            fprintf(stderr, "type      : %s\n",     cond->condition->type);   
            fprintf(stderr, "authority : %s\n",     cond->condition->authority);
            fprintf(stderr, "value     : %s\n",     cond->condition->value);
            fprintf(stderr, "status    : %08x\n\n", cond->condition->status);

            cond = cond->next;
        }

        ptr = ptr->next;
    }

}

/**********************************************************************/
void
oldgaa_globus_print_attributes(oldgaa_sec_attrb_ptr attributes)
{
    oldgaa_sec_attrb_ptr        ptr = attributes;


    while(ptr != NULL)
    {  
        fprintf(stderr, "ATTRIBUTE\n");
        fprintf(stderr, "type      : %s\n",   ptr->type);   
        fprintf(stderr, "authority : %s\n",   ptr->authority);
        fprintf(stderr, "value     : %s\n\n", ptr->value);

        ptr = ptr->next; 
    }
}

/**********************************************************************/

oldgaa_error_code
oldgaa_globus_get_trusted_ca_list(oldgaa_sec_attrb_ptr *attributes,
                                  oldgaa_policy_ptr     policy_handle,
                                  oldgaa_rights_ptr     rights)
{
    oldgaa_error_code     oldgaa_status    = OLDGAA_SUCCESS;
    uint32             minor_status  = 0;
    oldgaa_principals_ptr principal= NULL;     
   
#ifdef DEBUG
    fprintf(stderr, "\noldgaa_globus_get_trusted_ca_list:\n");
#endif /* DEBUG */


    oldgaa_allocate_principals(&principal);
    principal->type      = oldgaa_strcopy(OLDGAA_CA,             principal->type);   
    principal->authority = oldgaa_strcopy(OLDGAA_X509_AUTHORITY, principal->authority);
    /* principal->value     = oldgaa_strcopy("\"*\"",            principal->value); */

    oldgaa_status = oldgaa_get_authorized_principals(attributes, 
                                                     policy_handle,
                                                     principal, 
                                                     rights);

    oldgaa_status = oldgaa_release_principals(&minor_status, &principal);

    return oldgaa_status;   

}


/**********************************************************************/