summaryrefslogtreecommitdiff
path: root/examples/libsmbclient/smbwrapper/smbw.c
blob: d2f1c18695ddca2973df1a304722f6abd6292e86 (plain)
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
/* 
   Unix SMB/Netbios implementation.
   Version 2.0
   SMB wrapper functions
   Copyright (C) Andrew Tridgell 1998
   Copyright (C) Derrell Lipman 2003-2005
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <assert.h>
#include "smbw.h"

int smbw_fd_map[__FD_SETSIZE];
int smbw_ref_count[__FD_SETSIZE];
char smbw_cwd[PATH_MAX];
char smbw_prefix[] = SMBW_PREFIX;

/* needs to be here because of dumb include files on some systems */
int creat_bits = O_WRONLY|O_CREAT|O_TRUNC;

int smbw_initialized = 0;

static int debug_level = 0;

static SMBCCTX *smbw_ctx;

extern int smbw_debug;


int smbw_ref(int client_fd, Ref_Count_Type type, ...)
{
        va_list ap;

        /* client id values begin at SMBC_BASE_FC. */
        client_fd -= SMBC_BASE_FD;

        va_start(ap, type);
        switch(type)
        {
        case SMBW_RCT_Increment:
                return ++smbw_ref_count[client_fd];

        case SMBW_RCT_Decrement:
                return --smbw_ref_count[client_fd];

        case SMBW_RCT_Get:
                return smbw_ref_count[client_fd];

        case SMBW_RCT_Set:
                return (smbw_ref_count[client_fd] = va_arg(ap, int));
        }
        va_end(ap);

        /* never gets here */
        return -1;
}


/*
 * Return a username and password given a server and share name
 *
 * Returns 0 upon success;
 * non-zero otherwise, and errno is set to indicate the error.
 */
static void get_envvar_auth_data(const char *srv, 
                                 const char *shr,
                                 char *wg, int wglen, 
                                 char *un, int unlen,
                                 char *pw, int pwlen)
{
        char *u;
        char *p;
        char *w;

	/* Fall back to environment variables */

	w = getenv("WORKGROUP");
	if (w == NULL) w = "";

	u = getenv("USER");
	if (u == NULL) u = "";

	p = getenv("PASSWORD");
	if (p == NULL) p = "";

        strncpy(wg, w, wglen);
        strncpy(un, u, unlen);
        strncpy(pw, p, pwlen);
}

static smbc_get_auth_data_fn get_auth_data_fn = get_envvar_auth_data;

/*****************************************************
set the get auth data function
******************************************************/
void smbw_set_auth_data_fn(smbc_get_auth_data_fn fn)
{
	get_auth_data_fn = fn;
}


/*****************************************************
ensure that all connections are terminated upon exit
******************************************************/
static void do_shutdown(void)
{
        if (smbw_ctx != NULL) {
                smbc_free_context(smbw_ctx, 1);
        }
}


/***************************************************** 
initialise structures
*******************************************************/
static void do_init(int is_real_startup)
{
        int i;
        char *p;

	smbw_initialized = 1;   /* this must be first to avoid recursion! */

        smbw_ctx = NULL;        /* don't free context until it's established */

        /* initially, no file descriptors are mapped */
        for (i = 0; i < __FD_SETSIZE; i++) {
                smbw_fd_map[i] = -1;
                smbw_ref_count[i] = 0;
        }

        /* See if we've been told to start in a particular directory */
        if ((p=getenv("SMBW_DIR")) != NULL) {
                strncpy(smbw_cwd, p, PATH_MAX);

                /* we don't want the old directory to be busy */
                (* smbw_libc.chdir)("/");
                
        } else {
                *smbw_cwd = '\0';
        }

	if ((p=getenv("DEBUG"))) {
		debug_level = atoi(p);
	}

        if ((smbw_ctx = smbc_new_context()) == NULL) {
                exit(1);
        }
        
        smbw_ctx->debug = debug_level;
        smbw_ctx->callbacks.auth_fn = get_auth_data_fn;
        smbw_ctx->options.browse_max_lmb_count = 0;
        smbw_ctx->options.urlencode_readdir_entries = 1;
        smbw_ctx->options.one_share_per_server = 1;
//        smbw_cache_functions(smbw_ctx);
        
        if (smbc_init_context(smbw_ctx) == NULL) {
                exit(1);
        }
                
        smbc_set_context(smbw_ctx);

        /* if not real startup, exit handler has already been established */
        if (is_real_startup) {
            atexit(do_shutdown);
        }
}

