summaryrefslogtreecommitdiff
path: root/source4/ntvfs/ipc/vfs_ipc.c
blob: 7fc3b1488415695cee1357981af42719a284aae3 (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
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
/* 
   Unix SMB/CIFS implementation.
   default IPC$ NTVFS backend

   Copyright (C) Andrew Tridgell 2003
   Copyright (C) Stefan (metze) Metzmacher 2004-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 3 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, see <http://www.gnu.org/licenses/>.
*/
/*
  this implements the IPC$ backend, called by the NTVFS subsystem to
  handle requests on IPC$ shares
*/


#include "includes.h"
#include "../lib/util/dlinklist.h"
#include "ntvfs/ntvfs.h"
#include "../librpc/gen_ndr/rap.h"
#include "ntvfs/ipc/proto.h"
#include "../libcli/smb/smb_constants.h"
#include "param/param.h"
#include "../lib/tsocket/tsocket.h"
#include "../libcli/named_pipe_auth/npa_tstream.h"
#include "auth/auth.h"
#include "auth/auth_sam_reply.h"
#include "lib/socket/socket.h"
#include "auth/credentials/credentials.h"
#include "auth/credentials/credentials_krb5.h"
#include "system/kerberos.h"
#include "system/gssapi.h"
#include "system/locale.h"
#include "system/filesys.h"

/* this is the private structure used to keep the state of an open
   ipc$ connection. It needs to keep information about all open
   pipes */
struct ipc_private {
	struct ntvfs_module_context *ntvfs;

	/* a list of open pipes */
	struct pipe_state {
		struct pipe_state *next, *prev;
		struct ipc_private *ipriv;
		const char *pipe_name;
		struct ntvfs_handle *handle;
		struct tstream_context *npipe;
		uint16_t file_type;
		uint16_t device_state;
		uint64_t allocation_size;
		struct tevent_queue *write_queue;
		struct tevent_queue *read_queue;
	} *pipe_list;
};


/*
  find a open pipe give a file handle
*/
static struct pipe_state *pipe_state_find(struct ipc_private *ipriv, struct ntvfs_handle *handle)
{
	struct pipe_state *s;
	void *p;

	p = ntvfs_handle_get_backend_data(handle, ipriv->ntvfs);
	if (!p) return NULL;

	s = talloc_get_type(p, struct pipe_state);
	if (!s) return NULL;

	return s;
}

/*
  find a open pipe give a wire fnum
*/
static struct pipe_state *pipe_state_find_key(struct ipc_private *ipriv, struct ntvfs_request *req, const DATA_BLOB *key)
{
	struct ntvfs_handle *h;

	h = ntvfs_handle_search_by_wire_key(ipriv->ntvfs, req, key);
	if (!h) return NULL;

	return pipe_state_find(ipriv, h);
}


/*
  connect to a share - always works 
*/
static NTSTATUS ipc_connect(struct ntvfs_module_context *ntvfs,
			    struct ntvfs_request *req,
			    union smb_tcon* tcon)
{
	struct ipc_private *ipriv;
	const char *sharename;

	switch (tcon->generic.level) {
	case RAW_TCON_TCON:
		sharename = tcon->tcon.in.service;
		break;
	case RAW_TCON_TCONX:
		sharename = tcon->tconx.in.path;
		break;
	case RAW_TCON_SMB2:
		sharename = tcon->smb2.in.path;
		break;
	default:
		return NT_STATUS_INVALID_LEVEL;
	}

	if (strncmp(sharename, "\\\\", 2) == 0) {
		char *p = strchr(sharename+2, '\\');
		if (p) {
			sharename = p + 1;
		}
	}

	ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "IPC");
	NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);

	ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "IPC");
	NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);

	if (tcon->generic.level == RAW_TCON_TCONX) {
		tcon->tconx.out.fs_type = ntvfs->ctx->fs_type;
		tcon->tconx.out.dev_type = ntvfs->ctx->dev_type;
	}

	/* prepare the private state for this connection */
	ipriv = talloc(ntvfs, struct ipc_private);
	NT_STATUS_HAVE_NO_MEMORY(ipriv);

	ntvfs->private_data = ipriv;

	ipriv->ntvfs = ntvfs;
	ipriv->pipe_list = NULL;

	return NT_STATUS_OK;
}

/*
  disconnect from a share
*/
static NTSTATUS ipc_disconnect(struct ntvfs_module_context *ntvfs)
{
	return NT_STATUS_OK;
}

/*
  delete a file
*/
static NTSTATUS ipc_unlink(struct ntvfs_module_context *ntvfs,
			   struct ntvfs_request *req,
			   union smb_unlink *unl)
{
	return NT_STATUS_ACCESS_DENIED;
}

/*
  check if a directory exists
*/
static NTSTATUS ipc_chkpath(struct ntvfs_module_context *ntvfs,
			    struct ntvfs_request *req,
			    union smb_chkpath *cp)
{
	return NT_STATUS_ACCESS_DENIED;
}

/*
  return info on a pathname
*/
static NTSTATUS ipc_qpathinfo(struct ntvfs_module_context *ntvfs,
			      struct ntvfs_request *req, union smb_fileinfo *info)
{
	switch (info->generic.level) {
	case  RAW_FILEINFO_GENERIC:
		return NT_STATUS_INVALID_DEVICE_REQUEST;
	case RAW_FILEINFO_GETATTR:
		return NT_STATUS_ACCESS_DENIED;
	default:
		return ntvfs_map_qpathinfo(ntvfs, req, info);
	}
}

