File: srmv2_dirreq.c

package info (click to toggle)
dpm-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,788 kB
  • ctags: 10,782
  • sloc: ansic: 146,136; sh: 13,362; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 955; fortran: 113
file content (730 lines) | stat: -rw-r--r-- 25,281 bytes parent folder | download | duplicates (5)
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
/*
 * Copyright (C) 2004-2008 by CERN
 * All rights reserved
 */

#ifndef lint
static char sccsid[] = "@(#)$RCSfile: srmv2_dirreq.c,v $ $Revision: 1.25 $ $Date: 2009/08/27 13:04:10 $ CERN Jean-Philippe Baud";
#endif /* not lint */

#include <sys/stat.h>
#include "Cgrp.h"
#include "Cnetdb.h"
#include "Cpwd.h"
#include "dpm.h"
#include "dpm_api.h"
#include "dpm_server.h"
#include "dpm_util.h"
#include "dpns_api.h"
#include "serrno.h"
#include "srm_server.h"
#include "srmv2H.h"
static int na_key = -1;

/*			Directory Functions				*/

int
ns1__srmMkdir (struct soap *soap, struct ns1__srmMkdirRequest *req, struct ns1__srmMkdirResponse_ *rep)
{
	char clientdn[256];
	const char *clienthost;
	char **fqan;
	char func[16];
	gid_t gid;
	gid_t *gids;
	char logbuf[CA_MAXSFNLEN+7];
	int nbfqans;
	int nbgids;
	struct ns1__srmMkdirResponse *repp;
	char *sfn;
	struct srm_srv_thread_info *thip = soap->user;
	uid_t uid;
	char *voname;

	strcpy (func, "Mkdir");
	get_client_dn (soap, clientdn, sizeof(clientdn));
	clienthost = Cgetnetaddress (-1, &soap->peer, soap->peerlen, &na_key, NULL, NULL, 0, 0);
	if (!clienthost) clienthost = "(unknown)";
	srmlogit (func, "request by %s from %s\n", clientdn, clienthost);
	if (! req) {
		soap_sender_fault (soap, "NULL request", NULL);
		RETURN (SOAP_FAULT);
	}

	/* Allocate response structure */

	if ((repp = soap_malloc (soap, sizeof(struct ns1__srmMkdirResponse))) == NULL ||
	    (repp->returnStatus = soap_malloc (soap, sizeof(struct ns1__TReturnStatus))) == NULL) {
		RETURN (SOAP_EOM);
	}
	repp->returnStatus->explanation = NULL;
	rep->srmMkdirResponse = repp;

	if (get_client_full_id (soap, clientdn, &voname, &fqan, &nbfqans, &uid, &gid, &nbgids, &gids) < 0) {
		repp->returnStatus->statusCode = SRM_USCOREAUTHENTICATION_USCOREFAILURE;
		repp->returnStatus->explanation = soap_strdup (soap, "Could not get user mapping");
		RETURN (SOAP_OK);
	}

	if (! req->directoryPath || ! req->directoryPath->SURLOrStFN ||
	    ! req->directoryPath->SURLOrStFN->value) {
		repp->returnStatus->statusCode = SRM_USCOREFAILURE;
		repp->returnStatus->explanation = soap_strdup (soap, "directoryPath is required");
		RETURN (SOAP_OK);
	}
	if (strlen (req->directoryPath->SURLOrStFN->value) > CA_MAXSFNLEN ||
	    (sfn = sfnfromsurl (req->directoryPath->SURLOrStFN->value)) == NULL) {
		repp->returnStatus->statusCode = SRM_USCOREINVALID_USCOREPATH;
		RETURN (SOAP_OK);
	}
	sprintf (logbuf, "Mkdir %s", req->directoryPath->SURLOrStFN->value);
	srm_logreq (func, logbuf);

	Cns_seterrbuf (thip->errbuf, sizeof(thip->errbuf));
	Cns_client_setAuthorizationId (uid, gid, "GSI", clientdn);
	if (voname && fqan)
		Cns_client_setVOMS_data (voname, fqan, nbfqans);

	if (Cns_mkdir (sfn, 0775) < 0) {
		repp->returnStatus->explanation = soap_strdup (soap, sstrerror (serrno));
		repp->returnStatus->statusCode = serrno2statuscode (serrno);
	} else
		repp->returnStatus->statusCode = SRM_USCORESUCCESS;
	RETURN (SOAP_OK);
}

