File: locate.diff

package info (click to toggle)
lg-issue26 3-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,460 kB
  • ctags: 230
  • sloc: makefile: 30; sh: 3
file content (129 lines) | stat: -rw-r--r-- 3,186 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
diff -cr findutils-4.1/locate/locate.c findutils-4.1-patched/locate/locate.c
*** findutils-4.1/locate/locate.c	Mon Sep 26 17:06:14 1994
--- findutils-4.1-patched/locate/locate.c	Wed Jan  7 15:13:42 1998
***************
*** 54,59 ****
--- 54,61 ----
  #include <time.h>
  #include <fnmatch.h>
  #include <getopt.h>
+ #include <dirent.h>
+ #include <unistd.h>
  
  #define NDEBUG
  #include <assert.h>
***************
*** 93,98 ****
--- 95,101 ----
  char *xmalloc ();
  char *xrealloc ();
  void error ();
+ int DO_LS = 0;
  
  /* Read in a 16-bit int, high byte first (network byte order).  */
  
***************
*** 165,170 ****
--- 168,174 ----
  locate (pathpart, dbfile)
       char *pathpart, *dbfile;
  {
+   FILE *q_file;  char q_str[1000];  struct stat q_stat;  int q_includeit;
    /* The pathname database.  */
    FILE *fp;
    /* An input byte.  */
***************
*** 309,316 ****
  		prev_fast_match = true;
  		if (globflag == false || fnmatch (pathpart, path, 0) == 0)
  		  {
! 		    puts (path);
! 		    ++printed;
  		  }
  		break;
  	      }
--- 313,350 ----
  		prev_fast_match = true;
  		if (globflag == false || fnmatch (pathpart, path, 0) == 0)
  		  {
! 	 /* We have a successful hit, decide if it shouldn't be viewed */
! 	 /* A) Open file to read - if we can, include it	       */
! 	 /*    Rules out unauthorized and non-existent files           */
! 	 /* B) If file is unreadable, but owned by user, include it    */
!          /* C) Root sees all files				       */
! 		    q_file = NULL;  q_includeit = 0;
! 		    q_file = fopen(path, "r");
! 		    if (q_file != NULL)
! 		    {
! 		      q_includeit = 1;
! 		      fclose(q_file);
! 		    }
! 		    else
! 		      if (stat(path, &q_stat) != -1)
! 		      {
! 			if (q_stat.st_uid == getuid())
! 			  q_includeit = 1;
! 		      }
! 		    if (getuid() == 0) q_includeit = 1;
! 
! 		    if (q_includeit == 1)
! 		    {
! 		      if (DO_LS)
! 		      {
! 			sprintf(q_str, "/bin/ls -ld '%s'", path);
! 			q_str[999] = 0;  /* Just in case path is overflowing */
! 			system(q_str);
! 		      }
! 		      else
! 		        puts (path);
! 		      ++printed;
! 		    }
  		  }
  		break;
  	      }
***************
*** 342,348 ****
       int status;
  {
    fprintf (stream, "\
! Usage: %s [-d path] [--database=path] [--version] [--help] pattern...\n",
  	   program_name);
    exit (status);
  }
--- 376,382 ----
       int status;
  {
    fprintf (stream, "\
! Usage: %s [-d path] [--database=path] [-l] [--version] [--help] pattern...\n",
  	   program_name);
    exit (status);
  }
***************
*** 369,375 ****
    if (dbpath == NULL)
      dbpath = LOCATE_DB;
  
!   while ((optc = getopt_long (argc, argv, "d:", longopts, (int *) 0)) != -1)
      switch (optc)
        {
        case 'd':
--- 403,409 ----
    if (dbpath == NULL)
      dbpath = LOCATE_DB;
  
!   while ((optc = getopt_long (argc, argv, "ld:", longopts, (int *) 0)) != -1)
      switch (optc)
        {
        case 'd':
***************
*** 383,388 ****
--- 417,425 ----
  	printf ("GNU locate version %s\n", version_string);
  	exit (0);
  
+       case 'l':
+ 	DO_LS = 1;
+ 	break;
        default:
  	usage (stderr, 1);
        }