/*
  set info on a pathname
*/
static NTSTATUS ipc_setpathinfo(struct ntvfs_module_context *ntvfs,
				struct ntvfs_request *req, union smb_setfileinfo *st)
{
	return NT_STATUS_ACCESS_DENIED;
}


/*
  destroy a open pipe structure
*/
static int ipc_fd_destructor(struct pipe_state *p)
{
	DLIST_REMOVE(p->ipriv->pipe_list, p);
	ntvfs_handle_remove_backend_data(p->handle, p->ipriv->ntvfs);
	return 0;
}

struct ipc_open_state {
	struct ipc_private *ipriv;
	struct pipe_state *p;
	struct ntvfs_request *req;
	union smb_open *oi;
	struct auth_session_info_transport *session_info_transport;
};

static void ipc_open_done(struct tevent_req *subreq);

/*
  check the pipename is valid
 */
static NTSTATUS validate_pipename(const char *name)
{
	while (*name) {
		if (!isalnum(*name) && *name != '_') {
			return NT_STATUS_INVALID_PARAMETER;
		}
		name++;
	}
	return NT_STATUS_OK;
}

/*
  open a file - used for MSRPC pipes
*/
static NTSTATUS ipc_open(struct ntvfs_module_context *ntvfs,
			 struct ntvfs_request *req, union smb_open *oi)
{
	NTSTATUS status;
	struct pipe_state *p;
	struct ipc_private *ipriv = talloc_get_type_abort(ntvfs->private_data,
				    struct ipc_private);
	struct ntvfs_handle *h;
	struct ipc_open_state *state;
	struct tevent_req *subreq;
	const char *fname;
	const char *directory;
	const struct tsocket_address *client_addr;
	const struct tsocket_address *server_addr;

	switch (oi->generic.level) {
	case RAW_OPEN_NTCREATEX:
	case RAW_OPEN_NTTRANS_CREATE:
		fname = oi->ntcreatex.in.fname;
		while (fname[0] == '\\') fname++;
		break;
	case RAW_OPEN_OPENX:
		fname = oi->openx.in.fname;
		while (fname[0] == '\\') fname++;
		if (strncasecmp(fname, "PIPE\\", 5) != 0) {
			return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
		}
		while (fname[0] == '\\') fname++;
		break;
	case RAW_OPEN_SMB2:
		fname = oi->smb2.in.fname;
		break;
	default:
		return NT_STATUS_NOT_SUPPORTED;
	}

	directory = talloc_asprintf(req, "%s/np",
				    lpcfg_ncalrpc_dir(ipriv->ntvfs->ctx->lp_ctx));
	NT_STATUS_HAVE_NO_MEMORY(directory);

	state = talloc(req, struct ipc_open_state);
	NT_STATUS_HAVE_NO_MEMORY(state);

	status = ntvfs_handle_new(ntvfs, req, &h);
	NT_STATUS_NOT_OK_RETURN(status);

	p = talloc(h, struct pipe_state);
	NT_STATUS_HAVE_NO_MEMORY(p);

	/* check for valid characters in name */
	fname = strlower_talloc(p, fname);

	status = validate_pipename(fname);
	NT_STATUS_NOT_OK_RETURN(status);

	p->pipe_name = talloc_asprintf(p, "\\pipe\\%s", fname);
	NT_STATUS_HAVE_NO_MEMORY(p->pipe_name);

	p->handle = h;
	p->ipriv = ipriv;

	p->write_queue = tevent_queue_create(p, "ipc_write_queue");
	NT_STATUS_HAVE_NO_MEMORY(p->write_queue);

	p->read_queue = tevent_queue_create(p, "ipc_read_queue");
	NT_STATUS_HAVE_NO_MEMORY(p->read_queue);

	state->ipriv = ipriv;
	state->p = p;
	state->req = req;
	state->oi = oi;

	status = auth_session_info_transport_from_session(state,
							  req->session_info,
							  ipriv->ntvfs->ctx->event_ctx,
							  ipriv->ntvfs->ctx->lp_ctx,
							  &state->session_info_transport);

	NT_STATUS_NOT_OK_RETURN(status);

	client_addr = ntvfs_get_local_address(ipriv->ntvfs);
	server_addr = ntvfs_get_remote_address(ipriv->ntvfs);

	subreq = tstream_npa_connect_send(p,
					  ipriv->ntvfs->ctx->event_ctx,
					  directory,
					  fname,
					  client_addr,
					  NULL,
					  server_addr,
					  NULL,
					  state->session_info_transport);
	NT_STATUS_HAVE_NO_MEMORY(subreq);
	tevent_req_set_callback(subreq, ipc_open_done, state);

	req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC;
	return NT_STATUS_OK;
}

static void ipc_open_done(struct tevent_req *subreq)
{
	struct ipc_open_state *state = tevent_req_callback_data(subreq,
				       struct ipc_open_state);
	struct ipc_private *ipriv = state->ipriv;
	struct pipe_state *p = state->p;
	struct ntvfs_request *req = state->req;
	union smb_open *oi = state->oi;
	int ret;
	int sys_errno;
	NTSTATUS status;

	ret = tstream_npa_connect_recv(subreq, &sys_errno,
				       p, &p->npipe,
				       &p->file_type,
				       &p->device_state,
				       &p->allocation_size);
	TALLOC_FREE(subreq);
	if (ret == -1) {
		status = map_nt_error_from_unix_common(sys_errno);
		goto reply;
	}

	DLIST_ADD(ipriv->pipe_list, p);
	talloc_set_destructor(p, ipc_fd_destructor);

	status = ntvfs_handle_set_backend_data(p->handle, ipriv->ntvfs, p);
	if (!NT_STATUS_IS_OK(status)) {
		goto reply;
	}

	switch (oi->generic.level) {
	case RAW_OPEN_NTCREATEX:
		ZERO_STRUCT(oi->ntcreatex.out);
		oi->ntcreatex.out.file.ntvfs	= p->handle;
		oi->ntcreatex.out.oplock_level	= 0;
		oi->ntcreatex.out.create_action	= NTCREATEX_ACTION_EXISTED;
		oi->ntcreatex.out.create_time	= 0;
		oi->ntcreatex.out.access_time	= 0;
		oi->ntcreatex.out.write_time	= 0;
		oi->ntcreatex.out.change_time	= 0;
		oi->ntcreatex.out.attrib	= FILE_ATTRIBUTE_NORMAL;
		oi->ntcreatex.out.alloc_size	= p->allocation_size;
		oi->ntcreatex.out.size		= 0;
		oi->ntcreatex.out.file_type	= p->file_type;
		oi->ntcreatex.out.ipc_state	= p->device_state;
		oi->ntcreatex.out.is_directory	= 0;
		break;
	case RAW_OPEN_OPENX:
		ZERO_STRUCT(oi->openx.out);
		oi->openx.out.file.ntvfs	= p->handle;
		oi->openx.out.attrib		= FILE_ATTRIBUTE_NORMAL;
		oi->openx.out.write_time	= 0;
		oi->openx.out.size		= 0;
		oi->openx.out.access		= 0;
		oi->openx.out.ftype		= p->file_type;
		oi->openx.out.devstate		= p->device_state;
		oi->openx.out.action		= 0;
		oi->openx.out.unique_fid	= 0;
		oi->openx.out.access_mask	= 0;
		oi->openx.out.unknown		= 0;
		break;
	case RAW_OPEN_SMB2:
		ZERO_STRUCT(oi->smb2.out);
		oi->smb2.out.file.ntvfs		= p->handle;
		oi->smb2.out.oplock_level	= oi->smb2.in.oplock_level;
		oi->smb2.out.create_action	= NTCREATEX_ACTION_EXISTED;
		oi->smb2.out.create_time	= 0;
		oi->smb2.out.access_time	= 0;
		oi->smb2.out.write_time		= 0;
		oi->smb2.out.change_time	= 0;
		oi->smb2.out.alloc_size		= p->allocation_size;
		oi->smb2.out.size		= 0;
		oi->smb2.out.file_attr		= FILE_ATTRIBUTE_NORMAL;
		oi->smb2.out.reserved2		= 0;
		break;
	default:
		break;
	}

reply:
	req->async_states->status = status;
	req->async_states->send_fn(req);
}

/*
  create a directory
*/
static NTSTATUS ipc_mkdir(struct ntvfs_module_context *ntvfs,
			  struct ntvfs_request *req, union smb_mkdir *md)
{
	return NT_STATUS_ACCESS_DENIED;
}

/*
  remove a directory
*/
static NTSTATUS ipc_rmdir(struct ntvfs_module_context *ntvfs,
			  struct ntvfs_request *req, struct smb_rmdir *rd)
{
	return NT_STATUS_ACCESS_DENIED;
}

/*
  rename a set of files
*/
static NTSTATUS ipc_rename(struct ntvfs_module_context *ntvfs,
			   struct ntvfs_request *req, union smb_rename *ren)
{
	return NT_STATUS_ACCESS_DENIED;
}

/*
  copy a set of files
*/
static NTSTATUS ipc_copy(struct ntvfs_module_context *ntvfs,
			 struct ntvfs_request *req, struct smb_copy *cp)
{
	return NT_STATUS_ACCESS_DENIED;
}

struct ipc_readv_next_vector_state {
	uint8_t *buf;
	size_t len;
	off_t ofs;
	size_t remaining;
};

static void ipc_readv_next_vector_init(struct ipc_readv_next_vector_state *s,
				       uint8_t *buf, size_t len)
{
	ZERO_STRUCTP(s);

	s->buf = buf;
	s->len = MIN(len, UINT16_MAX);
}

static int ipc_readv_next_vector(struct tstream_context *stream,
				 void *private_data,
				 TALLOC_CTX *mem_ctx,
				 struct iovec **_vector,
				 size_t *count)
{
	struct ipc_readv_next_vector_state *state =
		(struct ipc_readv_next_vector_state *)private_data;
	struct iovec *vector;
	ssize_t pending;
	size_t wanted;

	if (state->ofs == state->len) {
		*_vector = NULL;
		*count = 0;
		return 0;
	}

	pending = tstream_pending_bytes(stream);
	if (pending == -1) {
		return -1;
	}

	if (pending == 0 && state->ofs != 0) {
		/* return a short read */
		*_vector = NULL;
		*count = 0;
		return 0;
	}

	if (pending == 0) {
		/* we want at least one byte and recheck again */
		wanted = 1;
	} else {
		size_t missing = state->len - state->ofs;
		if (pending > missing) {
			/* there's more available */
			state->remaining = pending - missing;
			wanted = missing;
		} else {
			/* read what we can get and recheck in the next cycle */
			wanted = pending;
		}
	}

	vector = talloc_array(mem_ctx, struct iovec, 1);
	if (!vector) {
		return -1;
	}

	vector[0].iov_base = (char *) (state->buf + state->ofs);
	vector[0].iov_len = wanted;

	state->ofs += wanted;

	*_vector = vector;
	*count = 1;
	return 0;
}