int
ns1__srmRmdir (struct soap *soap, struct ns1__srmRmdirRequest *req, struct ns1__srmRmdirResponse_ *rep)
{
	char clientdn[256];
	const char *clienthost;
	char **fqan;
	char func[16];
	gid_t gid;
	gid_t *gids;
	char logbuf[CA_MAXSFNLEN+7];
	int nbfqans;
	int nbgids;
	struct ns1__srmRmdirResponse *repp;
	char *sfn;
	struct srm_srv_thread_info *thip = soap->user;
	uid_t uid;
	char *voname;

	strcpy (func, "Rmdir");
	get_client_dn (soap, clientdn, sizeof(clientdn));
	clienthost = Cgetnetaddress (-1, &soap->peer, soap->peerlen, &na_key, NULL, NULL, 0, 0);
	if (!clienthost) clienthost = "(unknown)";
	srmlogit (func, "request by %s from %s\n", clientdn, clienthost);
	if (! req) {
		soap_sender_fault (soap, "NULL request", NULL);
		RETURN (SOAP_FAULT);
	}

	/* Allocate response structure */

	if ((repp = soap_malloc (soap, sizeof(struct ns1__srmRmdirResponse))) == NULL ||
	    (repp->returnStatus = soap_malloc (soap, sizeof(struct ns1__TReturnStatus))) == NULL) {
		RETURN (SOAP_EOM);
	}
	repp->returnStatus->explanation = NULL;
	rep->srmRmdirResponse = repp;

	if (get_client_full_id (soap, clientdn, &voname, &fqan, &nbfqans, &uid, &gid, &nbgids, &gids) < 0) {
		repp->returnStatus->statusCode = SRM_USCOREAUTHENTICATION_USCOREFAILURE;
		repp->returnStatus->explanation = soap_strdup (soap, "Could not get user mapping");
		RETURN (SOAP_OK);
	}

	if (! req->directoryPath || ! req->directoryPath->SURLOrStFN ||
	    ! req->directoryPath->SURLOrStFN->value) {
		repp->returnStatus->statusCode = SRM_USCOREFAILURE;
		repp->returnStatus->explanation = soap_strdup (soap, "directoryPath is required");
		RETURN (SOAP_OK);
	}
	if (strlen (req->directoryPath->SURLOrStFN->value) > CA_MAXSFNLEN ||
	    (sfn = sfnfromsurl (req->directoryPath->SURLOrStFN->value)) == NULL) {
		repp->returnStatus->statusCode = SRM_USCOREINVALID_USCOREPATH;
		RETURN (SOAP_OK);
	}
	if (req->recursive && *req->recursive == true_) {
		repp->returnStatus->statusCode = SRM_USCORENOT_USCORESUPPORTED;
		repp->returnStatus->explanation = soap_strdup (soap, "recursive option is not supported");
		RETURN (SOAP_OK);
	}
	sprintf (logbuf, "Rmdir %s", req->directoryPath->SURLOrStFN->value);
	srm_logreq (func, logbuf);

	Cns_seterrbuf (thip->errbuf, sizeof(thip->errbuf));
	Cns_client_setAuthorizationId (uid, gid, "GSI", clientdn);
	if (voname && fqan)
		Cns_client_setVOMS_data (voname, fqan, nbfqans);

	if (Cns_rmdir (sfn) < 0) {
		repp->returnStatus->explanation = soap_strdup (soap, sstrerror (serrno));
		if (serrno == EEXIST)
			repp->returnStatus->statusCode = SRM_USCORENON_USCOREEMPTY_USCOREDIRECTORY;
		else
			repp->returnStatus->statusCode = serrno2statuscode (serrno);
	} else
		repp->returnStatus->statusCode = SRM_USCORESUCCESS;
	RETURN (SOAP_OK);
}

