* SUMMARY: Permissions on a file
@ 1998-06-09 19:34 Spalding, Stephen
0 siblings, 0 replies; 2+ messages in thread
From: Spalding, Stephen @ 1998-06-09 19:34 UTC (permalink / raw)
To: tru64-unix-managers
Since I posted my message a few minutes ago, I got one response which has to
do with using c language to write a short
program. Here it is:
> the stat() lstat() and fstat() functions are keen to this. If I had the
> time and skill I would try to program a c app for this purpose. You
> might want to try this yourself if you are handy with c.
>
> Nathan J Grass, MV-STAR Technical Support
> Utility Translation Systems, Inc. Raleigh, NC
> 919 876 2600 x2216 Fax: 919.876.4001
> nathang@uts.itron.com / zaz@null.net
>
>
>
Unfortunately, I am not handy with c. I wrote a small, simple ksh script to
take care of the problem. Again, it's very simple and would need to be
modified to take care of extra permissions (sticky bit and so forth) and
would not work on files which the user does not have permission, but on
simple files it should do just fine. Here is my script:
#!/bin/ksh
file=$1
perms=`ls -l $file|awk '{print $1}'`
x=2
count1=0
count2=0
count3=0
while [ $x != 11 ]; do
letter=`echo $perms|cut -b $x`
case $x in
[2-4]) case $letter in
r) let count1=count1+4
;;
w) let count1=count1+2
;;
x) let count1=count1+1
;;
esac #case $letter in
;;
[5-7]) case $letter in
r) let count2=count2+4
;;
w) let count2=count2+2
;;
x) let count2=count2+1
;;
esac #case $letter in
;;
[8-9]|10) case $letter in
r) let count3=count3+4
;;
w) let count3=count3+2
;;
x) let count3=count3+1
;;
esac #case $letter in
;;
esac #case $x in
let x=x+1
done
echo "The permissions are $count1$count2$count3 "
- Stephen Spalding
^ permalink raw reply [flat|nested] 2+ messages in thread
* SUMMARY: Permissions on a file
@ 1998-06-09 20:59 Peter Olson, Delphi Information Engineer
0 siblings, 0 replies; 2+ messages in thread
From: Peter Olson, Delphi Information Engineer @ 1998-06-09 20:59 UTC (permalink / raw)
To: tru64-unix-managers
I figure I owe the list a contribution in return for all the great stuff I
read here, so here is a small C program to solve SSpaldin@mem-ins.com's
permissions inquiry. Tested on Digital Unix 3.2c and 4.0 and 4.0B, but
it should work on most Unix systems.
Peter Olson, Delphi Information Engineer
-----------%<----------
/*
** fstatm.c
**
** fstat multiple files.
**
** Public Domain 1998
**
*/
#include <stdio.h>
#include <sys/stat.h>
#include <sys/mode.h>
int
main(int argc, char **argv)
{
int retcode = 0, showfn = 0;
if (argc > 1 && '-' == argv[1][0])
{
if ('n' != argv[1][1] || argv[1][2])
{
fprintf(stderr, "Usage: fstatm {-n} filenames\n");
fprintf(stderr,
" -n causes filenames to be displayed in second column\n");
return 2;
}
showfn = 1;
argv++; argc--;
}
while (++argv, --argc > 0) /* can run against wildcards */
{
struct stat stbuf;
if (0 == lstat(argv[0], &stbuf)) /* don't follow symbolic links */
{
if (S_ISREG(stbuf.st_mode)) /* is this a regular file? */
stbuf.st_mode &= ~S_IFREG; /* lose the bit that says so */
/* see /usr/include/sys/mode.h for esoteric high order bits */
if (showfn)
printf("%3.3lo %s\n", 0x0000FFFFL & (long) stbuf.st_mode,
argv[0]);
else printf("%3.3lo\n", 0x0000FFFFL & (long) stbuf.st_mode);
}
else /* placeholder for when we can't get status bits */
{
/* real 'no permissions' has 3 digits */
if (showfn)
printf("000000 %s\n", argv[0]);
else printf("000000\n");
retcode = 1; /* bad path name or other error */
}
}
return retcode; /* non-zero if one or more fstat errors */
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1998-06-09 20:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-06-09 20:59 SUMMARY: Permissions on a file Peter Olson, Delphi Information Engineer
-- strict thread matches above, loose matches on Subject: below --
1998-06-09 19:34 Spalding, Stephen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox