2 Unix SMB/Netbios implementation.
4 SMB agent/socket plugin
5 Copyright (C) Andrew Tridgell 1999
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "rpc_parse.h"
26 extern int DEBUGLEVEL
;
28 static char packet
[BUFFER_SIZE
];
30 /****************************************************************************
31 terminate sockent connection
32 ****************************************************************************/
33 static void free_sock(void *sock
)
37 struct msrpc_local
*n
= (struct msrpc_local
*)sock
;
38 msrpc_use_del(n
->pipe_name
, False
, NULL
);
42 static struct msrpc_local
*init_client_connection(int c
)
49 struct msrpc_local
*n
= NULL
;
56 DEBUG(10,("init_client_connection: first request\n"));
58 rl
= read(c
, &buf
, sizeof(len
));
60 if (rl
!= sizeof(len
))
62 DEBUG(0,("Unable to read length\n"));
63 dump_data(0, buf
, sizeof(len
));
69 if (len
> sizeof(buf
))
71 DEBUG(0,("length %d too long\n", len
));
75 rl
= read(c
, buf
, len
);
79 DEBUG(0,("Unable to read from connection\n"));
84 dump_data(100, buf
, rl
);
87 /* make a static data parsing structure from the api_fd_reply data */
88 prs_create(&ps
, buf
, len
, 4, True
);
90 if (!creds_io_cmd("creds", &cmd
, &ps
, 0))
92 DEBUG(0,("Unable to parse credentials\n"));
101 DEBUG(0,("Buffer size %d %d!\n", ps
.offset
, rl
));
108 case AGENT_CMD_CON_ANON
:
113 case AGENT_CMD_CON_REUSE
:
120 DEBUG(0,("unknown command %d\n", cmd
.command
));
128 n
= msrpc_use_add(pipe_name
, &cmd
.key
, False
);
132 DEBUG(0,("Unable to connect to %s\n", pipe_name
));
137 fstrcpy(n
->pipe_name
, pipe_name
);
140 if (write(c
, &status
, sizeof(status
)) != sizeof(status
))
142 DEBUG(0,("Could not write connection down pipe.\n"));
145 msrpc_use_del(pipe_name
, False
, NULL
);
153 static BOOL
process_cli_sock(struct sock_redir
**socks
, uint32 num_socks
,
154 struct sock_redir
*sock
)
156 struct msrpc_local
*n
= (struct msrpc_local
*)sock
->n
;
159 n
= init_client_connection(sock
->c
);
169 if (!receive_smb(sock
->c
, packet
, 0))
171 DEBUG(0,("client closed connection\n"));
175 if (!send_smb(sock
->s
, packet
))
177 DEBUG(0,("server is dead\n"));
184 static BOOL
process_srv_sock(struct sock_redir
**socks
, uint32 num_socks
,
188 if (!receive_smb(fd
, packet
, 0))
190 DEBUG(0,("server closed connection\n"));
194 DEBUG(10,("process_srv_sock:\tfd:\t%d\n", fd
));
196 for (i
= 0; i
< num_socks
; i
++)
198 struct msrpc_local
*n
;
199 if (socks
[i
] == NULL
|| socks
[i
]->n
== NULL
)
203 n
= (struct msrpc_local
*)socks
[i
]->n
;
204 DEBUG(10,("list:\tfd:\t%d\n",
206 if (!send_smb(socks
[i
]->c
, packet
))
208 DEBUG(0,("client is dead\n"));
216 static int get_agent_sock(char *pipe_name
)
221 slprintf(dir
, sizeof(dir
)-1, "/tmp/.msrpc/.%s", pipe_name
);
222 slprintf(path
, sizeof(path
)-1, "%s/agent", dir
);
224 return create_pipe_socket(dir
, S_IRUSR
|S_IWUSR
|S_IXUSR
, path
, 0);
227 void start_msrpc_agent(char *pipe_name
)
229 struct vagent_ops va
=