Anselm R. Garbe --> dwm (2006-10-13 10:53:21 +0200):
> On Fri, Oct 13, 2006 at 10:45:17AM +0200, Jukka Salmi wrote:
> > Anselm R. Garbe --> dwm (2006-10-12 18:02:43 +0200):
> > > On Thu, Oct 12, 2006 at 05:45:21PM +0200, Cedric Krier wrote:
> > > > Here is a patch to add check for all user's groups instead of only the
> > > > real group.
> > >
> > > How portable is that? Can some BSD user check please?
> >
> > Seems fine to me: getgroups() is POSIX.1, and the patch makes lsx work
> > as expected at least on NetBSD.
> >
> > Cheers, Jukka
> >
> > BTW: lsx shouldn't need libX11...
>
> Indeed!
>
> Cedric, your patch is applied!
Why not just use access(2) (also POSIX.1) instead?
Cheers, Jukka
--
bashian roulette:
$ ((RANDOM%6)) || rm -rf ~
diff -r 9f363c099ba9 lsx.c
--- a/lsx.c Fri Oct 13 10:54:25 2006 +0200
+++ b/lsx.c Fri Oct 13 11:05:19 2006 +0200
@@ -7,30 +7,13 @@
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
-#include <sys/types.h>
-
-static int
-ingroups(struct stat *s, int size, gid_t list[]) {
- int i;
-
- for(i = 0; i < size; i++)
- if(s->st_gid == list[i])
- return 1;
- return 0;
-}
int
main(int argc, char *argv[]) {
int i;
- gid_t gid = getgid();
struct dirent *dp;
struct stat s;
- uid_t uid = getuid();
DIR *dir;
- long ngroups_max;
- ngroups_max = sysconf(_SC_NGROUPS_MAX);
- gid_t gid_l[ngroups_max];
- int ngroups = getgroups(ngroups_max, gid_l);
if((argc > 1) && !strncmp(argv[1], "-v", 3)) {
fputs("lsx-"VERSION", (C)opyright MMVI Anselm R. Garbe\n",
stdout);
@@ -43,9 +26,7 @@ main(int argc, char *argv[]) {
if((dp = readdir(dir))
&& (stat(dp->d_name, &s) != -1)
&& S_ISREG (s.st_mode)
- && ((s.st_uid == uid && s.st_mode &
S_IXUSR) ||
- ((s.st_gid == gid ||
ingroups(&s, ngroups, gid_l))
- && s.st_mode & S_IXGRP) ||
(s.st_mode & S_IXOTH)))
+ && !access(dp->d_name, X_OK))
puts(dp->d_name);
while(dp);
closedir(dir);