struct ipc_read_state {
	struct ipc_private *ipriv;
	struct pipe_state *p;
	struct ntvfs_request *req;
	union smb_read *rd;
	struct ipc_readv_next_vector_state next_vector;
};

static void ipc_read_done(struct tevent_req *subreq);

/*
  read from a file
*/
static NTSTATUS ipc_read(struct ntvfs_module_context *ntvfs,
			 struct ntvfs_request *req, union smb_read *rd)
{
	struct ipc_private *ipriv = talloc_get_type_abort(ntvfs->private_data,
				    struct ipc_private);
	struct pipe_state *p;
	struct ipc_read_state *state;
	struct tevent_req *subreq;

	if (rd->generic.level != RAW_READ_GENERIC) {
		return ntvfs_map_read(ntvfs, req, rd);
	}

	p = pipe_state_find(ipriv, rd->readx.in.file.ntvfs);
	if (!p) {
		return NT_STATUS_INVALID_HANDLE;
	}

	state = talloc(req, struct ipc_read_state);
	NT_STATUS_HAVE_NO_MEMORY(state);

	state->ipriv = ipriv;
	state->p = p;
	state->req = req;
	state->rd = rd;

	/* rd->readx.out.data is already allocated */
	ipc_readv_next_vector_init(&state->next_vector,
				   rd->readx.out.data,
				   rd->readx.in.maxcnt);

	subreq = tstream_readv_pdu_queue_send(req,
					      ipriv->ntvfs->ctx->event_ctx,
					      p->npipe,
					      p->read_queue,
					      ipc_readv_next_vector,
					      &state->next_vector);
	NT_STATUS_HAVE_NO_MEMORY(subreq);
	tevent_req_set_callback(subreq, ipc_read_done, state);

	req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC;
	return NT_STATUS_OK;
}

static void ipc_read_done(struct tevent_req *subreq)
{
	struct ipc_read_state *state =
		tevent_req_callback_data(subreq,
		struct ipc_read_state);
	struct ntvfs_request *req = state->req;
	union smb_read *rd = state->rd;
	int ret;
	int sys_errno;
	NTSTATUS status;

	ret = tstream_readv_pdu_queue_recv(subreq, &sys_errno);
	TALLOC_FREE(subreq);
	if (ret == -1) {
		status = map_nt_error_from_unix_common(sys_errno);
		goto reply;
	}

	status = NT_STATUS_OK;
	if (state->next_vector.remaining > 0) {
		status = STATUS_BUFFER_OVERFLOW;
	}

	rd->readx.out.remaining = state->next_vector.remaining;
	rd->readx.out.compaction_mode = 0;
	rd->readx.out.nread = ret;

reply:
	req->async_states->status = status;
	req->async_states->send_fn(req);
}

struct ipc_write_state {
	struct ipc_private *ipriv;
	struct pipe_state *p;
	struct ntvfs_request *req;
	union smb_write *wr;
	struct iovec iov;
};

static void ipc_write_done(struct tevent_req *subreq);

/*
  write to a file
*/
static NTSTATUS ipc_write(struct ntvfs_module_context *ntvfs,
			  struct ntvfs_request *req, union smb_write *wr)
{
	struct ipc_private *ipriv = talloc_get_type_abort(ntvfs->private_data,
				    struct ipc_private);
	struct pipe_state *p;
	struct tevent_req *subreq;
	struct ipc_write_state *state;

	if (wr->generic.level != RAW_WRITE_GENERIC) {
		return ntvfs_map_write(ntvfs, req, wr);
	}

	p = pipe_state_find(ipriv, wr->writex.in.file.ntvfs);
	if (!p) {
		return NT_STATUS_INVALID_HANDLE;
	}

	state = talloc(req, struct ipc_write_state);
	NT_STATUS_HAVE_NO_MEMORY(state);

	state->ipriv = ipriv;
	state->p = p;
	state->req = req;
	state->wr = wr;
	state->iov.iov_base = discard_const_p(void, wr->writex.in.data);
	state->iov.iov_len = wr->writex.in.count;

	subreq = tstream_writev_queue_send(state,
					   ipriv->ntvfs->ctx->event_ctx,
					   p->npipe,
					   p->write_queue,
					   &state->iov, 1);
	NT_STATUS_HAVE_NO_MEMORY(subreq);
	tevent_req_set_callback(subreq, ipc_write_done, state);

	req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC;
	return NT_STATUS_OK;
}

