tizen 2.4 release
[external/ncurses.git] / packaging / 03-linux-use-fsuid.patch
1 ---
2  ncurses/tinfo/read_termcap.c |   40 ++++++++++++++++++++++++++++++++++++++++
3  1 file changed, 40 insertions(+)
4
5 --- a/ncurses/tinfo/read_termcap.c
6 +++ b/ncurses/tinfo/read_termcap.c
7 @@ -319,6 +319,7 @@
8              */
9             if (fd >= 0) {
10                 (void) lseek(fd, (off_t) 0, SEEK_SET);
11 +#ifndef __linux__
12             } else if ((_nc_access(db_array[current], R_OK) < 0)
13                        || (fd = open(db_array[current], O_RDONLY, 0)) < 0) {
14                 /* No error on unfound file. */
15 @@ -329,6 +330,33 @@
16             } else {
17                 myfd = TRUE;
18             }
19 +#else
20 +           } else {
21 +               bool fd1, fd2;
22 +
23 +               setfsuid(getuid());
24 +               setfsgid(getgid());
25 +
26 +               fd1 = _nc_access(db_array[current], R_OK) < 0;
27 +               if (!fd1) {
28 +                   fd = open(db_array[current], O_RDONLY, 0));
29 +                   fd1 = fd < 0;
30 +               }
31 +
32 +               setfsuid(geteuid());
33 +               setfsgid(getegid());
34 +
35 +               if (! fd1) {
36 +                   /* No error on unfound file. */
37 +                   if (errno == ENOENT)
38 +                       continue;
39 +                   free(record);
40 +                   return (TC_SYS_ERR);
41 +               } else {
42 +                   myfd = TRUE;
43 +               }
44 +           }
45 +#endif
46             lineno = 0;
47  
48             /*
49 @@ -1097,8 +1125,20 @@
50         for (i = 0; i < filecount; i++) {
51  
52             T(("Looking for %s in %s", tn, termpaths[i]));
53 +#ifndef __linux__
54             if (_nc_access(termpaths[i], R_OK) == 0
55                 && (fp = fopen(termpaths[i], "r")) != (FILE *) 0) {
56 +#else
57 +           fp = (FILE *) 0;
58 +           if (_nc_access(termpaths[i], R_OK) == 0) {
59 +               setfsuid(getuid());
60 +               setfsgid(getgid());
61 +               fp = fopen(termpaths[i], "r");
62 +               setfsuid(geteuid());
63 +               setfsgid(getegid());
64 +           }
65 +           if (fp != (FILE *) 0) {
66 +#endif
67                 _nc_set_source(termpaths[i]);
68  
69                 /*