Import ncpfs 2.0.1
This commit is contained in:
133
util/ncplib.c
133
util/ncplib.c
@@ -531,11 +531,13 @@ do_ncp_call(struct ncp_conn *conn, int request_size)
|
||||
int retries = 20;
|
||||
int len;
|
||||
long err;
|
||||
struct ncp_reply_header *r =
|
||||
(struct ncp_reply_header *)&(conn->packet);
|
||||
|
||||
while (retries > 0)
|
||||
{
|
||||
struct ncp_reply_header reply;
|
||||
struct sockaddr_ipx sender;
|
||||
int sizeofaddr = sizeof(sender);
|
||||
|
||||
retries -= 1;
|
||||
|
||||
result = sendto(conn->ncp_sock, conn->packet,
|
||||
@@ -549,30 +551,48 @@ do_ncp_call(struct ncp_conn *conn, int request_size)
|
||||
}
|
||||
|
||||
re_select:
|
||||
len = ipx_recv(conn->ncp_sock,
|
||||
conn->packet, NCP_PACKET_SIZE, 0, 3, &err);
|
||||
len = ipx_recvfrom(conn->ncp_sock,
|
||||
(char *)&reply, sizeof(reply),
|
||||
MSG_PEEK, &sender, &sizeofaddr, 3, &err);
|
||||
|
||||
if ( (len == sizeof(*r))
|
||||
&& (r->type == NCP_POSITIVE_ACK))
|
||||
if ((len < 0) && (err == ETIMEDOUT))
|
||||
{
|
||||
goto re_select;
|
||||
}
|
||||
if ( (len >= sizeof(*r))
|
||||
&& (r->type == NCP_REPLY)
|
||||
&& ( (request.type == NCP_ALLOC_SLOT_REQUEST)
|
||||
|| ( (r->sequence == request.sequence)
|
||||
&& (r->conn_low == request.conn_low)
|
||||
&& (r->conn_high == request.conn_high))))
|
||||
{
|
||||
conn->reply_size = len;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
if (len < 0)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
|
||||
if ( /* Is the sender wrong? */
|
||||
(memcmp(&sender.sipx_node,
|
||||
&(conn->i.addr.sipx_node), 6) != 0)
|
||||
|| (sender.sipx_port != conn->i.addr.sipx_port)
|
||||
|
||||
/* Did the sender send a positive acknowledge? */
|
||||
|| ( (len == sizeof(reply))
|
||||
&& (reply.type == NCP_POSITIVE_ACK))
|
||||
|
||||
/* Did we get a bogus answer? */
|
||||
|| ( (len < sizeof(reply))
|
||||
|| (reply.type != NCP_REPLY)
|
||||
|| ( (request.type != NCP_ALLOC_SLOT_REQUEST)
|
||||
&& ( (reply.sequence != request.sequence)
|
||||
|| (reply.conn_low != request.conn_low)
|
||||
|| (reply.conn_high != request.conn_high)))))
|
||||
{
|
||||
/* Then throw away the packet */
|
||||
ipx_recv(conn->ncp_sock, (char *)&reply, sizeof(reply),
|
||||
0, 1, &err);
|
||||
goto re_select;
|
||||
}
|
||||
|
||||
ipx_recv(conn->ncp_sock, conn->packet, NCP_PACKET_SIZE,
|
||||
0, 1, &err);
|
||||
conn->reply_size = len;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
return ETIMEDOUT;
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -590,8 +610,9 @@ ncp_mount_request(struct ncp_conn *conn, int function)
|
||||
|
||||
if (conn->has_subfunction != 0)
|
||||
{
|
||||
*(__u16 *)&(h->data[0]) = conn->current_size
|
||||
- sizeof(struct ncp_request_header)- 2;
|
||||
*(__u16 *)&(h->data[0])
|
||||
= htons(conn->current_size
|
||||
- sizeof(struct ncp_request_header) - 2);
|
||||
}
|
||||
|
||||
request.function = function;
|
||||
@@ -628,8 +649,9 @@ ncp_temp_request(struct ncp_conn *conn, int function)
|
||||
|
||||
if (conn->has_subfunction != 0)
|
||||
{
|
||||
*(__u16 *)&(h->data[0]) = conn->current_size
|
||||
- sizeof(struct ncp_request_header) - 2;
|
||||
*(__u16 *)&(h->data[0])
|
||||
= htons(conn->current_size
|
||||
- sizeof(struct ncp_request_header) - 2);
|
||||
}
|
||||
|
||||
h->type = NCP_REQUEST;
|
||||
@@ -2593,7 +2615,42 @@ ncp_delete_directory(struct ncp_conn *conn,
|
||||
ncp_unlock_conn(conn);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
long
|
||||
ncp_add_trustee(struct ncp_conn *conn,
|
||||
int dir_handle, const char *path,
|
||||
__u32 object_id, __u8 rights)
|
||||
{
|
||||
long result;
|
||||
|
||||
ncp_init_request_s(conn, 13);
|
||||
ncp_add_byte(conn, dir_handle);
|
||||
ncp_add_dword(conn, htonl(object_id));
|
||||
ncp_add_byte(conn, rights);
|
||||
ncp_add_pstring(conn, path);
|
||||
|
||||
result = ncp_request(conn, 22);
|
||||
ncp_unlock_conn(conn);
|
||||
return result;
|
||||
}
|
||||
|
||||
long
|
||||
ncp_delete_trustee(struct ncp_conn *conn,
|
||||
int dir_handle, const char *path,__u32 object_id)
|
||||
{
|
||||
long result;
|
||||
|
||||
ncp_init_request_s(conn, 14);
|
||||
ncp_add_byte(conn, dir_handle);
|
||||
ncp_add_dword(conn, htonl(object_id));
|
||||
ncp_add_byte(conn, 0);
|
||||
ncp_add_pstring(conn, path);
|
||||
|
||||
result = ncp_request(conn, 22);
|
||||
ncp_unlock_conn(conn);
|
||||
return result;
|
||||
}
|
||||
|
||||
long
|
||||
ncp_rename_directory(struct ncp_conn *conn,
|
||||
int dir_handle,
|
||||
@@ -3239,3 +3296,33 @@ ncp_alloc_short_dir_handle(struct ncp_conn *conn,
|
||||
ncp_unlock_conn(conn);
|
||||
return result;
|
||||
}
|
||||
|
||||
long
|
||||
ncp_add_trustee_set(struct ncp_conn *conn,
|
||||
__u8 volume_number, __u32 dir_entry,
|
||||
__u16 rights_mask,
|
||||
int object_count, struct ncp_trustee_struct *rights)
|
||||
{
|
||||
long result = 0;
|
||||
|
||||
ncp_init_request(conn);
|
||||
ncp_add_byte(conn, 10); /* subfunction */
|
||||
ncp_add_byte(conn, 0); /* dos name space */
|
||||
ncp_add_byte(conn, 0); /* reserved */
|
||||
ncp_add_word(conn, 0x8006);
|
||||
ncp_add_word(conn, rights_mask);
|
||||
ncp_add_word(conn, object_count);
|
||||
ncp_add_handle_path(conn, volume_number, dir_entry, 1, NULL);
|
||||
|
||||
while (object_count > 0)
|
||||
{
|
||||
ncp_add_dword(conn, htonl(rights->object_id));
|
||||
ncp_add_word(conn, rights->rights);
|
||||
object_count -= 1;
|
||||
rights += 1;
|
||||
}
|
||||
|
||||
result = ncp_request(conn, 87);
|
||||
ncp_unlock_conn(conn);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user