int
ns1__srmRm (struct soap *soap, struct ns1__srmRmRequest *req, struct ns1__srmRmResponse_ *rep)
{
	char clientdn[256];
	const char *clienthost;
	struct dpm_filestatus *filestatuses = NULL;
	char **fqan;
	char func[16];
	gid_t gid;
	gid_t *gids;
	int i;
	int j;
	int nbfqans;
	int nbgids;
	int nbreplies = 0;
	int nbsurls;
	struct ns1__TSURLReturnStatus *repfilep;
	struct ns1__srmRmResponse *repp;
	char **surls = NULL;
	struct srm_srv_thread_info *thip = soap->user;
	uid_t uid;
	char *voname;

	strcpy (func, "Rm");
	get_client_dn (soap, clientdn, sizeof(clientdn));
	clienthost = Cgetnetaddress (-1, &soap->peer, soap->peerlen, &na_key, NULL, NULL, 0, 0);
	if (!clienthost) clienthost = "(unknown)";
	srmlogit (func, "request by %s from %s\n", clientdn, clienthost);
	if (! req) {
		soap_sender_fault (soap, "NULL request", NULL);
		RETURN (SOAP_FAULT);
	}

	/* Allocate response structure */

	if ((repp = soap_malloc (soap, sizeof(struct ns1__srmRmResponse))) == NULL ||
	    (repp->returnStatus = soap_malloc (soap, sizeof(struct ns1__TReturnStatus))) == NULL) {
		RETURN (SOAP_EOM);
	}
	repp->returnStatus->explanation = NULL;
	repp->arrayOfFileStatuses = NULL;
	rep->srmRmResponse = repp;

	if (get_client_full_id (soap, clientdn, &voname, &fqan, &nbfqans, &uid, &gid, &nbgids, &gids) < 0) {
		repp->returnStatus->statusCode = SRM_USCOREAUTHENTICATION_USCOREFAILURE;
		repp->returnStatus->explanation = soap_strdup (soap, "Could not get user mapping");
		RETURN (SOAP_OK);
	}

	if (! req->arrayOfFilePaths) {
		repp->returnStatus->statusCode = SRM_USCOREFAILURE;
		repp->returnStatus->explanation = soap_strdup (soap, "arrayOfFilePaths is required");
		RETURN (SOAP_OK);
	}
	nbsurls = req->arrayOfFilePaths->__sizesurlInfoArray;

	/* Allocate the array of file statuses */

	if ((repp->arrayOfFileStatuses =
	    soap_malloc (soap, sizeof(struct ns1__ArrayOfTSURLReturnStatus))) == NULL ||
	    (repp->arrayOfFileStatuses->surlReturnStatusArray =
	    soap_malloc (soap, nbsurls * sizeof(struct ns1__TSURLReturnStatus *))) == NULL ||
	    (surls = soap_malloc (soap, nbsurls * sizeof (char *))) == NULL) {
		RETURN (SOAP_EOM);
	}
	repp->arrayOfFileStatuses->__sizesurlReturnStatusArray = nbsurls;

	j = 0;
	for (i = 0; i < nbsurls; i++) {
		surls[j] = req->arrayOfFilePaths->surlInfoArray[i]->SURLOrStFN->value;
		if ((repp->arrayOfFileStatuses->surlReturnStatusArray[i] =
		    soap_malloc (soap, sizeof(struct ns1__TSURLReturnStatus))) == NULL ||
		    (repp->arrayOfFileStatuses->surlReturnStatusArray[i]->status =
		    soap_malloc (soap, sizeof(struct ns1__TReturnStatus))) == NULL)
			RETURN (SOAP_EOM);
		if (surls[j]) j++;
	}

	if (j > 0) {
		dpm_seterrbuf (thip->errbuf, sizeof(thip->errbuf));
		thip->errbuf[0] = '\0';
		dpm_client_setAuthorizationId (uid, gid, "GSI", clientdn);
		if (voname && fqan)
			dpm_client_setVOMS_data (voname, fqan, nbfqans);

		if (dpm_rm (j, surls, &nbreplies, &filestatuses) < 0 && ! filestatuses) {
			repp->arrayOfFileStatuses = NULL;
			repp->returnStatus->statusCode = serrno2statuscode (serrno);
			if (*thip->errbuf) {
				thip->errbuf[strlen(thip->errbuf)-1] = '\0';
				repp->returnStatus->explanation = soap_strdup (soap, thip->errbuf);
			}
			RETURN (SOAP_OK);
		}
	}

	/* Copy the status (and error string) for each file */

	for (i = 0; i < req->arrayOfFilePaths->__sizesurlInfoArray; i++) {
		repfilep = repp->arrayOfFileStatuses->surlReturnStatusArray[i];
		repfilep->surl = req->arrayOfFilePaths->surlInfoArray[i]->SURLOrStFN;
		if (! req->arrayOfFilePaths->surlInfoArray[i]->SURLOrStFN->value) {
			repfilep->status->statusCode = SRM_USCOREINVALID_USCOREPATH;
			repfilep->status->explanation =
				soap_strdup (soap, "Pointer to SURL is NULL");
			continue;
		}
		if ((filestatuses+i)->surl)
			free ((filestatuses+i)->surl);
		repfilep->status->statusCode =
			dpmstatus2statuscode ((filestatuses+i)->status, 0, 0);
		if ((filestatuses+i)->errstring) {
			repfilep->status->explanation =
				soap_strdup (soap, (filestatuses+i)->errstring);
			free ((filestatuses+i)->errstring);
		} else
			repfilep->status->explanation = NULL;
	}
	free (filestatuses);
	repp->returnStatus->statusCode = j ? SRM_USCORESUCCESS : SRM_USCOREFAILURE;
	RETURN (SOAP_OK);
}