/***************************************************** 
initialise structures, real start up vs a fork()
*******************************************************/
void smbw_init(void)
{
    do_init(1);
}


/***************************************************** 
determine if a file descriptor is a smb one
*******************************************************/
int smbw_fd(int smbw_fd)
{
        SMBW_INIT();

        return (smbw_fd >= 0 &&
                smbw_fd < __FD_SETSIZE &&
                smbw_fd_map[smbw_fd] >= SMBC_BASE_FD); /* minimum smbc_ fd */
}


/***************************************************** 
determine if a path is a smb one
*******************************************************/
int smbw_path(const char *name)
{
        int len;
        int ret;
        int saved_errno;

        saved_errno = errno;

        SMBW_INIT();

        len = strlen(smbw_prefix);

        ret = ((strncmp(name, smbw_prefix, len) == 0 &&
                (name[len] == '\0' || name[len] == '/')) ||
               (*name != '/' && *smbw_cwd != '\0'));

        errno = saved_errno;
        return ret;
}


/***************************************************** 
remove redundent stuff from a filename
*******************************************************/
void smbw_clean_fname(char *name)
{
	char *p, *p2;
	int l;
	int modified = 1;

	if (!name) return;

        DEBUG(10, ("Clean [%s]...\n", name));

	while (modified) {
		modified = 0;

		if ((p=strstr(name,"/./"))) {
			modified = 1;
			while (*p) {
				p[0] = p[2];
				p++;
			}
                        DEBUG(10, ("\tclean 1 (/./) produced [%s]\n", name));
		}

		if ((p=strstr(name,"//"))) {
			modified = 1;
			while (*p) {
				p[0] = p[1];
				p++;
			}
                        DEBUG(10, ("\tclean 2 (//) produced [%s]\n", name));
		}

		if (strcmp(name,"/../")==0) {
			modified = 1;
			name[1] = 0;
                        DEBUG(10,("\tclean 3 (^/../$) produced [%s]\n", name));
		}

		if ((p=strstr(name,"/../"))) {
			modified = 1;
			for (p2 = (p > name ? p-1 : p); p2 > name; p2--) {
				if (p2[0] == '/') break;
			}
                        if (p2 > name) p2++;
			while (*p2) {
				p2[0] = p[3];
				p2++;
                                p++;
			}
                        DEBUG(10, ("\tclean 4 (/../) produced [%s]\n", name));
		}

		if (strcmp(name,"/..")==0) {
			modified = 1;
			name[1] = 0;
                        DEBUG(10, ("\tclean 5 (^/..$) produced [%s]\n", name));
		}

		l = strlen(name);
		p = l>=3?(name+l-3):name;
		if (strcmp(p,"/..")==0) {
			modified = 1;
			for (p2=p-1;p2>name;p2--) {
				if (p2[0] == '/') break;
			}
			if (p2==name) {
				p[0] = '/';
				p[1] = 0;
			} else {
				p2[0] = 0;
			}
                        DEBUG(10, ("\tclean 6 (/..) produced [%s]\n", name));
		}

		l = strlen(name);
		p = l>=2?(name+l-2):name;
		if (strcmp(p,"/.")==0) {
                        modified = 1;
			if (p == name) {
				p[1] = 0;
			} else {
				p[0] = 0;
			}
                        DEBUG(10, ("\tclean 7 (/.) produced [%s]\n", name));
		}

		if (strncmp(p=name,"./",2) == 0) {      
			modified = 1;
			do {
				p[0] = p[2];
			} while (*p++);
                        DEBUG(10, ("\tclean 8 (^./) produced [%s]\n", name));
		}

		l = strlen(p=name);
		if (l > 1 && p[l-1] == '/') {
			modified = 1;
			p[l-1] = 0;
                        DEBUG(10, ("\tclean 9 (/) produced [%s]\n", name));
		}
	}
}

void smbw_fix_path(const char *src, char *dest)
{
        const char *p;
        int len = strlen(smbw_prefix);

        if (*src == '/') {
                for (p = src + len; *p == '/'; p++)
                        ;
                snprintf(dest, PATH_MAX, "smb://%s", p);
        } else {
                snprintf(dest, PATH_MAX, "%s/%s", smbw_cwd, src);
        }

        smbw_clean_fname(dest + 5);

        DEBUG(10, ("smbw_fix_path(%s) returning [%s]\n", src, dest));
}



