1 /* $Id: w3mimg.c,v 1.6 2010/12/21 10:13:55 htrb Exp $ */
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <sys/types.h>
6 #include <unistd.h>
7 #include "w3mimg/w3mimg.h"
8 
9 w3mimg_op *
w3mimg_open()10 w3mimg_open()
11 {
12     w3mimg_op *w_op = NULL;
13 #ifdef W3MIMGDISPLAY_SETUID
14     uid_t runner_uid = getuid();
15     uid_t owner_uid = geteuid();
16 #endif
17 #ifdef USE_W3MIMG_WIN
18     if (w_op == NULL)
19 	w_op = w3mimg_winopen();
20 #endif
21 #ifdef USE_W3MIMG_X11
22 #ifdef W3MIMGDISPLAY_SETUID
23     /* run in user privileges */
24     setreuid(owner_uid, runner_uid);
25 #endif
26     if (w_op == NULL)
27 	w_op = w3mimg_x11open();
28 #ifdef W3MIMGDISPLAY_SETUID
29     setreuid(runner_uid, owner_uid);
30 #endif
31 #endif
32 #ifdef USE_W3MIMG_FB
33     /* run in setuid privileges */
34     if (w_op == NULL)
35 	w_op = w3mimg_fbopen();
36 #endif
37     return w_op;
38 }
39