static void ipc_write_done(struct tevent_req *subreq)
{
	struct ipc_write_state *state =
		tevent_req_callback_data(subreq,
		struct ipc_write_state);
	struct ntvfs_request *req = state->req;
	union smb_write *wr = state->wr;
	int ret;
	int sys_errno;
	NTSTATUS status;

	ret = tstream_writev_queue_recv(subreq, &sys_errno);
	TALLOC_FREE(subreq);
	if (ret == -1) {
		status = map_nt_error_from_unix_common(sys_errno);
		goto reply;
	}

	status = NT_STATUS_OK;

	wr->writex.out.nwritten = ret;
	wr->writex.out.remaining = 0;

reply:
	req->async_states->status = status;
	req->async_states->send_fn(req);
}

/*
  seek in a file
*/
static NTSTATUS ipc_seek(struct ntvfs_module_context *ntvfs,
			 struct ntvfs_request *req,
			 union smb_seek *io)
{
	return NT_STATUS_ACCESS_DENIED;
}

/*
  flush a file
*/
static NTSTATUS ipc_flush(struct ntvfs_module_context *ntvfs,
			  struct ntvfs_request *req,
			  union smb_flush *io)
{
	return NT_STATUS_ACCESS_DENIED;
}

/*
  close a file
*/
static NTSTATUS ipc_close(struct ntvfs_module_context *ntvfs,
			  struct ntvfs_request *req, union smb_close *io)
{
	struct ipc_private *ipriv = talloc_get_type_abort(ntvfs->private_data,
				    struct ipc_private);
	struct pipe_state *p;

	if (io->generic.level != RAW_CLOSE_CLOSE) {
		return ntvfs_map_close(ntvfs, req, io);
	}

	p = pipe_state_find(ipriv, io->close.in.file.ntvfs);
	if (!p) {
		return NT_STATUS_INVALID_HANDLE;
	}

	talloc_free(p);

	return NT_STATUS_OK;
}

/*
  exit - closing files
*/
static NTSTATUS ipc_exit(struct ntvfs_module_context *ntvfs,
			 struct ntvfs_request *req)
{
	struct ipc_private *ipriv = talloc_get_type_abort(ntvfs->private_data,
				    struct ipc_private);
	struct pipe_state *p, *next;
	
	for (p=ipriv->pipe_list; p; p=next) {
		next = p->next;
		if (p->handle->session_info == req->session_info &&
		    p->handle->smbpid == req->smbpid) {
			talloc_free(p);
		}
	}

	return NT_STATUS_OK;
}

/*
  logoff - closing files open by the user
*/
static NTSTATUS ipc_logoff(struct ntvfs_module_context *ntvfs,
			   struct ntvfs_request *req)
{
	struct ipc_private *ipriv = talloc_get_type_abort(ntvfs->private_data,
				    struct ipc_private);
	struct pipe_state *p, *next;
	
	for (p=ipriv->pipe_list; p; p=next) {
		next = p->next;
		if (p->handle->session_info == req->session_info) {
			talloc_free(p);
		}
	}

	return NT_STATUS_OK;
}

/*
  setup for an async call
*/
static NTSTATUS ipc_async_setup(struct ntvfs_module_context *ntvfs,
				struct ntvfs_request *req,
				void *private_data)
{
	return NT_STATUS_OK;
}

/*
  cancel an async call
*/
static NTSTATUS ipc_cancel(struct ntvfs_module_context *ntvfs,
			   struct ntvfs_request *req)
{
	return NT_STATUS_UNSUCCESSFUL;
}

/*
  lock a byte range
*/
static NTSTATUS ipc_lock(struct ntvfs_module_context *ntvfs,
			 struct ntvfs_request *req, union smb_lock *lck)
{
	return NT_STATUS_ACCESS_DENIED;
}

/*
  set info on a open file
*/
static NTSTATUS ipc_setfileinfo(struct ntvfs_module_context *ntvfs,
				struct ntvfs_request *req, union smb_setfileinfo *info)
{
	return NT_STATUS_ACCESS_DENIED;
}

/*
  query info on a open file
*/
static NTSTATUS ipc_qfileinfo(struct ntvfs_module_context *ntvfs,
			      struct ntvfs_request *req, union smb_fileinfo *info)
{
	struct ipc_private *ipriv = talloc_get_type_abort(ntvfs->private_data,
				    struct ipc_private);
	struct pipe_state *p = pipe_state_find(ipriv, info->generic.in.file.ntvfs);
	if (!p) {
		return NT_STATUS_INVALID_HANDLE;
	}
	switch (info->generic.level) {
	case RAW_FILEINFO_GENERIC: 
	{
		ZERO_STRUCT(info->generic.out);
		info->generic.out.attrib = FILE_ATTRIBUTE_NORMAL;
		info->generic.out.fname.s = strrchr(p->pipe_name, '\\');
		info->generic.out.alloc_size = 4096;
		info->generic.out.nlink = 1;
		/* What the heck?  Match Win2k3: IPC$ pipes are delete pending */
		info->generic.out.delete_pending = 1;
		return NT_STATUS_OK;
	}
	case RAW_FILEINFO_ALT_NAME_INFO:
	case RAW_FILEINFO_ALT_NAME_INFORMATION:
	case RAW_FILEINFO_STREAM_INFO:
	case RAW_FILEINFO_STREAM_INFORMATION:
	case RAW_FILEINFO_COMPRESSION_INFO:
	case RAW_FILEINFO_COMPRESSION_INFORMATION:
	case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:
	case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
		return NT_STATUS_INVALID_PARAMETER;
	case  RAW_FILEINFO_ALL_EAS:
		return NT_STATUS_ACCESS_DENIED;
	default:
		return ntvfs_map_qfileinfo(ntvfs, req, info);
	}
}


