Solved

masks and sys/stat.h

Posted on 1998-08-19
5
395 Views
Last Modified: 2013-12-26
My question relates to the header file <sys/stat.h>. The following code snippet is from W. Richard Stevens' "Unix Network Programming" (it's part of an authentication program):

#include <sys/stat.h>
#include <pwd.h>
...

struct stat statbuff;
struct passwd *pwd;
register FILE *hostfp;
...

if ((fstat(fileno(hostfp), &statbuff) < 0 ||
      (statbuff.st_uid !=0 && statbuff.st_uid != pwd->pw_uid) ||
      (statbuff.st_mode & 022) {
            fclose(hostfp);
            return(-1);
            }

My question relates to the reference to 022. This appears to be some kind of mask - but what exactly is its role in the program? My sys/stat.h contains the following masks, none of which seems to correspond to the 022:

#define S_IFMT  00170000
#define S_IFSOCK 0140000
#define S_IFLNK       0120000
#define S_IFREG  0100000
#define S_IFBLK  0060000
#define S_IFDIR  0040000
#define S_IFCHR  0020000
#define S_IFIFO  0010000
#define S_ISUID  0004000
#define S_ISGID  0002000
#define S_ISVTX  0001000

Any enlightenment would be appreciated! (Also, I'm certain that Stevens has omitted to mention what "fileno", also in the above code snippet, is. It's not some standard library function, is it?)

0
Comment
Question by:sevrin
  • 4
5 Comments
 
LVL 5

Expert Comment

by:ecw
ID: 1292940
022 refers to group and others writable permission.  fileno is a standard function that returns the file descriptor of the FILE* passed.
0
 
LVL 5

Expert Comment

by:ecw
ID: 1292941
Symbolically, 022 is;
 (S_IWGRP | S_IWOTH)
0
 
LVL 5

Expert Comment

by:ecw
ID: 1292942
The code snippet I guess is from rlogind or rshd (remshd), and verifies that .rhosts is either owned by root or owned by the user, and is not writable by anyone other than the owner.
0
 

Author Comment

by:sevrin
ID: 1292943
I want to give you the points for this, ecw, so perhaps you can reply so that I get the "question answered" message. Thanks.
0
 
LVL 5

Accepted Solution

by:
ecw earned 50 total points
ID: 1292944
Repeat of comments:-
022 refers to group and others writable permission.  fileno is a standard function that returns the file descriptor of the FILE* passed
Symbolically, 022 is;
         (S_IWGRP | S_IWOTH)
The code snippet I guess is from rlogind or rshd (remshd), and verifies that .rhosts is either owned by root or owned by the user, and is not writable by anyone other than the owner.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Separate files macro - Errors on larger data set 18 65
deburging in oracle form 12 88
substring method in java 1 97
has22 challenge 11 78
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now