char *
decode_group(gid_t gid, gid_t *sav_gid, char *sav_gidstr)
{
	struct group *gr;

	if (gid != *sav_gid) {
#ifdef VIRTUAL_ID
		if (gid == 0)
			return ("root");
		*sav_gid = gid;
		if (Cns_getgrpbygid (*sav_gid, sav_gidstr) < 0)
#else
		*sav_gid = gid;
		if (gr = getgrgid (*sav_gid))
			strcpy (sav_gidstr, gr->gr_name);
		else
#endif
			return (NULL);
	}
	return (sav_gidstr);
}

char *
decode_user(uid_t uid, uid_t *sav_uid, char *sav_uidstr)
{
	struct passwd *pw;

	if (uid != *sav_uid) {
#ifdef VIRTUAL_ID
		if (uid == 0)
			return ("root");
		*sav_uid = uid;
		if (Cns_getusrbyuid (*sav_uid, sav_uidstr) < 0)
#else
		*sav_uid = uid;
		if (pw = getpwuid (*sav_uid))
			strcpy (sav_uidstr, pw->pw_name);
		else
#endif
			return (NULL);
	}
	return (sav_uidstr);
}

listdir (struct soap *soap, char *dir, int nbfiles, int fflag, int nblevels, int level, struct ns1__TMetaDataPathDetail *repfilep, gid_t *sav_gid, char *sav_gidstr, uid_t *sav_uid, char *sav_uidstr)
{
	Cns_DIR *dirp;
	struct Cns_direnstatg *dxp;
	int i = 0;
	char path[CA_MAXPATHLEN+1];

	if ((repfilep->subPaths =
	    soap_malloc (soap, sizeof(struct ns1__ArrayOfTMetaDataPathDetail))) == NULL ||
	    (nbfiles > 0 && (repfilep->subPaths->pathDetailArray =
	    soap_malloc (soap, nbfiles * sizeof(struct ns1__TMetaDataPathDetail *))) == NULL))
		return (-2);
	if ((dirp = Cns_opendir (dir)) == NULL) {
		repfilep->subPaths = NULL;
		return (-1);
	}
	while ((dxp = Cns_readdirg (dirp)) != NULL) {
		if (i > nbfiles) break;
		if ((repfilep->subPaths->pathDetailArray[i] =
		    soap_malloc (soap, sizeof(struct ns1__TMetaDataPathDetail))) == NULL)
			return (-2);
		sprintf (path, "%s/%s", dir, dxp->d_name);
		listentry (soap, path, dxp, fflag,
		    nblevels, level, repfilep->subPaths->pathDetailArray[i++],
		    sav_gid, sav_gidstr, sav_uid, sav_uidstr);
	}
	(void) Cns_closedir (dirp);
	repfilep->subPaths->__sizepathDetailArray = i;
	return (0);
}