/*
  return filesystem info
*/
static NTSTATUS ipc_fsinfo(struct ntvfs_module_context *ntvfs,
			   struct ntvfs_request *req, union smb_fsinfo *fs)
{
	return NT_STATUS_ACCESS_DENIED;
}

/*
  return print queue info
*/
static NTSTATUS ipc_lpq(struct ntvfs_module_context *ntvfs,
			struct ntvfs_request *req, union smb_lpq *lpq)
{
	return NT_STATUS_ACCESS_DENIED;
}

/* 
   list files in a directory matching a wildcard pattern
*/
static NTSTATUS ipc_search_first(struct ntvfs_module_context *ntvfs,
			  struct ntvfs_request *req, union smb_search_first *io,
			  void *search_private, 
			  bool (*callback)(void *, const union smb_search_data *))
{
	return NT_STATUS_ACCESS_DENIED;
}

/* 
   continue listing files in a directory 
*/
static NTSTATUS ipc_search_next(struct ntvfs_module_context *ntvfs,
			 struct ntvfs_request *req, union smb_search_next *io,
			 void *search_private, 
			 bool (*callback)(void *, const union smb_search_data *))
{
	return NT_STATUS_ACCESS_DENIED;
}

/* 
   end listing files in a directory 
*/
static NTSTATUS ipc_search_close(struct ntvfs_module_context *ntvfs,
			  struct ntvfs_request *req, union smb_search_close *io)
{
	return NT_STATUS_ACCESS_DENIED;
}

struct ipc_trans_state {
	struct ipc_private *ipriv;
	struct pipe_state *p;
	struct ntvfs_request *req;
	struct smb_trans2 *trans;
	struct iovec writev_iov;
	struct ipc_readv_next_vector_state next_vector;
};

static void ipc_trans_writev_done(struct tevent_req *subreq);
static void ipc_trans_readv_done(struct tevent_req *subreq);

/* SMBtrans - handle a DCERPC command */
static NTSTATUS ipc_dcerpc_cmd(struct ntvfs_module_context *ntvfs,
			       struct ntvfs_request *req, struct smb_trans2 *trans)
{
	struct ipc_private *ipriv = talloc_get_type_abort(ntvfs->private_data,
				    struct ipc_private);
	struct pipe_state *p;
	DATA_BLOB fnum_key;
	uint16_t fnum;
	struct ipc_trans_state *state;
	struct tevent_req *subreq;

	/*
	 * the fnum is in setup[1], a 16 bit value
	 * the setup[*] values are already in host byteorder
	 * but ntvfs_handle_search_by_wire_key() expects
	 * network byteorder
	 */
	SSVAL(&fnum, 0, trans->in.setup[1]);
	fnum_key = data_blob_const(&fnum, 2);

	p = pipe_state_find_key(ipriv, req, &fnum_key);
	if (!p) {
		return NT_STATUS_INVALID_HANDLE;
	}

	/*
	 * Trans requests are only allowed
	 * if no other Trans or Read is active
	 */
	if (tevent_queue_length(p->read_queue) > 0) {
		return NT_STATUS_PIPE_BUSY;
	}

	state = talloc(req, struct ipc_trans_state);
	NT_STATUS_HAVE_NO_MEMORY(state);

	trans->out.setup_count = 0;
	trans->out.setup = NULL;
	trans->out.params = data_blob(NULL, 0);
	trans->out.data = data_blob_talloc(req, NULL, trans->in.max_data);
	NT_STATUS_HAVE_NO_MEMORY(trans->out.data.data);

	state->ipriv = ipriv;
	state->p = p;
	state->req = req;
	state->trans = trans;
	state->writev_iov.iov_base = (char *) trans->in.data.data;
	state->writev_iov.iov_len = trans->in.data.length;

	ipc_readv_next_vector_init(&state->next_vector,
				   trans->out.data.data,
				   trans->out.data.length);

	subreq = tstream_writev_queue_send(state,
					   ipriv->ntvfs->ctx->event_ctx,
					   p->npipe,
					   p->write_queue,
					   &state->writev_iov, 1);
	NT_STATUS_HAVE_NO_MEMORY(subreq);
	tevent_req_set_callback(subreq, ipc_trans_writev_done, state);

	req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC;
	return NT_STATUS_OK;
}

static void ipc_trans_writev_done(struct tevent_req *subreq)
{
	struct ipc_trans_state *state =
		tevent_req_callback_data(subreq,
		struct ipc_trans_state);
	struct ipc_private *ipriv = state->ipriv;
	struct pipe_state *p = state->p;
	struct ntvfs_request *req = state->req;
	int ret;
	int sys_errno;
	NTSTATUS status;

	ret = tstream_writev_queue_recv(subreq, &sys_errno);
	TALLOC_FREE(subreq);
	if (ret == 0) {
		status = NT_STATUS_PIPE_DISCONNECTED;
		goto reply;
	} else if (ret == -1) {
		status = map_nt_error_from_unix_common(sys_errno);
		goto reply;
	}

	subreq = tstream_readv_pdu_queue_send(state,
					      ipriv->ntvfs->ctx->event_ctx,
					      p->npipe,
					      p->read_queue,
					      ipc_readv_next_vector,
					      &state->next_vector);
	if (!subreq) {
		status = NT_STATUS_NO_MEMORY;
		goto reply;
	}
	tevent_req_set_callback(subreq, ipc_trans_readv_done, state);
	return;

reply:
	req->async_states->status = status;
	req->async_states->send_fn(req);
}