/***************************************************** 
a wrapper for open()
*******************************************************/
int smbw_open(const char *fname, int flags, mode_t mode)
{
        int client_fd;
        int smbw_fd;
	char path[PATH_MAX];

	SMBW_INIT();

	if (!fname) {
		errno = EINVAL;
		return -1;
	}

	smbw_fd = (smbw_libc.open)(SMBW_DUMMY, O_WRONLY, 0200);
	if (smbw_fd == -1) {
		errno = EMFILE;
                return -1;
	}

        smbw_fix_path(fname, path);
        if (flags == creat_bits) {
                client_fd =  smbc_creat(path, mode);
        } else {
                client_fd = smbc_open(path, flags, mode);
        }

        if (client_fd < 0) {
                (* smbw_libc.close)(smbw_fd);
                return -1;
        }

        smbw_fd_map[smbw_fd] = client_fd;
        smbw_ref(client_fd, SMBW_RCT_Increment);
        return smbw_fd;
}


/***************************************************** 
a wrapper for pread()

there should really be an smbc_pread() to avoid the two
lseek()s required in this kludge.
*******************************************************/
ssize_t smbw_pread(int smbw_fd, void *buf, size_t count, SMBW_OFF_T ofs)
{
        int client_fd;
	ssize_t ret;
        int saved_errno;
        SMBW_OFF_T old_ofs;
        
        client_fd = smbw_fd_map[smbw_fd];

        if ((old_ofs = smbc_lseek(client_fd, 0, SEEK_CUR)) < 0 ||
            smbc_lseek(client_fd, ofs, SEEK_SET) < 0) {
                return -1;
        }

        if ((ret = smbc_read(client_fd, buf, count)) < 0) {
                saved_errno = errno;
                (void) smbc_lseek(client_fd, old_ofs, SEEK_SET);
                errno = saved_errno;
                return -1;
        }

        return ret;
}

/***************************************************** 
a wrapper for read()
*******************************************************/
ssize_t smbw_read(int smbw_fd, void *buf, size_t count)
{
        int client_fd;
        
        client_fd = smbw_fd_map[smbw_fd];

        return smbc_read(client_fd, buf, count);
}

	

/***************************************************** 
a wrapper for write()
*******************************************************/
ssize_t smbw_write(int smbw_fd, void *buf, size_t count)
{
        int client_fd;

        client_fd = smbw_fd_map[smbw_fd];

        return smbc_write(client_fd, buf, count);
}

/***************************************************** 
a wrapper for pwrite()
*******************************************************/
ssize_t smbw_pwrite(int smbw_fd, void *buf, size_t count, SMBW_OFF_T ofs)
{
        int saved_errno;
        int client_fd;
	ssize_t ret;
        SMBW_OFF_T old_ofs;
        
        client_fd = smbw_fd_map[smbw_fd];

        if ((old_ofs = smbc_lseek(client_fd, 0, SEEK_CUR)) < 0 ||
            smbc_lseek(client_fd, ofs, SEEK_SET) < 0) {
                return -1;
        }

        if ((ret = smbc_write(client_fd, buf, count)) < 0) {
                saved_errno = errno;
                (void) smbc_lseek(client_fd, old_ofs, SEEK_SET);
                errno = saved_errno;
                return -1;
        }

        return ret;
}

/***************************************************** 
a wrapper for close()
*******************************************************/
int smbw_close(int smbw_fd)
{
        int client_fd;

        client_fd = smbw_fd_map[smbw_fd];

        if (smbw_ref(client_fd, SMBW_RCT_Decrement) > 0) {
                return 0;
        }
        
        (* smbw_libc.close)(smbw_fd);
        smbw_fd_map[smbw_fd] = -1;
        return smbc_close(client_fd);
}


/***************************************************** 
a wrapper for fcntl()
*******************************************************/
int smbw_fcntl(int smbw_fd, int cmd, long arg)
{
	return 0;
}


/***************************************************** 
a wrapper for access()
*******************************************************/
int smbw_access(const char *name, int mode)
{
	struct SMBW_stat st;

        SMBW_INIT();

	if (smbw_stat(name, &st)) return -1;

	if (((mode & R_OK) && !(st.s_mode & S_IRUSR)) ||
	    ((mode & W_OK) && !(st.s_mode & S_IWUSR)) ||
	    ((mode & X_OK) && !(st.s_mode & S_IXUSR))) {
		errno = EACCES;
		return -1;
	}
	
	return 0;
}