listentry (struct soap *soap, char *path, struct Cns_filestatg *statbuf, int fflag, int nblevels, int level, struct ns1__TMetaDataPathDetail *repfilep, gid_t *sav_gid, char *sav_gidstr, uid_t *sav_uid, char *sav_uidstr)
{
	struct Cns_acl acl[CA_MAXACLENTRIES];
	struct Cns_acl *aclp;
	static enum ns1__TFileType ftypes[] = {File, Directory, Link};
	char *gr_name;
	int ig;
	int iu;
	int j;
	int nbfiles;
	int nentries;
	int ng;
	int nu;
	char *pw_name;
	char *sfn;
	struct Cns_filestatg st;

	memset (repfilep, 0, sizeof(struct ns1__TMetaDataPathDetail));
	if ((repfilep->status =
	    soap_malloc (soap, sizeof(struct ns1__TReturnStatus))) == NULL)
		return (-2);
	memset (repfilep->status, 0, sizeof(struct ns1__TReturnStatus));
	if (! statbuf) {
		if (! path) {
			repfilep->status->statusCode = SRM_USCOREINVALID_USCOREPATH;
			repfilep->status->explanation = soap_strdup (soap, "Pointer to SURL is NULL");
			return (-1);
		}
		if (strlen (path) >= CA_MAXSFNLEN ||
		    (sfn = sfnfromsurl (path)) == NULL) {
			repfilep->status->statusCode = SRM_USCOREINVALID_USCOREPATH;
			return (-1);
		}
		repfilep->path = sfn;
		if (Cns_statg (sfn, NULL, &st) < 0) {
			repfilep->status->explanation = soap_strdup (soap, sstrerror (serrno));
			repfilep->status->statusCode = serrno2statuscode (serrno);
			return (-1);
		}
	} else {
		if ((repfilep->path = soap_strdup (soap, path)) == NULL)
			return (-2);
		memcpy (&st, statbuf, sizeof(struct Cns_filestatg));
	}
	if ((repfilep->size =
	    soap_malloc (soap, sizeof(struct ns1__TSizeInBytes))))
		repfilep->size->value = (st.filemode & S_IFDIR) ? 0 : st.filesize;
	if (st.filemode & S_IFDIR)
		repfilep->type = &ftypes[Directory];
	else if ((st.filemode & S_IFLNK) == S_IFLNK)
		repfilep->type = &ftypes[Link];
	else
		repfilep->type = &ftypes[File];
	if (fflag == 0)
		goto end_entry;
	if ((repfilep->ownerPermission =
	    soap_malloc (soap, sizeof(struct ns1__TOwnerPermission))))
		repfilep->ownerPermission->mode = (st.filemode >> 6) & 7;
	if ((nentries = Cns_getacl (repfilep->path, CA_MAXACLENTRIES, acl)) > 3) {
		ng = 0;
		nu = 0;
		for (j = 0, aclp = acl; j < nentries; j++, aclp++) {
			if (aclp->a_type == CNS_ACL_USER) nu++;
			if (aclp->a_type == CNS_ACL_GROUP_OBJ) ng++;
			if (aclp->a_type == CNS_ACL_GROUP) ng++;
		}
		if (nu == 0 || (repfilep->userPermissions =
		      soap_malloc (soap, sizeof(struct ns1__ArrayOfTUserPermission))) == NULL ||
		    (repfilep->userPermissions->userPermissionArray =
		      soap_malloc (soap, nu * sizeof(struct ns1__TUserPermission *))) == NULL)
			repfilep->userPermissions = NULL;
		if ((repfilep->groupPermissions =
		      soap_malloc (soap, sizeof(struct ns1__ArrayOfTGroupPermission))) == NULL ||
		    (repfilep->groupPermissions->groupPermissionArray =
		      soap_malloc (soap, ng * sizeof(struct ns1__TGroupPermission *))) == NULL)
			repfilep->groupPermissions = NULL;
		ig = 0;
		iu = 0;
		for (j = 0, aclp = acl; j < nentries; j++, aclp++) {
			if (aclp->a_type == CNS_ACL_USER &&
			    (pw_name = decode_user (aclp->a_id, sav_uid, sav_uidstr)) &&
			    repfilep->userPermissions &&
			    (repfilep->userPermissions->userPermissionArray[iu] =
			      soap_malloc (soap, sizeof(struct ns1__TUserPermission))) &&
			    (repfilep->userPermissions->userPermissionArray[iu]->userID =
			      soap_malloc (soap, sizeof(struct ns1__TUserID))) &&
			    (repfilep->userPermissions->userPermissionArray[iu]->userID->value =
			      soap_strdup (soap, pw_name)))
				repfilep->userPermissions->userPermissionArray[iu++]->mode = aclp->a_perm;
			if ((aclp->a_type == CNS_ACL_GROUP_OBJ ||
			    aclp->a_type == CNS_ACL_GROUP) &&
			    (gr_name = decode_group (aclp->a_id, sav_gid, sav_gidstr)) &&
			    repfilep->groupPermissions &&
			    (repfilep->groupPermissions->groupPermissionArray[ig] =
			      soap_malloc (soap, sizeof(struct ns1__TGroupPermission))) &&
			    (repfilep->groupPermissions->groupPermissionArray[ig]->groupID =
			      soap_malloc (soap, sizeof(struct ns1__TGroupID))) &&
			    (repfilep->groupPermissions->groupPermissionArray[ig]->groupID->value =
			      soap_strdup (soap, gr_name)))
				repfilep->groupPermissions->groupPermissionArray[ig++]->mode = aclp->a_perm;
		}
		if (iu)
			repfilep->userPermissions->__sizeuserPermissionArray = iu;
		else
			repfilep->userPermissions = NULL;
		if (ig)
			repfilep->groupPermissions->__sizegroupPermissionArray = ig;
		else
			repfilep->groupPermissions = NULL;
	} else {
		if ((gr_name = decode_group (st.gid, sav_gid, sav_gidstr)) &&
		    (repfilep->groupPermissions =
		      soap_malloc (soap, sizeof(struct ns1__ArrayOfTGroupPermission))) &&
		    (repfilep->groupPermissions->groupPermissionArray =
		      soap_malloc (soap, sizeof(struct ns1__TGroupPermission *))) &&
		    (repfilep->groupPermissions->groupPermissionArray[0] =
		      soap_malloc (soap, sizeof(struct ns1__TGroupPermission))) &&
		    (repfilep->groupPermissions->groupPermissionArray[0]->groupID =
		      soap_malloc (soap, sizeof(struct ns1__TGroupID))) &&
		    (repfilep->groupPermissions->groupPermissionArray[0]->groupID->value =
		      soap_strdup (soap, gr_name))) {
			repfilep->groupPermissions->groupPermissionArray[0]->mode = (st.filemode >> 3) & 7;
			repfilep->groupPermissions->__sizegroupPermissionArray = 1;
		} else
			repfilep->groupPermissions = NULL;
	}
	if ((repfilep->otherPermission =
	    soap_malloc (soap, sizeof(struct ns1__TOtherPermission))))
		repfilep->otherPermission->mode = st.filemode & 7;
	if ((repfilep->createdAtTime =
	    soap_malloc (soap, sizeof(struct ns1__TGMTTime)))) {
		if ((repfilep->createdAtTime->value =
		    soap_strdup (soap, soap_dateTime2s (soap, st.ctime))) == NULL)
			repfilep->createdAtTime = NULL;
	}
	if ((repfilep->lastModificationTime =
	    soap_malloc (soap, sizeof(struct ns1__TGMTTime)))) {
		if ((repfilep->lastModificationTime->value =
		    soap_strdup (soap, soap_dateTime2s (soap, st.mtime))) == NULL)
			repfilep->lastModificationTime = NULL;
	}
	if ((pw_name = decode_user (st.uid, sav_uid, sav_uidstr)) &&
	    (repfilep->owner =
	    soap_malloc (soap, sizeof(struct ns1__TUserID)))) {
		if ((repfilep->owner->value =
		    soap_strdup (soap, pw_name)) == NULL)
			repfilep->owner = NULL;
	}
	if (*st.csumtype &&
	    (repfilep->checkSumType =
	    soap_malloc (soap, sizeof(struct ns1__TCheckSumType)))) {
		if ((repfilep->checkSumType->value =
		    soap_strdup (soap, csumtype2srmname (st.csumtype))) == NULL)
			repfilep->checkSumType = NULL;
	}
	if (*st.csumvalue &&
	    (repfilep->checkSumValue =
	    soap_malloc (soap, sizeof(struct ns1__TCheckSumValue)))) {
		if ((repfilep->checkSumValue->value =
		    soap_strdup (soap, st.csumvalue)) == NULL)
			repfilep->checkSumValue = NULL;
	}
end_entry:
	if ((st.filemode & S_IFDIR) == 0 || level >= nblevels || st.nlink == 0)
		return (0);
	return (listdir (soap, repfilep->path, st.nlink, fflag, nblevels, level + 1, repfilep,
	    sav_gid, sav_gidstr, sav_uid, sav_uidstr));
}