static void ipc_trans_readv_done(struct tevent_req *subreq)
{
	struct ipc_trans_state *state =
		tevent_req_callback_data(subreq,
		struct ipc_trans_state);
	struct ntvfs_request *req = state->req;
	struct smb_trans2 *trans = state->trans;
	int ret;
	int sys_errno;
	NTSTATUS status;

	ret = tstream_readv_pdu_queue_recv(subreq, &sys_errno);
	TALLOC_FREE(subreq);
	if (ret == -1) {
		status = map_nt_error_from_unix_common(sys_errno);
		goto reply;
	}

	status = NT_STATUS_OK;
	if (state->next_vector.remaining > 0) {
		status = STATUS_BUFFER_OVERFLOW;
	}

	trans->out.data.length = ret;

reply:
	req->async_states->status = status;
	req->async_states->send_fn(req);
}

/* SMBtrans - set named pipe state */
static NTSTATUS ipc_set_nm_pipe_state(struct ntvfs_module_context *ntvfs,
				      struct ntvfs_request *req, struct smb_trans2 *trans)
{
	struct ipc_private *ipriv = talloc_get_type_abort(ntvfs->private_data,
				    struct ipc_private);
	struct pipe_state *p;
	DATA_BLOB fnum_key;

	/* the fnum is in setup[1] */
	fnum_key = data_blob_const(&trans->in.setup[1], sizeof(trans->in.setup[1]));

	p = pipe_state_find_key(ipriv, req, &fnum_key);
	if (!p) {
		return NT_STATUS_INVALID_HANDLE;
	}

	if (trans->in.params.length != 2) {
		return NT_STATUS_INVALID_PARAMETER;
	}

	/*
	 * TODO: pass this to the tstream_npa logic
	 */
	p->device_state = SVAL(trans->in.params.data, 0);

	trans->out.setup_count = 0;
	trans->out.setup = NULL;
	trans->out.params = data_blob(NULL, 0);
	trans->out.data = data_blob(NULL, 0);

	return NT_STATUS_OK;
}


/* SMBtrans - used to provide access to SMB pipes */
static NTSTATUS ipc_trans(struct ntvfs_module_context *ntvfs,
				struct ntvfs_request *req, struct smb_trans2 *trans)
{
	NTSTATUS status;

	if (strequal(trans->in.trans_name, "\\PIPE\\LANMAN"))
		return ipc_rap_call(req, ntvfs->ctx->event_ctx, ntvfs->ctx->lp_ctx, trans);

       	if (trans->in.setup_count != 2) {
		return NT_STATUS_INVALID_PARAMETER;
	}

	switch (trans->in.setup[0]) {
	case TRANSACT_SETNAMEDPIPEHANDLESTATE:
		status = ipc_set_nm_pipe_state(ntvfs, req, trans);
		break;
	case TRANSACT_DCERPCCMD:
		status = ipc_dcerpc_cmd(ntvfs, req, trans);
		break;
	default:
		status = NT_STATUS_INVALID_PARAMETER;
		break;
	}

	return status;
}

struct ipc_ioctl_state {
	struct ipc_private *ipriv;
	struct pipe_state *p;
	struct ntvfs_request *req;
	union smb_ioctl *io;
	struct iovec writev_iov;
	struct ipc_readv_next_vector_state next_vector;
};

static void ipc_ioctl_writev_done(struct tevent_req *subreq);
static void ipc_ioctl_readv_done(struct tevent_req *subreq);

static NTSTATUS ipc_ioctl_smb2(struct ntvfs_module_context *ntvfs,
			       struct ntvfs_request *req, union smb_ioctl *io)
{
	struct ipc_private *ipriv = talloc_get_type_abort(ntvfs->private_data,
				    struct ipc_private);
	struct pipe_state *p;
	struct ipc_ioctl_state *state;
	struct tevent_req *subreq;

	switch (io->smb2.in.function) {
	case FSCTL_NAMED_PIPE_READ_WRITE:
		break;

	default:
		return NT_STATUS_FS_DRIVER_REQUIRED;
	}

	p = pipe_state_find(ipriv, io->smb2.in.file.ntvfs);
	if (!p) {
		return NT_STATUS_INVALID_HANDLE;
	}

	/*
	 * Trans requests are only allowed
	 * if no other Trans or Read is active
	 */
	if (tevent_queue_length(p->read_queue) > 0) {
		return NT_STATUS_PIPE_BUSY;
	}

	state = talloc(req, struct ipc_ioctl_state);
	NT_STATUS_HAVE_NO_MEMORY(state);

	io->smb2.out._pad	= 0;
	io->smb2.out.function	= io->smb2.in.function;
	io->smb2.out.unknown2	= 0;
	io->smb2.out.unknown3	= 0;
	io->smb2.out.in		= data_blob_null;
	io->smb2.out.out = data_blob_talloc(req, NULL, io->smb2.in.max_response_size);
	NT_STATUS_HAVE_NO_MEMORY(io->smb2.out.out.data);

