+Error text: Failed to remove (non-recursive removal) directory "%s": %m
[captive.git] / src / libcaptive / sandbox / split.c
1 /* $Id$
2  * Connection of captive-vfs interface through CORBA/ORBit
3  * Copyright (C) 2002-2005 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "split.h"      /* self */
23 #include "sandbox.h"
24 #include "server-GLogFunc.h"
25 #include "captive/macros.h"
26 #include <glib/gmacros.h>
27 #include <stdlib.h>
28 #include "captive/rtl-file.h"
29 #include <unistd.h>
30 #include <fcntl.h>
31 #include "server-Directory.h"
32 #include "server-Vfs.h"
33 #include "../client/vfs.h"
34 #include "parent-Vfs.h"
35 #include <dirent.h>
36 #include "server-CaptiveIOChannel.h"
37 #include <errno.h>
38 #include "../client/giochannel-blind.h" /* for captive_giochannel_blind_new() */
39 #include <signal.h>
40 #include "../storage/relastblock.h"     /* for captive_storage_relastblock() */
41 #include <sys/file.h>   /* flock() */
42
43 #ifdef HAVE_ORBIT_LINK
44 void link_set_tmpdir(const char *dir);
45 #else
46 #include <linc/linc.h>  /* for linc_main_get_loop() */
47 #endif
48
49
50 /* CONFIG: */
51
52 #define HEARTBEAT_SOURCE_CHECK_EVENTS (G_IO_IN|G_IO_PRI)
53 #define HEARTBEAT_SOURCE_CHECK_REVENTS (HEARTBEAT_SOURCE_CHECK_EVENTS|G_IO_ERR|G_IO_HUP|G_IO_NVAL)
54
55
56 gboolean validate_CORBA_Environment(CORBA_Environment *evp)
57 {
58         if (evp->_major==CORBA_NO_EXCEPTION)
59                 return TRUE;
60
61         g_error(_("CORBA Exception occured: id=\"%s\", value=%p"),
62                         CORBA_exception_id(evp),CORBA_exception_value(evp));
63         CORBA_exception_free(evp);
64         return FALSE;
65 }
66
67 CORBA_Environment captive_corba_ev;
68 CORBA_ORB captive_corba_orb;
69 PortableServer_POA captive_corba_poa;
70
71 static void corba_shutdown_atexit(void);
72
73 static gboolean corba_init(const char *pname,CORBA_Environment *evp,CORBA_ORB *orbp,PortableServer_POA *poap)
74 {
75 static gboolean done=FALSE;
76 int orb_argc=1;
77 gchar *orb_argv[]={
78                 (gchar *)captive_strdup_alloca(pname),
79                 NULL};
80
81         g_return_val_if_fail(evp!=NULL,FALSE);
82         g_return_val_if_fail(orbp!=NULL,FALSE);
83         g_return_val_if_fail(poap!=NULL,FALSE);
84
85         if (done)
86                 return TRUE;    /* FIXME: '*poap' is left invalid! */
87
88         /* Init 'ev' */
89         CORBA_exception_init(evp);
90
91         /* Init 'orb' */
92         /* libcaptive is single-threaded only, caller must lock it.
93          * If thread A spawned the sandbox while currently doing its own work
94          * and thread B calls the sandbox thread B waits on ORB_run()
95          * while the sandbox waits for the response of thread A ORB. Deadlock.
96          * "orbit-local-non-threaded-orb" requests thread unaware ORB.
97          */
98         *orbp=CORBA_ORB_init(&orb_argc,orb_argv,"orbit-local-non-threaded-orb",evp);
99         g_return_val_if_fail(*orbp!=CORBA_OBJECT_NIL,FALSE);
100         g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
101
102         /* Init 'poa' */
103         *poap=(PortableServer_POA)CORBA_ORB_resolve_initial_references(*orbp,"RootPOA",evp);
104         g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
105         {
106 PortableServer_POAManager poa_mgr;
107                 poa_mgr=PortableServer_POA__get_the_POAManager(*poap,evp);
108                 g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
109                 PortableServer_POAManager_activate(poa_mgr,evp);
110                 g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
111                 CORBA_Object_release((CORBA_Object)poa_mgr,evp);
112                 g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
113                 }
114
115         g_atexit(corba_shutdown_atexit);
116
117         done=TRUE;
118         return TRUE;
119 }
120
121
122 static CORBA_ORB heartbeat_source_callback_orb=CORBA_OBJECT_NIL;
123
124 gboolean corba_shutdown(CORBA_Environment *evp,CORBA_ORB *orbp,PortableServer_POA *poap)
125 {
126 PortableServer_POA poa;
127 CORBA_ORB orb;
128
129         g_return_val_if_fail(evp!=NULL,FALSE);
130         g_return_val_if_fail(orbp!=NULL,FALSE);
131         g_return_val_if_fail(poap!=NULL,FALSE);
132
133         /* Shutdown 'poa' */
134         poa=*poap;
135         *poap=CORBA_OBJECT_NIL;
136         CORBA_Object_release((CORBA_Object)poa,evp);
137         g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
138
139         /* Shutdown 'orb' */
140         orb=*orbp;
141         *orbp=CORBA_OBJECT_NIL;
142         heartbeat_source_callback_orb=CORBA_OBJECT_NIL;
143         CORBA_ORB_destroy(orb,evp);
144         /* Do not: g_return_val_if_fail(validate_CORBA_Environment(evp),FALSE);
145          * here as CORBA_ORB_destroy() sometimes reports:
146          *      WARNING **: ORB: a total of X refs to X ORB objects were leaked
147          */
148         CORBA_exception_free(evp);
149
150         /* Shutdown 'ev' */
151         CORBA_exception_free(evp);
152
153         return TRUE;
154 }
155
156 static void sandbox_parent_own_orbit_dir_cleanup_atexit(void);
157
158 static void corba_shutdown_atexit(void)
159 {
160 gboolean errbool;
161
162         errbool=corba_shutdown(&captive_corba_ev,&captive_corba_orb,&captive_corba_poa);
163         g_assert(errbool==TRUE);
164
165         /* Delete the CORBA ORB socket directory only after full CORBA ORB shutdown. */
166         sandbox_parent_own_orbit_dir_cleanup_atexit();
167 }
168
169
170 static GSource *captive_corba_sandbox_child_heartbeat_gsource;
171
172 #if 0   /* Currently unused - see server-Vfs.c:impl_Captive_Vfs_shutdown() */
173 void sandbox_child_prepare_shutdown(void)
174 {
175         /* Prevent during shutdown: Captive-WARNING **: CORBA Exception occured: id="IDL:omg.org/CORBA/COMM_FAILURE:1.0" */
176         if (captive_corba_sandbox_child_heartbeat_gsource) {
177                 g_source_destroy(captive_corba_sandbox_child_heartbeat_gsource);
178                 g_source_unref(captive_corba_sandbox_child_heartbeat_gsource);
179                 captive_corba_sandbox_child_heartbeat_gsource=NULL;
180                 }
181 }
182 #endif
183
184 GMainLoop *captive_corba_get_loop(void)
185 {
186 #ifdef HAVE_ORBIT_LINK
187 static GMainLoop *link_loop;
188
189         if (!link_loop)
190                 link_loop=g_main_loop_new(g_main_context_default(),TRUE);
191         return link_loop;
192 #else
193         return linc_main_get_loop();
194 #endif
195 }
196
197 GMainContext *captive_corba_get_context(void)
198 {
199         return g_main_loop_get_context(captive_corba_get_loop());
200 }
201
202 void sandbox_child_shutdown(void)
203 {
204         /* Do not fail by passing logging messages to the master. */
205         impl_Captive_Vfs_init_g_log_func_disable();
206
207         g_main_loop_quit(captive_corba_get_loop());
208 }
209
210
211 static gboolean heartbeat_source_callback(gpointer data /* unused */)
212 {
213         g_return_val_if_fail(heartbeat_source_callback_orb!=CORBA_OBJECT_NIL,FALSE);    /* the source should be removed */
214
215         sandbox_child_shutdown();
216
217         return FALSE;   /* the source should be removed */
218 }
219
220
221 static gboolean heartbeat_source_prepare(GSource *source,gint *timeout)
222 {
223         *timeout=-1;
224
225         return FALSE;
226 }
227
228 static GPollFD heartbeat_source_check_gpollfd;
229
230 static gboolean heartbeat_source_check(GSource *source)
231 {
232         return !!(heartbeat_source_check_gpollfd.revents & HEARTBEAT_SOURCE_CHECK_REVENTS);
233 }
234
235 static gboolean heartbeat_source_dispatch(GSource *source,GSourceFunc callback,gpointer user_data)
236 {
237         g_assert(callback!=NULL);
238         return (*callback)(user_data);
239 }
240
241 static GSourceFuncs heartbeat_source_watch_funcs={
242                 heartbeat_source_prepare,
243                 heartbeat_source_check,
244                 heartbeat_source_dispatch,
245                 NULL,   /* finalize */
246                 };
247
248 void captive_corba_sandbox_child(const gchar *chrooted_orbit_dir)
249 {
250 Captive_Vfs Vfs_object;
251 impl_POA_Captive_Vfs *Vfs_servant;
252 gboolean errbool;
253 guint errguint;
254 int errint;
255
256         /* attach heartbeat_source_callback() to watch for any abnormalities
257          * on our open pipe 'parentheart_fds' and terminate the child if parent dies.
258          */
259         captive_corba_sandbox_child_heartbeat_gsource=g_source_new(&heartbeat_source_watch_funcs,sizeof(GSource));
260         g_return_if_fail(captive_corba_sandbox_child_heartbeat_gsource!=NULL);
261         g_source_set_callback(
262                         captive_corba_sandbox_child_heartbeat_gsource,  /* source */
263                         heartbeat_source_callback,      /* func */
264                         NULL,   /* data */
265                         NULL);  /* notify */
266         heartbeat_source_check_gpollfd.fd=0 /* STDIN */;        /* parentheart_fd_read */
267         heartbeat_source_check_gpollfd.events=HEARTBEAT_SOURCE_CHECK_EVENTS;
268         heartbeat_source_check_gpollfd.revents=0;
269         g_source_add_poll(captive_corba_sandbox_child_heartbeat_gsource,&heartbeat_source_check_gpollfd);
270
271         errbool=corba_init("captive-sandbox-child",&captive_corba_ev,&captive_corba_orb,&captive_corba_poa);
272         g_return_if_fail(errbool==TRUE);
273
274         heartbeat_source_callback_orb=captive_corba_orb;
275
276         /* captive_corba_get_context() makes sense only after corba_init() -> CORBA_ORB_init() */
277         errguint=g_source_attach(
278                         captive_corba_sandbox_child_heartbeat_gsource,  /* source */
279                         captive_corba_get_context());   /* context; NULL means 'default context' */
280         g_assert(errguint!=0);
281
282         /* Init 'Vfs_object' */
283         Vfs_object=impl_Captive_Vfs__create(captive_corba_poa,&captive_corba_ev);
284         g_assert(validate_CORBA_Environment(&captive_corba_ev));
285
286         /* Pass IOR to our parent.
287          * It will also create the socket needed for 'chrooted_orbit_dir' below
288          * by CORBA_ORB_object_to_string()->ORBit_marshal_object()->IOP_generate_profiles()->ORBit_ORB_start_servers...
289          */
290         {
291 char *Vfs_IOR;
292                 Vfs_IOR=CORBA_ORB_object_to_string(captive_corba_orb,Vfs_object,&captive_corba_ev);
293                 g_assert(validate_CORBA_Environment(&captive_corba_ev));
294                 g_assert(Vfs_IOR!=NULL);
295                 errint=printf("ior=%s\n",Vfs_IOR);
296                 g_assert(errint>=0);
297                 CORBA_free(Vfs_IOR);
298                 }
299
300         /* Default mode is 0700, permit parent non-"captive" users to access our IOR socket. */
301         if (chrooted_orbit_dir) {
302 DIR *dir;
303 struct dirent *dirent;
304 const gchar *socketname=NULL,*socketpathname;
305
306                 errint=chmod(chrooted_orbit_dir,0755);
307                 g_assert(errint==0);
308
309                 dir=opendir(chrooted_orbit_dir);
310                 g_assert(dir!=NULL);
311                 while (errno=0,(dirent=readdir(dir))) {
312                         if (!strcmp(dirent->d_name,".") || !strcmp(dirent->d_name,".."))
313                                 continue;
314                         g_assert(socketname==NULL);
315                         socketname=captive_strdup_alloca(dirent->d_name);
316                         }
317                 g_assert(errno==0);
318                 errint=closedir(dir);
319                 g_assert(errint==0);
320                 g_assert(socketname!=NULL);
321
322                 socketpathname=captive_printf_alloca("%s/%s",chrooted_orbit_dir,socketname);
323                 errint=chmod(socketpathname,0666);
324                 g_assert(errint==0);
325
326                 printf("socketname=%s\n",socketname);
327                 }
328
329         /* Close the output to flush it to our spawning parent. */
330         errint=fflush(stdout);
331         g_assert(errint==0);
332         errint=fclose(stdout);
333         g_assert(errint==0);
334
335         /* CORBA_ORB_run() -> linc_main_loop_run() -> g_main_loop_run()
336          * and therefore we should be safe with glib events handling.
337          */
338 #ifdef HAVE_ORBIT_LINK
339         g_main_loop_run(captive_corba_get_loop());
340 #else
341         CORBA_ORB_run(captive_corba_orb,&captive_corba_ev);
342         g_assert(validate_CORBA_Environment(&captive_corba_ev));
343 #endif
344
345         /* Shutdown 'Vfs' servant */
346         Vfs_servant=PortableServer_POA_reference_to_servant(captive_corba_poa,Vfs_object,&captive_corba_ev);
347         g_assert(validate_CORBA_Environment(&captive_corba_ev));
348         CORBA_Object_release(Vfs_object,&captive_corba_ev);
349         g_assert(validate_CORBA_Environment(&captive_corba_ev));
350         impl_Captive_Vfs__destroy(Vfs_servant,&captive_corba_ev);
351         g_assert(validate_CORBA_Environment(&captive_corba_ev));
352
353         errbool=corba_shutdown(&captive_corba_ev,&captive_corba_orb,&captive_corba_poa);
354         g_assert(errbool==TRUE);
355
356         _exit(EXIT_SUCCESS);
357 }
358
359
360 static void options_module_captive_to_options_module_corba
361                 (Captive_CaptiveOptionsModule *dest_options_module_corba,const struct captive_options_module *src_options_module_captive)
362 {
363         g_return_if_fail(dest_options_module_corba!=NULL);
364         g_return_if_fail(src_options_module_captive!=NULL);
365
366         g_return_if_fail(src_options_module_captive->type==CAPTIVE_OPTIONS_MODULE_TYPE_PE32);
367
368         dest_options_module_corba->pathname_utf8=CORBA_string_dup(src_options_module_captive->pathname_utf8);
369         dest_options_module_corba->data._maximum=src_options_module_captive->u.pe32.length;
370         dest_options_module_corba->data._length =src_options_module_captive->u.pe32.length;
371         dest_options_module_corba->data._buffer=Captive_Bytes_allocbuf(dest_options_module_corba->data._maximum);
372         memcpy(dest_options_module_corba->data._buffer,src_options_module_captive->u.pe32.base,
373                         src_options_module_captive->u.pe32.length);
374         dest_options_module_corba->data._release=TRUE;
375 }
376
377 static void unlink_nonrecursive(const gchar *dirname)
378 {
379 DIR *dir;
380 struct dirent *dirent;
381 int errint;
382
383         dir=opendir(dirname);
384         if (!dir)
385                 g_error(_("Failed to check for non-recursive removal directory \"%s\": %m"),dirname);
386
387         while (errno=0,(dirent=readdir(dir))) {
388 gchar *pathname;
389
390                 if (!strcmp(dirent->d_name,".") || !strcmp(dirent->d_name,".."))
391                         continue;
392                 pathname=g_strdup_printf("%s/%s",dirname,dirent->d_name);
393                 errint=unlink(pathname);
394                 g_assert(errint==0);
395                 g_free(pathname);
396                 }
397         g_assert(errno==0);
398         errint=closedir(dir);
399         g_assert(errint==0);
400         errint=rmdir(dirname);
401         if (errint)
402                 g_error(_("Failed to remove (non-recursive removal) directory \"%s\": %m"),dirname);
403 }
404
405 static const gchar *sandbox_parent_own_orbit_dir;
406 static const gchar *sandbox_parent_own_orbit_socket;
407
408 static void sandbox_parent_own_orbit_dir_cleanup_atexit(void)
409 {
410 static gboolean done=FALSE;
411
412         g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"%s; done=%d",G_STRLOC,(int)done);
413
414         if (done)
415                 return;
416         done=TRUE;
417
418         if (sandbox_parent_own_orbit_dir)
419                 unlink_nonrecursive(sandbox_parent_own_orbit_dir);
420 }
421
422 static struct sandbox_parent_own_orbit_dir_cleanup_signal {
423         int signum;
424         /* FIXME: Why we cannot use 'sighandler_t'? */ void (*sighandler_orig)(int signum);
425         } sandbox_parent_own_orbit_dir_cleanup_signals[]={
426                 { SIGINT  },
427                 { SIGQUIT },
428                 { SIGTERM },
429                 { SIGHUP  },
430                 { SIGABRT },
431                 { SIGFPE  },
432                 };
433
434 static void sandbox_parent_own_orbit_dir_cleanup_sighandler(int signum)
435 {
436 struct sandbox_parent_own_orbit_dir_cleanup_signal *sigstructp;
437
438         for (
439                         sigstructp=sandbox_parent_own_orbit_dir_cleanup_signals;
440                         sigstructp<sandbox_parent_own_orbit_dir_cleanup_signals+G_N_ELEMENTS(sandbox_parent_own_orbit_dir_cleanup_signals);
441                         sigstructp++) {
442                 if (sigstructp->signum==signum)
443                         break;
444                 }
445         g_assert(sigstructp<sandbox_parent_own_orbit_dir_cleanup_signals+G_N_ELEMENTS(sandbox_parent_own_orbit_dir_cleanup_signals));
446         signal(signum,sigstructp->sighandler_orig);
447
448         /* Prevent recursive fatal logging before signal restore: */
449         /* Do not: g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"%s: signum=%d,sighandler_orig=%p",G_STRLOC,signum,sigstructp->sighandler_orig);
450          * as it is dangerous to g_log() from sighandler.
451          */
452
453         sandbox_parent_own_orbit_dir_cleanup_atexit();
454
455         /* Do not: g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"%s: re-raising...",G_STRLOC);
456          * as it is dangerous to g_log() from sighandler.
457          */
458         raise(signum);
459 }
460
461 static void sandbox_parent_own_orbit_dir_cleanup_init(void)
462 {
463 struct sandbox_parent_own_orbit_dir_cleanup_signal *sigstructp;
464
465         for (
466                         sigstructp=sandbox_parent_own_orbit_dir_cleanup_signals;
467                         sigstructp<sandbox_parent_own_orbit_dir_cleanup_signals+G_N_ELEMENTS(sandbox_parent_own_orbit_dir_cleanup_signals);
468                         sigstructp++) {
469                 sigstructp->sighandler_orig=signal(sigstructp->signum,sandbox_parent_own_orbit_dir_cleanup_sighandler);
470                 if (sigstructp->sighandler_orig==SIG_IGN)
471                         sigstructp->sighandler_orig=SIG_DFL;
472                 }
473 }
474
475 static void createlockdir(const gchar *dir)
476 {
477 gint retries;
478
479         for (retries=0;retries<10;retries++) {
480 struct stat statbuf;
481 int dirfd;
482
483                 if (mkdir(dir,0700)) {
484                         if (errno!=EEXIST)
485                                 g_error(_("Failed to create chroot directory \"%s\": %m"),dir);
486                         unlink_nonrecursive(dir);
487                         if (mkdir(dir,0700))
488                                 g_error(_("Failed to create chroot directory \"%s\" after attempted unlink: %m"),dir);
489                         }
490                 dirfd=open(dir,O_RDONLY);
491                 if (dirfd==-1) {
492                         if (errno!=ENOENT)
493                                 g_error(_("Failed to open created chroot directory \"%s\" to lock it: %m"),dir);
494                         continue;
495                         }
496                 /* Do not use 'LOCK_NB' here as the garbage collector should release it soon. */
497                 if (flock(dirfd,LOCK_EX))
498                         g_error(_("Failed to lock created chroot directory \"%s\": %m"),dir);
499                 if (lstat(dir,&statbuf)) {
500                         if (errno!=ENOENT)
501                                 g_error(_("Failed to lstat(2) created chroot directory \"%s\": %m"),dir);
502                         if (close(dirfd))
503                                 g_error(_("Failed to close created and locked chroot directory \"%s\": %m"),dir);
504                         continue;
505                         }
506                 /* Leave 'dirfd' open to leave it LOCK_EX-ed. */
507                 break;
508                 }
509 }
510
511 static gchar *sandbox_parent_read_ior
512                 (int Vfs_IOR_fd_read,gchar **child_chroot_pid_hashkey_dirp,CaptiveVfsParentObject *captive_vfs_parent_object)
513 {
514 gchar *data;
515 gsize data_size;
516 GHashTable *hash;
517 gchar *ior,*child_chroot_pid_hashkey_dir;
518 int errint;
519 gchar *s,*sd,*se;
520 gboolean errbool;
521 const gchar *ior_read_error;
522
523         /* Initialize /tmp/orbit-$username directory for linking IOR socket. */
524         errbool=corba_init("captive-sandbox-parent",&captive_corba_ev,&captive_corba_orb,&captive_corba_poa);
525         g_assert(errbool==TRUE);
526
527         /* FIXME: Security: Duplicate giop_tmpdir_init() here. */
528         if (!sandbox_parent_own_orbit_dir) {
529                 /* FIXME: Make 'CAPTIVE_SANDBOX_CHROOT' configurable. */
530                 /* Use also geteuid() marker here as could not remove the directory
531                  * of some other user otherwise.
532                  */
533                 sandbox_parent_own_orbit_dir=g_strdup_printf("%s/tmp/captive-orbit-%d-%d",CAPTIVE_SANDBOX_CHROOT,getpid(),geteuid());
534                 sandbox_parent_own_orbit_dir_cleanup_init();
535                 createlockdir(sandbox_parent_own_orbit_dir);
536 #ifdef HAVE_ORBIT_LINK
537                 link_set_tmpdir(sandbox_parent_own_orbit_dir);
538 #else
539                 linc_set_tmpdir(sandbox_parent_own_orbit_dir);
540 #endif
541                 }
542
543         data=captive_rtl_file_read(Vfs_IOR_fd_read,&data_size); /* data_fd_read */
544         errint=close(Vfs_IOR_fd_read);
545         ior_read_error=NULL;
546 #define IOR_READ_ERROR(cond) G_STMT_START { \
547                 if (!ior_read_error && !(cond)) \
548                         ior_read_error=G_STRINGIFY(cond); \
549                 } G_STMT_END
550         IOR_READ_ERROR(errint==0);
551         IOR_READ_ERROR(data!=NULL);
552         IOR_READ_ERROR(data_size>=1);
553         IOR_READ_ERROR(data[data_size-1]=='\n');
554         if (ior_read_error)
555                 g_error(_("Error connecting to the sandbox server (failed \"%s\"). Try running by hand: %s"),
556                                 ior_read_error,CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.sandbox_server_argv[0]);
557 #undef IOR_READ_ERROR
558
559         hash=g_hash_table_new(g_str_hash,g_str_equal);
560
561         for (s=data;s<data+data_size;s=se+1) {
562                 se=strchr(s,'\n');
563                 g_assert(se!=NULL);
564                 *se=0;
565                 sd=strchr(s,'=');
566                 g_assert(sd!=NULL);
567                 *sd=0;
568                 g_hash_table_insert(hash,s,sd+1);
569                 }
570         g_assert(s==data+data_size);
571
572         if ((child_chroot_pid_hashkey_dir=g_hash_table_lookup(hash,"chroot_pid_hashkey_dir"))) {
573 const gchar *socketname,*socketpathname_src,*socketpathname_dest;
574 const gchar *chrooted_orbit_dir;
575
576                 /* IOR contains the full pathname with the setuid username encoded. */
577                 chrooted_orbit_dir=g_hash_table_lookup(hash,"chrooted_orbit_dir");
578                 g_assert(chrooted_orbit_dir!=NULL);
579                 captive_vfs_parent_object->corba_chrooted_orbit_dir=g_strdup(chrooted_orbit_dir);
580                 /* 0700 as this directory will not be reused
581                  * to commuicate with any other sandbox child.
582                  */
583                 if (mkdir(chrooted_orbit_dir,0700)) {
584                         g_assert(errno==EEXIST);
585                         }
586
587                 socketname=g_hash_table_lookup(hash,"socketname");
588                 g_assert(socketname!=NULL);
589                 captive_vfs_parent_object->corba_socketname=g_strdup(socketname);
590
591                 socketpathname_src=captive_printf_alloca("%s/%s/%s",child_chroot_pid_hashkey_dir,chrooted_orbit_dir,socketname);
592                 socketpathname_dest=g_strdup_printf("%s/%s",chrooted_orbit_dir,socketname);
593                 errint=link(socketpathname_src,socketpathname_dest);
594                 if (errint)
595                         g_error("link(\"%s\",\"%s\")=%d:%m",socketpathname_src,socketpathname_dest,errint);
596                 }
597         if (child_chroot_pid_hashkey_dirp)
598                 *child_chroot_pid_hashkey_dirp=g_strdup(child_chroot_pid_hashkey_dir);
599
600         ior=g_hash_table_lookup(hash,"ior");
601         g_assert(ior!=NULL);
602         ior=g_strdup(ior);
603         g_free(data);
604
605         g_hash_table_destroy(hash);
606
607         return ior;
608 }
609
610
611 static xmlNode *options_module_captive_to_xml
612                 (xmlNode *dest_xml_parent,const struct captive_options_module *src_options_module_captive)
613 {
614         g_return_val_if_fail(dest_xml_parent!=NULL,NULL);
615         g_return_val_if_fail(src_options_module_captive!=NULL,NULL);
616
617         { xmlNode *module=xmlNewTextChild(dest_xml_parent,NULL,"module",NULL);
618         const gchar *type_string="???"; /* Prevent: ... might be used uninitialized in this function */
619         const gchar *basename,*cgs;
620
621                 basename=src_options_module_captive->pathname_utf8;
622                 if ((cgs=strrchr(basename,'/')))
623                         basename=cgs+1;
624                 xmlNewProp(module,"basename",basename);
625                 switch (src_options_module_captive->type) {
626                         case CAPTIVE_OPTIONS_MODULE_TYPE_PE32:
627                                 type_string="PE32";
628                                 xmlNewProp(module,"length",captive_printf_alloca("%lu",(unsigned long)src_options_module_captive->u.pe32.length));
629                                 xmlNewProp(module,"md5"   ,src_options_module_captive->u.pe32.md5);
630                                 break;
631                         case CAPTIVE_OPTIONS_MODULE_TYPE_GMODULE:
632                                 type_string="gmodule";
633                                 break;
634                         default: g_assert_not_reached();
635                         }
636                 xmlNewProp(module,"type",type_string);  /* AFTER the 'switch' to set 'type_string'! */
637                 return module;
638                 }
639 }
640
641
642 static void sandbox_parent_bug_doc_make(CaptiveVfsParentObject *captive_vfs_parent_object)
643 {
644         { xmlDoc *doc=xmlNewDoc("1.0");
645                 captive_vfs_parent_object->corba_bug_doc=doc;
646                 { xmlNode *bug=xmlNewDocNode(captive_vfs_parent_object->corba_bug_doc,NULL,"bug",NULL);
647                         xmlDocSetRootElement(captive_vfs_parent_object->corba_bug_doc,bug);
648                         captive_vfs_parent_object->corba_bug=bug;
649                         { xmlNode *bug_captive=xmlNewTextChild(bug,NULL,"captive",NULL);
650                                 xmlNewProp(bug_captive,"version",VERSION);
651                                 }
652                         { xmlNode *bug_filesystem=xmlNewTextChild(bug,NULL,"filesystem",NULL);
653                                 options_module_captive_to_xml(bug_filesystem,&CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.filesystem);
654                                 }
655                         { xmlNode *bug_load_module=xmlNewTextChild(bug,NULL,"load_module",NULL);
656                         guint load_moduleui;
657                         struct captive_options_module *options_module;
658                         GList *load_module_node;
659
660                                 for (load_moduleui=0,load_module_node=CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.load_module;
661                                                 load_module_node;
662                                                 load_moduleui++,load_module_node=load_module_node->next) {
663                                         options_module=load_module_node->data;
664                                         options_module_captive_to_xml(bug_load_module,options_module);
665                                         }
666                                 }
667                         { xmlNode *bug_action=xmlNewTextChild(bug,NULL,"action",NULL);
668                                 captive_vfs_parent_object->corba_bug_action=bug_action;
669                                 }
670                         { xmlNode *bug_log=xmlNewTextChild(bug,NULL,"log",NULL);
671                                 captive_vfs_parent_object->corba_bug_log=bug_log;
672                                 }
673                         }
674                 }
675 }
676
677
678 static void sandbox_parent(const gchar *Vfs_IOR,const gchar *child_chroot_pid_hashkey_dir,CaptiveVfsParentObject *captive_vfs_parent_object)
679 {
680 Captive_Vfs Vfs_object;
681 Captive_GLogFunc GLogFunc_object;
682 Captive_CaptiveIOChannel CaptiveIOChannel_object;
683 Captive_CaptiveOptions options_corba;
684 guint load_module_length,load_moduleui;
685 struct captive_options_module *options_module;
686 GList *load_module_node;
687 const gchar *child_chroot_parent_own_orbit_socket,*child_chroot_parent_own_orbit_dir;
688 int errint;
689
690         g_return_if_fail(Vfs_IOR!=NULL);
691         /* 'child_chroot_pid_hashkey_dir' may be NULL */
692         g_return_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_parent_object));
693
694         Vfs_object=CORBA_ORB_string_to_object(captive_corba_orb,Vfs_IOR,&captive_corba_ev);
695         g_assert(validate_CORBA_Environment(&captive_corba_ev));
696
697         /* Init 'GLogFunc_object' */
698         GLogFunc_object=impl_Captive_GLogFunc__create(captive_corba_poa,captive_vfs_parent_object,&captive_corba_ev);
699         g_assert(validate_CORBA_Environment(&captive_corba_ev));
700
701         /* Init 'CaptiveIOChannel_object' */
702         if (!captive_vfs_parent_object->corba_parent_giochanel_blind_source) {
703 GIOChannel *giochannel;
704
705                 giochannel=CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.image_iochannel;
706                 g_io_channel_ref(giochannel);
707
708                 giochannel=captive_storage_relastblock(giochannel);
709
710                 switch (CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.rwmode) {
711                         case CAPTIVE_OPTION_RWMODE_RO:
712                         case CAPTIVE_OPTION_RWMODE_RW:
713                                 break;
714                         case CAPTIVE_OPTION_RWMODE_BLIND: {
715 GIOChannel *giochannel_orig;
716
717                                 giochannel_orig=giochannel;
718                                 giochannel=(GIOChannel *)captive_giochannel_blind_new(
719                                                 giochannel,     /* giochannel_orig */
720                                                 TRUE); /* writeable */
721                                 g_io_channel_unref(giochannel_orig);    /* reffed by captive_giochannel_blind_new() */
722                                 } break;
723                         default: g_assert_not_reached();
724                         }
725                 captive_vfs_parent_object->corba_parent_giochanel_blind_source=giochannel;
726                 }
727
728         if (!captive_vfs_parent_object->corba_parent_giochanel_blind)
729                 captive_vfs_parent_object->corba_parent_giochanel_blind=(GIOChannel *)captive_giochannel_blind_new(
730                                 captive_vfs_parent_object->corba_parent_giochanel_blind_source,  /* giochannel_orig */
731                                 (CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.rwmode!=CAPTIVE_OPTION_RWMODE_RO)); /* writeable */
732         CaptiveIOChannel_object=impl_Captive_CaptiveIOChannel__create(captive_corba_poa,
733                         captive_vfs_parent_object->corba_parent_giochanel_blind,&captive_corba_ev);
734         g_assert(validate_CORBA_Environment(&captive_corba_ev));
735
736         /* Create the socket needed for 'sandbox_parent_own_orbit_socket' below
737          * by CORBA_ORB_object_to_string()->ORBit_marshal_object()->IOP_generate_profiles()->ORBit_ORB_start_servers...
738          */
739         {
740 char *GLogFunc_IOR;
741                 GLogFunc_IOR=CORBA_ORB_object_to_string(captive_corba_orb,GLogFunc_object,&captive_corba_ev);
742                 g_assert(validate_CORBA_Environment(&captive_corba_ev));
743                 g_assert(GLogFunc_IOR!=NULL);
744                 CORBA_free(GLogFunc_IOR);
745                 }
746
747         if (sandbox_parent_own_orbit_dir && !sandbox_parent_own_orbit_socket) {
748 DIR *dir;
749 struct dirent *dirent;
750
751                 dir=opendir(sandbox_parent_own_orbit_dir);
752                 g_assert(dir!=NULL);
753
754                 while (errno=0,(dirent=readdir(dir))) {
755                         if (!strcmp(dirent->d_name,".") || !strcmp(dirent->d_name,".."))
756                                 continue;
757                         g_assert(sandbox_parent_own_orbit_socket==NULL);
758                         sandbox_parent_own_orbit_socket=g_strdup_printf("%s/%s",sandbox_parent_own_orbit_dir,dirent->d_name);
759                         }
760                 g_assert(errno==0);
761                 errint=closedir(dir);
762                 g_assert(errint==0);
763                 g_assert(sandbox_parent_own_orbit_socket!=NULL);
764                 }
765
766         if (child_chroot_pid_hashkey_dir) {
767 gchar *s;
768
769                 child_chroot_parent_own_orbit_dir=captive_printf_alloca("%s/%s",child_chroot_pid_hashkey_dir,sandbox_parent_own_orbit_dir);
770                 s=(/* de-const */ gchar *)child_chroot_parent_own_orbit_dir;
771                 do {
772                         s=strchr(s,'/');
773                         if (s)
774                                 *s=0;
775                         if (*child_chroot_parent_own_orbit_dir) {
776                                 errint=mkdir(child_chroot_parent_own_orbit_dir,0777);
777                                 if (errint)
778                                         g_assert(errno==EEXIST);
779                                 else {
780                                         /* chmod(2) it to prevent mode limitation by
781                                          * active ulimit(2) of being executed by mount(8).
782                                          */
783                                         errint=chmod(child_chroot_parent_own_orbit_dir,0777);
784                                         g_assert(errint==0);
785                                         }
786                                 }
787                         if (s)
788                                 *s++='/';
789                         } while (s);
790                 child_chroot_parent_own_orbit_socket=captive_printf_alloca("%s/%s",
791                                 child_chroot_pid_hashkey_dir,sandbox_parent_own_orbit_socket);
792                 errint=link(sandbox_parent_own_orbit_socket,child_chroot_parent_own_orbit_socket);
793                 g_assert(errint==0);
794                 /* chmod(2)s also our orig. one (!) but this one is protected by its 0777 directory. */
795                 errint=chmod(child_chroot_parent_own_orbit_socket,0666);
796                 g_assert(errint==0);
797                 }
798
799         options_corba.g_log_func=CORBA_Object_duplicate(GLogFunc_object,&captive_corba_ev);
800         g_assert(validate_CORBA_Environment(&captive_corba_ev));
801
802         options_module_captive_to_options_module_corba(&options_corba.filesystem,&CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.filesystem);
803         /* Prevent secondary captive_giochannel_blind inside of our sandbox child
804          * as we already have one captive_giochannel_blind in the parent.
805          */
806         options_corba.rwmode        =(CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.rwmode == CAPTIVE_OPTION_RWMODE_BLIND ? CAPTIVE_OPTION_RWMODE_RW
807                         : CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.rwmode);
808         options_corba.media         =CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.media;
809         options_corba.debug_messages=CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.debug_messages;
810
811         options_corba.image_iochannel=CORBA_Object_duplicate(CaptiveIOChannel_object,&captive_corba_ev);
812         g_assert(validate_CORBA_Environment(&captive_corba_ev));
813
814         load_module_length=g_list_length(CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.load_module);
815         options_corba.load_module._maximum=load_module_length;
816         options_corba.load_module._length=load_module_length;
817         options_corba.load_module._buffer=Captive_CaptiveOptionsModuleList_allocbuf(options_corba.load_module._maximum);
818         options_corba.load_module._release=TRUE;
819         for (load_moduleui=0,load_module_node=CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.load_module;
820                         load_module_node;
821                         load_moduleui++,load_module_node=load_module_node->next) {
822                 options_module=load_module_node->data;
823                 options_module_captive_to_options_module_corba(options_corba.load_module._buffer+load_moduleui,options_module);
824                 }
825
826         Captive_Vfs_init(Vfs_object,&options_corba,&captive_corba_ev);
827         g_assert(validate_CORBA_Environment(&captive_corba_ev));
828
829         Captive_CaptiveOptions__freekids(&options_corba,
830                         NULL);  /* d; unused */
831
832         captive_vfs_parent_object->corba_Vfs_object=Vfs_object;
833         captive_vfs_parent_object->corba_GLogFunc_object=GLogFunc_object;
834         captive_vfs_parent_object->corba_CaptiveIOChannel_object=CaptiveIOChannel_object;
835
836         if (CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.bug_pathname)
837                 sandbox_parent_bug_doc_make(captive_vfs_parent_object);
838 }
839
840 static void fd_shiftup(int *fdp)
841 {
842         g_return_if_fail(fdp!=NULL);
843
844         while (*fdp<=2 /* STDERR */) {
845                 *fdp=dup(*fdp);
846                 g_assert(*fdp!=-1);
847                 }
848 }
849
850 void captive_sandbox_fd_closeup(int fd_first_to_delete)
851 {
852 DIR *dir;
853 int errint;
854 int dir_fd;
855 struct dirent *dirent;
856
857         dir=opendir("/proc/self/fd/");
858         g_return_if_fail(dir!=NULL);
859         dir_fd=dirfd(dir);
860         g_return_if_fail(dir_fd!=-1);
861
862         while (errno=0,(dirent=readdir(dir))) {
863 long dirent_fd;
864 char *endptr;
865
866                 if (0
867                                 || !strcmp(dirent->d_name,".")
868                                 || !strcmp(dirent->d_name,".."))
869                         continue;
870                 dirent_fd=strtol(dirent->d_name,&endptr,10 /* base */);
871                 g_assert(dirent_fd>=0 && (!endptr || !*endptr));
872                 if (dirent_fd<fd_first_to_delete || dirent_fd==dir_fd)
873                         continue;
874
875                 errint=close(dirent_fd);
876                 g_assert(errint==0);
877                 errno=0;
878                 errint=close(dirent_fd);
879                 g_assert(errint==-1); g_assert(errno==EBADF);
880                 }
881         g_return_if_fail(errno==0);     /* check for EOF */
882
883         errint=closedir(dir);
884         g_return_if_fail(errint==0);
885         errno=0;
886         close(dir_fd); g_assert(errno==EBADF);  /* just a bit of paranoia; it should be already closed by closedir() */
887 }
888
889 gboolean captive_sandbox_spawn(CaptiveVfsParentObject *captive_vfs_parent_object)
890 {
891 /* Vfs_IOR_fds[0] for reading by sandbox_parent() - client,
892  * Vfs_IOR_fds[1] for writing by sandbox_child()  - server
893  */
894 int Vfs_IOR_fds[2],parentheart_fds[2];
895 int errint;
896 gboolean errbool;
897
898         g_return_val_if_fail(CAPTIVE_VFS_PARENT_IS_OBJECT(captive_vfs_parent_object),FALSE);
899
900         errint=pipe(Vfs_IOR_fds);
901         g_return_val_if_fail(errint==0,FALSE);
902         errint=pipe(parentheart_fds);
903         g_return_val_if_fail(errint==0,FALSE);
904
905         /* Currently never called anywhere:
906          *     errbool=corba_shutdown(&captive_corba_ev,&captive_corba_orb,&captive_corba_poa);
907          *     g_assert(errbool==TRUE);
908          */
909
910         if (CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.sandbox_server_ior) {
911                 g_assert(CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.sandbox_server_argv==NULL);
912
913                 errbool=corba_init("captive-sandbox-parent",&captive_corba_ev,&captive_corba_orb,&captive_corba_poa);
914                 g_assert(errbool==TRUE);
915
916                 captive_vfs_parent_object->corba_parentheart_fds_1=-1;
917                 captive_vfs_parent_object->corba_child_pid=-1;
918                 sandbox_parent(
919                                 CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.sandbox_server_ior,      /* Vfs_IOR */
920                                 NULL,   /* child_chroot_pid_hashkey_dir */
921                                 captive_vfs_parent_object);     /* captive_vfs_parent_object */
922                 return TRUE;
923                 }
924
925         g_assert(CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.sandbox_server_argv!=NULL);
926         switch ((captive_vfs_parent_object->corba_child_pid=fork())) {
927                 case -1:        /* error */
928                         g_return_val_if_reached(FALSE);
929
930                 case 0: { /* child */
931 const char *sandbox_argv0;
932 int execv_rc;
933
934                         errint=close(Vfs_IOR_fds[0]);   /* close Vfs_IOR_fd_read */
935                         g_return_val_if_fail(errint==0,FALSE);
936                         errint=close(parentheart_fds[1]);       /* close parentheart_fd_write */
937                         g_return_val_if_fail(errint==0,FALSE);
938
939                         fd_shiftup(Vfs_IOR_fds+1);      /* Vfs_IOR_fd_write */
940                         fd_shiftup(parentheart_fds+0);  /* parentheart_fd_read */
941                         errint=dup2(Vfs_IOR_fds[1],1 /* STDOUT */);     /* Vfs_IOR_fd_write */
942                         g_return_val_if_fail(errint==1 /* STDOUT */,FALSE);
943                         errint=dup2(parentheart_fds[0],0 /* STDIN */);  /* parentheart_fd_read */
944                         g_return_val_if_fail(errint==0 /* STDIN */,FALSE);
945
946                         captive_sandbox_fd_closeup(2 /* STDERR */ +1);
947
948                         sandbox_argv0=CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.sandbox_server_argv[0];
949                         execv_rc=execv(sandbox_argv0,
950                                         /* re-const */ (char * const *)CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.sandbox_server_argv);
951                         g_warning(_("Failed to spawn sandbox server - execv(\"%s\",...)=%d: %m"),sandbox_argv0,execv_rc);
952                         g_return_val_if_reached(FALSE);
953                         } /* NOTREACHED */
954
955                 default: {      /* parent */
956 gchar *Vfs_IOR;
957 gchar *child_chroot_pid_hashkey_dir;
958
959                         errint=close(Vfs_IOR_fds[1]);   /* close Vfs_IOR_fd_write */
960                         g_return_val_if_fail(errint==0,FALSE);
961                         errint=close(parentheart_fds[0]);       /* close parentheart_fd_read */
962                         g_return_val_if_fail(errint==0,FALSE);
963                         errint=fcntl(parentheart_fds[1],F_SETFD,FD_CLOEXEC);
964                         /* This fcntl(2) may not be enough - some fork(2) may duplicate this
965                          * write descriptor and even if we do some process finish the child
966                          * may remain alone connected with some unknown fork(2)er from us.
967                          * Currently I am not aware such case would occur.
968                          */
969                         g_return_val_if_fail(errint==0,FALSE);
970                         captive_vfs_parent_object->corba_parentheart_fds_1=parentheart_fds[1];
971
972                         Vfs_IOR=sandbox_parent_read_ior(
973                                         Vfs_IOR_fds[0], /* Vfs_IOR_fd_read */
974                                         &child_chroot_pid_hashkey_dir,
975                                         captive_vfs_parent_object);
976
977                         sandbox_parent(
978                                         Vfs_IOR,        /* Vfs_IOR */
979                                         child_chroot_pid_hashkey_dir,   /* child_chroot_pid_hashkey_dir */
980                                         captive_vfs_parent_object);     /* captive_vfs_parent_object */
981
982                         g_free(Vfs_IOR);
983                         g_free(child_chroot_pid_hashkey_dir);
984
985                         /* 'parentheart_fds[1]' - parentheart_fd_write - is left open here */
986                         return TRUE;
987                         }
988                 }
989         /* NOTREACHED */
990         g_return_val_if_reached(FALSE);
991 }
992
993
994 GnomeVFSResult captive_sandbox_parent_return_from_CORBA_Environment
995                 (CORBA_Environment *evp,CaptiveVfsParentObject *captive_vfs_parent_object)
996 {
997 GnomeVFSResult r;
998
999         if (evp->_major==CORBA_NO_EXCEPTION)
1000                 return GNOME_VFS_OK;
1001
1002         /* If !CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.sandbox_server_argv it is CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.sandbox_server_ior
1003          * where we cannot do any restart anyway.
1004          */
1005         if (captive_vfs_parent_object && CAPTIVE_VFS_OBJECT(captive_vfs_parent_object)->options.sandbox_server_argv
1006                         && (evp->_major==CORBA_SYSTEM_EXCEPTION && !strcmp(ex_CORBA_COMM_FAILURE,CORBA_exception_id(evp)))) {
1007                 r=GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE;
1008                 if (captive_vfs_parent_object->corba_Vfs_object!=CORBA_OBJECT_NIL)
1009                         captive_vfs_parent_object_aborted(captive_vfs_parent_object);   /* errors ignored */
1010                 }
1011         else if (evp->_major==CORBA_USER_EXCEPTION && !strcmp(ex_Captive_GnomeVFSResultException,CORBA_exception_id(evp))) {
1012                 r=((Captive_GnomeVFSResultException *)CORBA_exception_value(evp))->gnome_vfs_result;
1013                 g_assert(r!=GNOME_VFS_ERROR_SERVICE_NOT_AVAILABLE);     /* code reserved for sandbox restarts */
1014                 }
1015         else {
1016                 r=GNOME_VFS_ERROR_GENERIC;
1017                 g_warning(_("CORBA Exception occured: id=\"%s\", value=%p"),
1018                                 CORBA_exception_id(evp),CORBA_exception_value(evp));
1019                 }
1020         CORBA_exception_free(evp);
1021
1022         return r;
1023 }
1024
1025
1026 void captive_sandbox_child_GnomeVFSResultException_throw(CORBA_Environment *evp,GnomeVFSResult errvfsresult)
1027 {
1028 Captive_GnomeVFSResultException *gnome_vfs_result_exception;
1029
1030         g_return_if_fail(evp!=NULL);
1031
1032         gnome_vfs_result_exception=Captive_GnomeVFSResultException__alloc();
1033         gnome_vfs_result_exception->gnome_vfs_result=errvfsresult;
1034         CORBA_exception_set(evp,CORBA_USER_EXCEPTION,ex_Captive_GnomeVFSResultException,gnome_vfs_result_exception);
1035 }