2 * Server-side symbolic link object management
4 * Copyright (C) 2005 Vitaliy Margolen
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
29 #include <sys/types.h>
32 #define WIN32_NO_STATUS
43 struct object obj
; /* object header */
44 WCHAR
*target
; /* target of the symlink */
45 size_t len
; /* target len in bytes */
48 static void symlink_dump( struct object
*obj
, int verbose
);
49 static struct object
*symlink_lookup_name( struct object
*obj
, struct unicode_str
*name
,
51 static void symlink_destroy( struct object
*obj
);
53 static const struct object_ops symlink_ops
=
55 sizeof(struct symlink
), /* size */
56 symlink_dump
, /* dump */
57 no_add_queue
, /* add_queue */
58 NULL
, /* remove_queue */
61 no_signal
, /* signal */
62 no_get_fd
, /* get_fd */
63 symlink_lookup_name
, /* lookup_name */
64 no_close_handle
, /* close_handle */
65 symlink_destroy
/* destroy */
68 static void symlink_dump( struct object
*obj
, int verbose
)
70 struct symlink
*symlink
= (struct symlink
*)obj
;
71 assert( obj
->ops
== &symlink_ops
);
73 fprintf( stderr
, "Symlink " );
74 dump_object_name( obj
);
75 fprintf( stderr
, " -> L\"" );
76 dump_strW( symlink
->target
, symlink
->len
/ sizeof(WCHAR
), stderr
, "\"\"" );
77 fprintf( stderr
, "\"\n" );
80 static struct object
*symlink_lookup_name( struct object
*obj
, struct unicode_str
*name
,
83 struct symlink
*symlink
= (struct symlink
*)obj
;
84 struct unicode_str target_str
, name_left
;
85 struct object
*target
;
87 assert( obj
->ops
== &symlink_ops
);
88 if (attr
& OBJ_OPENLINK
) return NULL
;
90 target_str
.str
= symlink
->target
;
91 target_str
.len
= symlink
->len
;
92 if ((target
= find_object_dir( NULL
, &target_str
, attr
, &name_left
)))
96 release_object( target
);
98 set_error( STATUS_OBJECT_PATH_NOT_FOUND
);
104 static void symlink_destroy( struct object
*obj
)
106 struct symlink
*symlink
= (struct symlink
*)obj
;
107 assert( obj
->ops
== &symlink_ops
);
108 free( symlink
->target
);
111 struct symlink
*create_symlink( struct directory
*root
, const struct unicode_str
*name
,
112 unsigned int attr
, const struct unicode_str
*target
)
114 struct symlink
*symlink
;
118 set_error( STATUS_INVALID_PARAMETER
);
121 if ((symlink
= create_named_object_dir( root
, name
, attr
, &symlink_ops
)) &&
122 (get_error() != STATUS_OBJECT_NAME_EXISTS
))
124 if ((symlink
->target
= memdup( target
->str
, target
->len
)))
125 symlink
->len
= target
->len
;
128 release_object( symlink
);
136 /* create a symbolic link object */
137 DECL_HANDLER(create_symlink
)
139 struct symlink
*symlink
;
140 struct unicode_str name
, target
;
141 struct directory
*root
= NULL
;
143 if (req
->name_len
> get_req_data_size())
145 set_error( STATUS_INVALID_PARAMETER
);
148 name
.str
= get_req_data();
149 target
.str
= name
.str
+ req
->name_len
/ sizeof(WCHAR
);
150 name
.len
= (target
.str
- name
.str
) * sizeof(WCHAR
);
151 target
.len
= ((get_req_data_size() - name
.len
) / sizeof(WCHAR
)) * sizeof(WCHAR
);
153 if (req
->rootdir
&& !(root
= get_directory_obj( current
->process
, req
->rootdir
, 0 )))
156 if ((symlink
= create_symlink( root
, &name
, req
->attributes
, &target
)))
158 reply
->handle
= alloc_handle( current
->process
, symlink
, req
->access
,
159 req
->attributes
& OBJ_INHERIT
);
160 release_object( symlink
);
163 if (root
) release_object( root
);
166 /* open a symbolic link object */
167 DECL_HANDLER(open_symlink
)
169 struct unicode_str name
;
170 struct directory
*root
= NULL
;
172 get_req_unicode_str( &name
);
173 if (req
->rootdir
&& !(root
= get_directory_obj( current
->process
, req
->rootdir
, 0 )))
176 reply
->handle
= open_object_dir( root
, &name
, req
->attributes
| OBJ_OPENLINK
,
177 &symlink_ops
, req
->access
);
179 if (root
) release_object( root
);
182 /* query a symbolic link object */
183 DECL_HANDLER(query_symlink
)
185 struct symlink
*symlink
;
187 symlink
= (struct symlink
*)get_handle_obj( current
->process
, req
->handle
,
188 SYMBOLIC_LINK_QUERY
, &symlink_ops
);
189 if (!symlink
) return;
191 if (get_reply_max_size() < symlink
->len
)
192 set_error( STATUS_BUFFER_TOO_SMALL
);
194 set_reply_data( symlink
->target
, symlink
->len
);
195 release_object( symlink
);