int
ns1__srmLs (struct soap *soap, struct ns1__srmLsRequest *req, struct ns1__srmLsResponse_ *rep)
{
	int c;
	char clientdn[256];
	const char *clienthost;
	int fflag;
	char **fqan;
	char func[16];
	gid_t gid;
	gid_t *gids;
	int i;
	char logbuf[CA_MAXSFNLEN+4];
	int nb_file_err = 0;
	int nbfqans;
	int nbgids;
	int nblevels;
	int nbsurls;
	struct ns1__srmLsResponse *repp;
	gid_t sav_gid = -1;
	char sav_gidstr[256];
	uid_t sav_uid = -1;
	char sav_uidstr[256];
	struct srm_srv_thread_info *thip = soap->user;
	uid_t uid;
	char *voname;

	strcpy (func, "Ls");
	get_client_dn (soap, clientdn, sizeof(clientdn));
	clienthost = Cgetnetaddress (-1, &soap->peer, soap->peerlen, &na_key, NULL, NULL, 0, 0);
	if (!clienthost) clienthost = "(unknown)";
	srmlogit (func, "request by %s from %s\n", clientdn, clienthost);
	if (! req) {
		soap_sender_fault (soap, "NULL request", NULL);
		RETURN (SOAP_FAULT);
	}

	/* Allocate response structure */

	if ((repp = soap_malloc (soap, sizeof(struct ns1__srmLsResponse))) == NULL ||
	    (repp->returnStatus = soap_malloc (soap, sizeof(struct ns1__TReturnStatus))) == NULL) {
		RETURN (SOAP_EOM);
	}
	repp->details = NULL;
	repp->returnStatus->explanation = NULL;
	rep->srmLsResponse = repp;

	if (get_client_full_id (soap, clientdn, &voname, &fqan, &nbfqans, &uid, &gid, &nbgids, &gids) < 0) {
		repp->returnStatus->statusCode = SRM_USCOREAUTHENTICATION_USCOREFAILURE;
		repp->returnStatus->explanation = soap_strdup (soap, "Could not get user mapping");
		RETURN (SOAP_OK);
	}

	if (! req->paths) {
		repp->returnStatus->statusCode = SRM_USCOREFAILURE;
		repp->returnStatus->explanation = soap_strdup (soap, "paths is required");
		RETURN (SOAP_OK);
	}
	if (req->fileStorageType) {
		repp->returnStatus->statusCode = SRM_USCORENOT_USCORESUPPORTED;
		repp->returnStatus->explanation = soap_strdup (soap, "filtering by fileStorageType is not supported");
		RETURN (SOAP_OK);
	}
	if ((req->allLevelRecursive && *req->allLevelRecursive) ||
	    (req->numOfLevels && *req->numOfLevels > 1)) {
		repp->returnStatus->statusCode = SRM_USCORENOT_USCORESUPPORTED;
		repp->returnStatus->explanation = soap_strdup (soap, "recursive option is not supported");
		RETURN (SOAP_OK);
	}
	if (req->numOfLevels)
		nblevels = *req->numOfLevels;
	else
		nblevels = 1;
	if (req->fullDetailedList && *req->fullDetailedList == true_)
		fflag = 1;
	else
		fflag = 0;

	nbsurls = req->paths->__sizesurlInfoArray;
	if ((repp->details =
		soap_malloc (soap, sizeof(struct ns1__ArrayOfTMetaDataPathDetail))) == NULL ||
	    (nbsurls > 0 && (repp->details->pathDetailArray =
		soap_malloc (soap, nbsurls * sizeof(struct ns1__TMetaDataPathDetail *))) == NULL))
		RETURN (SOAP_EOM);

	Cns_seterrbuf (thip->errbuf, sizeof(thip->errbuf));
	Cns_client_setAuthorizationId (uid, gid, "GSI", clientdn);
	if (voname && fqan)
		Cns_client_setVOMS_data (voname, fqan, nbfqans);

	repp->details->__sizepathDetailArray = nbsurls;
	for (i = 0; i < nbsurls; i++) {
		sprintf (logbuf, "Ls %s", req->paths->surlInfoArray[i]->SURLOrStFN->value);
		srm_logreq (func, logbuf);
		if ((repp->details->pathDetailArray[i] =
		    soap_malloc (soap, sizeof(struct ns1__TMetaDataPathDetail))) == NULL)
			RETURN (SOAP_EOM);
		c = listentry (soap, req->paths->surlInfoArray[i]->SURLOrStFN->value,
		    NULL, fflag, nblevels, 0, repp->details->pathDetailArray[i],
		    &sav_gid, sav_gidstr, &sav_uid, sav_uidstr);
		if (c == -2)
			RETURN (SOAP_EOM);
		if (c == -1)
			nb_file_err++;
	}
	repp->returnStatus->statusCode = (nb_file_err != nbsurls) ?
		SRM_USCORESUCCESS : (nbsurls == 1) ?
		repp->details->pathDetailArray[0]->status->statusCode : SRM_USCOREFAILURE;
	RETURN (SOAP_OK);
}