	state->ipriv = ipriv;
	state->p = p;
	state->req = req;
	state->io = io;
	state->writev_iov.iov_base = (char *) io->smb2.in.out.data;
	state->writev_iov.iov_len = io->smb2.in.out.length;

	ipc_readv_next_vector_init(&state->next_vector,
				   io->smb2.out.out.data,
				   io->smb2.out.out.length);

	subreq = tstream_writev_queue_send(state,
					   ipriv->ntvfs->ctx->event_ctx,
					   p->npipe,
					   p->write_queue,
					   &state->writev_iov, 1);
	NT_STATUS_HAVE_NO_MEMORY(subreq);
	tevent_req_set_callback(subreq, ipc_ioctl_writev_done, state);

	req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC;
	return NT_STATUS_OK;
}

static void ipc_ioctl_writev_done(struct tevent_req *subreq)
{
	struct ipc_ioctl_state *state =
		tevent_req_callback_data(subreq,
		struct ipc_ioctl_state);
	struct ipc_private *ipriv = state->ipriv;
	struct pipe_state *p = state->p;
	struct ntvfs_request *req = state->req;
	int ret;
	int sys_errno;
	NTSTATUS status;

	ret = tstream_writev_queue_recv(subreq, &sys_errno);
	TALLOC_FREE(subreq);
	if (ret == -1) {
		status = map_nt_error_from_unix_common(sys_errno);
		goto reply;
	}

	subreq = tstream_readv_pdu_queue_send(state,
					      ipriv->ntvfs->ctx->event_ctx,
					      p->npipe,
					      p->read_queue,
					      ipc_readv_next_vector,
					      &state->next_vector);
	if (!subreq) {
		status = NT_STATUS_NO_MEMORY;
		goto reply;
	}
	tevent_req_set_callback(subreq, ipc_ioctl_readv_done, state);
	return;

reply:
	req->async_states->status = status;
	req->async_states->send_fn(req);
}

static void ipc_ioctl_readv_done(struct tevent_req *subreq)
{
	struct ipc_ioctl_state *state =
		tevent_req_callback_data(subreq,
		struct ipc_ioctl_state);
	struct ntvfs_request *req = state->req;
	union smb_ioctl *io = state->io;
	int ret;
	int sys_errno;
	NTSTATUS status;

	ret = tstream_readv_pdu_queue_recv(subreq, &sys_errno);
	TALLOC_FREE(subreq);
	if (ret == -1) {
		status = map_nt_error_from_unix_common(sys_errno);
		goto reply;
	}

	status = NT_STATUS_OK;
	if (state->next_vector.remaining > 0) {
		status = STATUS_BUFFER_OVERFLOW;
	}

	io->smb2.out.out.length = ret;

reply:
	req->async_states->status = status;
	req->async_states->send_fn(req);
}

/*
  ioctl interface
*/
static NTSTATUS ipc_ioctl(struct ntvfs_module_context *ntvfs,
			  struct ntvfs_request *req, union smb_ioctl *io)
{
	switch (io->generic.level) {
	case RAW_IOCTL_SMB2:
		return ipc_ioctl_smb2(ntvfs, req, io);

	case RAW_IOCTL_SMB2_NO_HANDLE:
		return NT_STATUS_FS_DRIVER_REQUIRED;

	default:
		return NT_STATUS_ACCESS_DENIED;
	}
}


/*
  initialialise the IPC backend, registering ourselves with the ntvfs subsystem
 */
NTSTATUS ntvfs_ipc_init(void)
{
	NTSTATUS ret;
	struct ntvfs_ops ops;
	NTVFS_CURRENT_CRITICAL_SIZES(vers);

	ZERO_STRUCT(ops);
	
	/* fill in the name and type */
	ops.name = "default";
	ops.type = NTVFS_IPC;

	/* fill in all the operations */
	ops.connect = ipc_connect;
	ops.disconnect = ipc_disconnect;
	ops.unlink = ipc_unlink;
	ops.chkpath = ipc_chkpath;
	ops.qpathinfo = ipc_qpathinfo;
	ops.setpathinfo = ipc_setpathinfo;
	ops.open = ipc_open;
	ops.mkdir = ipc_mkdir;
	ops.rmdir = ipc_rmdir;
	ops.rename = ipc_rename;
	ops.copy = ipc_copy;
	ops.ioctl = ipc_ioctl;
	ops.read = ipc_read;
	ops.write = ipc_write;
	ops.seek = ipc_seek;
	ops.flush = ipc_flush;	
	ops.close = ipc_close;
	ops.exit = ipc_exit;
	ops.lock = ipc_lock;
	ops.setfileinfo = ipc_setfileinfo;
	ops.qfileinfo = ipc_qfileinfo;
	ops.fsinfo = ipc_fsinfo;
	ops.lpq = ipc_lpq;
	ops.search_first = ipc_search_first;
	ops.search_next = ipc_search_next;
	ops.search_close = ipc_search_close;
	ops.trans = ipc_trans;
	ops.logoff = ipc_logoff;
	ops.async_setup = ipc_async_setup;
	ops.cancel = ipc_cancel;

	/* register ourselves with the NTVFS subsystem. */
	ret = ntvfs_register(&ops, &vers);

	if (!NT_STATUS_IS_OK(ret)) {
		DEBUG(0,("Failed to register IPC backend!\n"));
		return ret;
	}

	return ret;
}