Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

masks and sys/stat.h

Posted on 1998-08-19
5
Medium Priority
?
456 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

661 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