/***************************************************** 
a wrapper for readlink() - needed for correct errno setting
*******************************************************/
int smbw_readlink(const char *fname, char *buf, size_t bufsize)
{
	struct SMBW_stat st;
	int ret;

        SMBW_INIT();

	ret = smbw_stat(fname, &st);
	if (ret != 0) {
		return -1;
	}
	
	/* it exists - say it isn't a link */
	errno = EINVAL;
	return -1;
}


/***************************************************** 
a wrapper for unlink()
*******************************************************/
int smbw_unlink(const char *fname)
{
        char path[PATH_MAX];
        
        SMBW_INIT();

        smbw_fix_path(fname, path);
        return smbc_unlink(path);
}


/***************************************************** 
a wrapper for rename()
*******************************************************/
int smbw_rename(const char *oldname, const char *newname)
{
        char path_old[PATH_MAX];
        char path_new[PATH_MAX];

        SMBW_INIT();

        smbw_fix_path(oldname, path_old);
        smbw_fix_path(newname, path_new);
        return smbc_rename(path_old, path_new);
}


/***************************************************** 
a wrapper for utimes
*******************************************************/
int smbw_utimes(const char *fname, void *buf)
{
        char path[PATH_MAX];

        smbw_fix_path(fname, path);
	return smbc_utimes(path, buf);
}


/***************************************************** 
a wrapper for utime 
*******************************************************/
int smbw_utime(const char *fname, void *buf)
{
        char path[PATH_MAX];

        smbw_fix_path(fname, path);
        return smbc_utime(path, buf);
}

/***************************************************** 
a wrapper for chown()
*******************************************************/
int smbw_chown(const char *fname, uid_t owner, gid_t group)
{
        /* always indiciate that this is not supported. */
        errno = ENOTSUP;
        return -1;
}

/***************************************************** 
a wrapper for chmod()
*******************************************************/
int smbw_chmod(const char *fname, mode_t newmode)
{
        char path[PATH_MAX];

        smbw_fix_path(fname, path);
        return smbc_chmod(path, newmode);
}


/***************************************************** 
a wrapper for lseek()
*******************************************************/
SMBW_OFF_T smbw_lseek(int smbw_fd,
                      SMBW_OFF_T offset,
                      int whence)
{
        int client_fd;
        SMBW_OFF_T ret;
        
        client_fd = smbw_fd_map[smbw_fd];

        ret = smbc_lseek(client_fd, offset, whence);
        if (smbw_debug)
        {
                printf("smbw_lseek(%d/%d, 0x%llx) returned 0x%llx\n",
                       smbw_fd, client_fd,
                       (unsigned long long) offset,
                       (unsigned long long) ret);
        }
        return ret;
}

/***************************************************** 
a wrapper for dup()
*******************************************************/
int smbw_dup(int smbw_fd)
{
	int fd2;

	fd2 = (smbw_libc.dup)(smbw_fd);
	if (fd2 == -1) {
                return -1;
	}

        smbw_fd_map[fd2] = smbw_fd_map[smbw_fd];
        smbw_ref(smbw_fd_map[smbw_fd], SMBW_RCT_Increment);
	return fd2;
}


/***************************************************** 
a wrapper for dup2()
*******************************************************/
int smbw_dup2(int smbw_fd, int fd2)
{
	if ((* smbw_libc.dup2)(smbw_fd, fd2) != fd2) {
                return -1;
	}

        smbw_fd_map[fd2] = smbw_fd_map[smbw_fd];
        smbw_ref(smbw_fd_map[smbw_fd], SMBW_RCT_Increment);
	return fd2;
}


/***************************************************** 
when we fork we have to close all connections and files
in the child
*******************************************************/
int smbw_fork(void)
{
        int i;
	pid_t child_pid;
	int p[2];
	char c = 0;

        SMBW_INIT();

	if (pipe(p)) return (* smbw_libc.fork)();

	child_pid = (* smbw_libc.fork)();

	if (child_pid) {
		/* block the parent for a moment until the sockets are
                   closed */
		(* smbw_libc.close)(p[1]);
		(* smbw_libc.read)(p[0], &c, 1);
		(* smbw_libc.close)(p[0]);
		return child_pid;
        }

	(* smbw_libc.close)(p[0]);

        /* close all server connections and locally-opened files */
        for (i = 0; i < __FD_SETSIZE; i++) {
                if (smbw_fd_map[i] > 0 &&
                    smbw_ref(smbw_fd_map[i], SMBW_RCT_Get) > 0) {
                        
                        smbc_close(smbw_fd_map[i]);
                        smbw_ref(smbw_fd_map[i], SMBW_RCT_Set, 0);
                        (* smbw_libc.close)(i);
                }

                smbw_fd_map[i] = -1;
        }

	/* unblock the parent */
	write(p[1], &c, 1);
	(* smbw_libc.close)(p[1]);

        /* specify directory to start in, if it's simulated smb */
        if (*smbw_cwd != '\0') {
                setenv("SMBW_DIR", smbw_cwd, 1);
        } else {
                unsetenv("SMBW_DIR");
        }

        /* Re-initialize this library for the child */
        do_init(0);

	/* and continue in the child */
	return 0;
}

