Solved

masks and sys/stat.h

Posted on 1998-08-19
5
379 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

19 Experts available now in Live!

Get 1:1 Help Now