int
ns1__srmMv (struct soap *soap, struct ns1__srmMvRequest *req, struct ns1__srmMvResponse_ *rep)
{
	char clientdn[256];
	const char *clienthost;
	char **fqan;
	char func[16];
	gid_t gid;
	gid_t *gids;
	char logbuf[2*CA_MAXSFNLEN+5];
	int nbfqans;
	int nbgids;
	struct ns1__srmMvResponse *repp;
	char *sfn1;
	char *sfn2;
	struct srm_srv_thread_info *thip = soap->user;
	uid_t uid;
	char *voname;

	strcpy (func, "Mv");
	get_client_dn (soap, clientdn, sizeof(clientdn));
	clienthost = Cgetnetaddress (-1, &soap->peer, soap->peerlen, &na_key, NULL, NULL, 0, 0);
	if (!clienthost) clienthost = "(unknown)";
	srmlogit (func, "request by %s from %s\n", clientdn, clienthost);
	if (! req) {
		soap_sender_fault (soap, "NULL request", NULL);
		RETURN (SOAP_FAULT);
	}

	/* Allocate response structure */

	if ((repp = soap_malloc (soap, sizeof(struct ns1__srmMvResponse))) == NULL ||
	    (repp->returnStatus = soap_malloc (soap, sizeof(struct ns1__TReturnStatus))) == NULL) {
		RETURN (SOAP_EOM);
	}
	repp->returnStatus->explanation = NULL;
	rep->srmMvResponse = repp;

	if (get_client_full_id (soap, clientdn, &voname, &fqan, &nbfqans, &uid, &gid, &nbgids, &gids) < 0) {
		repp->returnStatus->statusCode = SRM_USCOREAUTHENTICATION_USCOREFAILURE;
		repp->returnStatus->explanation = soap_strdup (soap, "Could not get user mapping");
		RETURN (SOAP_OK);
	}

	if (! req->fromPath || ! req->fromPath->SURLOrStFN ||
	    ! req->fromPath->SURLOrStFN->value) {
		repp->returnStatus->statusCode = SRM_USCOREFAILURE;
		repp->returnStatus->explanation = soap_strdup (soap, "fromPath is required");
		RETURN (SOAP_OK);
	}
	if (! req->toPath || ! req->toPath->SURLOrStFN ||
	    ! req->toPath->SURLOrStFN->value) {
		repp->returnStatus->statusCode = SRM_USCOREFAILURE;
		repp->returnStatus->explanation = soap_strdup (soap, "toPath is required");
		RETURN (SOAP_OK);
	}
	if (strlen (req->fromPath->SURLOrStFN->value) > CA_MAXSFNLEN ||
	    strlen (req->toPath->SURLOrStFN->value) > CA_MAXSFNLEN ||
	    (sfn1 = sfnfromsurl (req->fromPath->SURLOrStFN->value)) == NULL ||
	    (sfn2 = sfnfromsurl (req->toPath->SURLOrStFN->value)) == NULL) {
		repp->returnStatus->statusCode = SRM_USCOREINVALID_USCOREPATH;
		RETURN (SOAP_OK);
	}
	sprintf (logbuf, "Mv %s %s", req->fromPath->SURLOrStFN->value,
	    req->toPath->SURLOrStFN->value);
	srm_logreq (func, logbuf);

	Cns_seterrbuf (thip->errbuf, sizeof(thip->errbuf));
	Cns_client_setAuthorizationId (uid, gid, "GSI", clientdn);
	if (voname && fqan)
		Cns_client_setVOMS_data (voname, fqan, nbfqans);

	if (Cns_rename (sfn1, sfn2) < 0) {
		repp->returnStatus->explanation = soap_strdup (soap, sstrerror (serrno));
		repp->returnStatus->statusCode = serrno2statuscode (serrno);
	} else
		repp->returnStatus->statusCode = SRM_USCORESUCCESS;
	RETURN (SOAP_OK);
}