int smbw_setxattr(const char *fname,
                  const char *name,
                  const void *value,
                  size_t size,
                  int flags)
{
        char path[PATH_MAX];

        if (strcmp(name, "system.posix_acl_access") == 0)
        {
                name = "system.*";
        }

        smbw_fix_path(fname, path);
        return smbc_setxattr(path, name, value, size, flags);
}

int smbw_lsetxattr(const char *fname,
                   const char *name,
                   const void *value,
                   size_t size,
                   int flags)
{
        char path[PATH_MAX];

        if (strcmp(name, "system.posix_acl_access") == 0)
        {
                name = "system.*";
        }

        smbw_fix_path(fname, path);
        return smbc_lsetxattr(path, name, value, size, flags);
}

int smbw_fsetxattr(int smbw_fd,
                   const char *name,
                   const void *value,
                   size_t size,
                   int flags)
{
        int client_fd;
        
        if (strcmp(name, "system.posix_acl_access") == 0)
        {
                name = "system.*";
        }

        client_fd = smbw_fd_map[smbw_fd];
        return smbc_fsetxattr(client_fd, name, value, size, flags);
}

int smbw_getxattr(const char *fname,
                  const char *name,
                  const void *value,
                  size_t size)
{
        char path[PATH_MAX];

        if (strcmp(name, "system.posix_acl_access") == 0)
        {
                name = "system.*";
        }

        smbw_fix_path(fname, path);

        return smbc_getxattr(path, name, value, size);
}

int smbw_lgetxattr(const char *fname,
                   const char *name,
                   const void *value,
                   size_t size)
{
        char path[PATH_MAX];

        if (strcmp(name, "system.posix_acl_access") == 0)
        {
                name = "system.*";
        }

        smbw_fix_path(fname, path);
        return smbc_lgetxattr(path, name, value, size);
}

int smbw_fgetxattr(int smbw_fd,
                   const char *name,
                   const void *value,
                   size_t size)
{
        int client_fd;
        
        if (strcmp(name, "system.posix_acl_access") == 0)
        {
                name = "system.*";
        }

        client_fd = smbw_fd_map[smbw_fd];
        return smbc_fgetxattr(client_fd, name, value, size);
}

int smbw_removexattr(const char *fname,
                     const char *name)
{
        char path[PATH_MAX];

        if (strcmp(name, "system.posix_acl_access") == 0)
        {
                name = "system.*";
        }

        smbw_fix_path(fname, path);
        return smbc_removexattr(path, name);
}

int smbw_lremovexattr(const char *fname,
                      const char *name)
{
        char path[PATH_MAX];

        if (strcmp(name, "system.posix_acl_access") == 0)
        {
                name = "system.*";
        }

        smbw_fix_path(fname, path);
        return smbc_lremovexattr(path, name);
}

int smbw_fremovexattr(int smbw_fd,
                      const char *name)
{
        int client_fd;
        
        if (strcmp(name, "system.posix_acl_access") == 0)
        {
                name = "system.*";
        }

        client_fd = smbw_fd_map[smbw_fd];
        return smbc_fremovexattr(client_fd, name);
}

int smbw_listxattr(const char *fname,
                   char *list,
                   size_t size)
{
        char path[PATH_MAX];

        smbw_fix_path(fname, path);
        return smbc_listxattr(path, list, size);
}

int smbw_llistxattr(const char *fname,
                    char *list,
                    size_t size)
{
        char path[PATH_MAX];

        smbw_fix_path(fname, path);
        return smbc_llistxattr(path, list, size);
}

int smbw_flistxattr(int smbw_fd,
                    char *list,
                    size_t size)
{
        int client_fd;
        
        client_fd = smbw_fd_map[smbw_fd];
        return smbc_flistxattr(client_fd, list, size);
}