home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *******************************************************************************
-
- Site: Western Michigan University Academic Computer Center
-
- System: Directory/File System Maintenance
-
- Program: maint
-
- Version=01 Level=00 01/24/92 Leonard J. Peirce
-
- Purpose: Give full information about a file, including size, pro-
- tection mode, inode, and file commands, among other info.
-
- Arguments: See individual routine(s).
-
- External variables: None
-
- Maint external functions:
-
- Defined: info
-
- Called: add_filetype, get_group, get_owner, prot_val_to_str,
- put_line, readlink
-
- Files accessed: File passed to info routine
-
- Return codes: See individual routines
-
- Compiling instructions: See Makefile
-
- Linking instructions: See Makefile
-
- Other information: (C) Copyright 1992, Leonard J. Peirce
-
- ********************************************************************************
- *******************************************************************************/
-
- /******************************************************************************/
- /* */
- /* # I N C L U D E F I L E S */
- /* */
- /******************************************************************************/
-
- #if !defined(SYSV) || defined(sun)
- #include <sys/types.h>
- #endif
- #ifdef ultrix
- #include <cursesX.h>
- #else
- #include <curses.h>
- #endif
- #include <stdio.h>
- #include <string.h>
- #include <errno.h>
- #include <time.h>
- #include "maint.h"
- #include <sys/stat.h>
-
- /******************************************************************************/
- /* */
- /* # D E F I N E S */
- /* */
- /******************************************************************************/
-
- /******************************************************************************/
- /* */
- /* S T R U C T U R E S , U N I O N S , T Y P E D E F S */
- /* */
- /******************************************************************************/
-
- /******************************************************************************/
- /* */
- /* E X T E R N A L D E F I N I T I O N S & D E C L A R A T I O N S */
- /* */
- /******************************************************************************/
-
- extern char *prot_val_to_str(),
- *get_owner(),
- *get_group();
-
- extern int readlink();
-
- extern u_short add_filetype();
-
- extern short put_line();
-
- short info();
-
- /******************************************************************************/
- /* */
- /* S T A T I C D E F I N I T I O N S & D E C L A R A T I O N S */
- /* */
- /******************************************************************************/
-
- /*******************************************************************************
- ********************************************************************************
-
- Function: info
-
- Purpose: Display all the information about the file that the user could
- possibly want. Basically, all of the information on the file
- is displayed, along with any of the commands that might be
- associated with the file.
-
- Global variables:
-
- Name Examine/Modify/Use/Read/Write
- ---- -----------------------------
- none
-
- Return Codes:
-
- Code Reason
- ---- ------
- 0 completed successfully
- CANT_DISPLAY can't get file attributes to display
-
- ********************************************************************************
- *******************************************************************************/
-
- short info(ent,args)
- /******* FORMAL PARAMETERS *******/
- register ENT_DEF *ent; /* file entry pointer */
- ARG_DEF *args; /* run-time arguments */
-
- { /*** info ***/
- /******** LOCAL VARIABLES ********/
- register COM_DEF *comm_ptr; /* pointer to file commands for file */
- WINDOW *window; /* window to use */
- long temp; /* temporary time value */
- struct stat statbuf; /* for getting file information */
- int row = 0, /* what row is being written to */
- length, /* length of string from readlink() */
- status, /* return code status holder */
- max_row, /* max. usable row for window */
- i, j ; /* simple counters */
- char buf[MAXNAMLEN*2], /* formatting buffer */
- buf2[MAXNAMLEN+10], /* for getting symbolic link info */
- time1[TIME_STR_MAX+2], /* time string formatting buffer */
- time2[TIME_STR_MAX+2], /* time string formatting buffer */
- time3[TIME_STR_MAX+2]; /* time string formatting buffer */
- u_short prot ; /* protection word value */
- static char indent_str[] = {" "},
- copy_str[] = {"Copy to: "},
- rename_str[] = {"Rename to: "},
- delete_str[] = {"Delete"},
- protect_str[] = {"Protection: "},
- text_str[] = {"Text descriptor: "},
- owner_str[] = {"Owner: "},
- group_str[] = {"Group: "},
- link_str[] = {"Symbolic link to: "};
- static char *who_perm[ 3 ] = {
- "Owner",
- "Group",
- "Others"
- } ;
- static char *dir_permissions[] = {
- " %s can%s read (list) the directory",
- " %s can%s create, delete and rename files in the directory",
- " %s can%s pass through the directory to other files or dirs",
- } ;
- static char *file_permissions[] = {
- " %s can%s read the file",
- " %s can%s change the file",
- " %s can%s run the program or shell script in the file",
- } ;
- char **perm_details = file_permissions ;
-
-
-
- /* first create a window to use */
-
- window = newwin(LINES - SPEC_WINDOW_ROWS,COLS,SPEC_WINDOW_ROWS,0);
- werase(window);
- keypad(window,TRUE);
- max_row = LINES - (SPEC_WINDOW_ROWS + 1);
-
- /* get the info for the file */
-
- #if !defined(SYSV) || defined(sun)
- status = lstat(ent->filename,&statbuf);
- #else
- status = stat(ent->filename,&statbuf);
- #endif
-
- if(status != 0)
- return(FAILURE);
-
- /* now write the stuff to the screen */
-
- strtcpy(buf,ent->filename); /* make control chars printable first */
- put_buf(window,buf,&row,max_row,0,A_BOLD,FALSE,' ',FALSE);
- put_buf(window,"",&row,max_row,0,A_BOLD,FALSE,' ',FALSE);
-
- #if !defined(SYSV) || defined(sun)
- if(ent->type == LINK)
- {
- /* get what it's linked to */
-
- length = readlink(ent->filename,buf2,MAXNAMLEN+10);
-
- if(length > 0)
- {
- buf2[length] = '\0'; /* make it a string */
- cat(3,buf,link_str,buf2);
- put_buf(window,buf,&row,max_row,sizeof(link_str),A_NORMAL,FALSE,' ',
- FALSE);
- }
- }
- #endif
-
- prot = add_filetype(ent->type,ent->prot);
- sprintf(buf,"Protection: %s Owner: %s Group: %s",
- prot_val_to_str(prot), get_owner(ent->uid),get_group(ent->gid));
-
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE);
-
- /* first determine what type of file it is */
-
- switch(prot & S_IFMT)
- {
- case(S_IFREG):
- put_buf(window,"This is a standard file.",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- #if !defined(SYSV) || defined(sun)
- sprintf(buf,"Size in bytes: %d Size in blocks: %d",statbuf.st_size,
- statbuf.st_blocks);
- #else
- sprintf(buf,"Size in bytes: %d",statbuf.st_size);
- #endif
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- break;
- case(S_IFDIR):
- put_buf(window,"This file is a directory.",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- perm_details = dir_permissions ;
- #if !defined(SYSV)
- if(prot & S_ISGID)
- put_buf(window," Files created in this directory will be of the same group as the directory.",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- else
- put_buf(window," Files created in this directory will be of the same group as your default.",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- #endif
- break;
- case(S_IFCHR):
- put_buf(window,"This file represents a character device.",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- sprintf(buf," The major device number is %d, minor number %d.",statbuf.st_size,
- statbuf.st_blocks);
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- break;
- case(S_IFBLK):
- put_buf(window,"This file represents a block device.",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- sprintf(buf," The major device number is %d, minor number %d.",statbuf.st_size,
- statbuf.st_blocks);
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- break;
- case(S_IFIFO):
- put_buf(window,"This file is a named pipe.",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- sprintf(buf," There are %d unread bytes in the pipe",statbuf.st_size);
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- break;
- #if defined(S_IFLNK)
- case(S_IFLNK):
- put_buf(window,"This file is a symbolic link.",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- break;
- #endif
- default:
- put_buf(window,"This file is an unknown type.",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- break;
- }
-
- /* create and print the detailed permission string */
-
- put_buf(window,"Details on permissions:",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE);
- for(i = j = 0 ; i < 3 ; i++, j+=3 )
- {
- sprintf( buf, perm_details[ 0 ], who_perm[ i ],
- (prot & (S_IREAD >> j)) ? "" : "not" ) ;
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- sprintf( buf, perm_details[ 1 ], who_perm[ i ],
- (prot & (S_IWRITE >> j)) ? "" : "not" ) ;
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- sprintf( buf, perm_details[ 2 ], who_perm[ i ],
- (prot & (S_IEXEC >> j)) ? "" : "not" ) ;
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
- }
-
- if(prot & S_ISUID)
- put_buf(window,"The setuid bit is set.",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
-
- if(prot & S_ISGID)
- put_buf(window,"The sgid bit is set.",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
-
- if(prot & S_ISVTX)
- put_buf(window,"The sticky bit is set.",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE) ;
-
- sprintf(buf,"Inode #: %d Number of links: %d",statbuf.st_ino,
- statbuf.st_nlink);
-
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE);
-
- temp = (long) statbuf.st_atime;
- strcpy(time1,ctime(&temp));
- temp = (long) statbuf.st_mtime;
- strcpy(time2,ctime(&temp));
- temp = (long) statbuf.st_ctime;
- strcpy(time3,ctime(&temp));
-
- time1[TIME_STR_MAX] = '\0'; /* lop off the \n's */
- time2[TIME_STR_MAX] = '\0';
- time3[TIME_STR_MAX] = '\0';
-
- cat(3,buf,"Last access: ",time1);
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE);
-
- cat(3,buf,"Last modification: ",time2);
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE);
-
- cat(3,buf,"Last status change: ",time3);
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE);
-
- if(args->text)
- {
- if(ent->text == NULL)
- strcpy(buf,"Text descriptor: None");
- else
- cat(3,buf,"Text descriptor: ",ent->text);
-
- put_buf(window,buf,&row,max_row,0,A_NORMAL,FALSE,' ',FALSE);
- }
-
- if(ent->command)
- {
- put_buf(window,"",&row,max_row,0,A_NORMAL,FALSE,' ',FALSE);
- put_buf(window,"File commands:",&row,max_row,0,A_BOLD,FALSE,' ',FALSE);
-
- comm_ptr = ent->command;
-
- if(comm_ptr->comm_copy)
- {
- cat(4,buf,indent_str,copy_str,comm_ptr->copy_name);
- put_buf(window,buf,&row,max_row,sizeof(indent_str) + sizeof(copy_str),
- A_NORMAL,FALSE,' ',FALSE);
- }
-
- if(comm_ptr->comm_ren)
- {
- cat(4,buf,indent_str,rename_str,comm_ptr->ren_name);
- put_buf(window,buf,&row,max_row,sizeof(indent_str) +
- sizeof(rename_str),A_NORMAL,FALSE,' ',FALSE);
- }
-
- if(comm_ptr->comm_prot)
- {
- cat(4,buf,indent_str,protect_str,
- prot_val_to_str(add_filetype(ent->type,comm_ptr->prot)));
- put_buf(window,buf,&row,max_row,sizeof(indent_str) +
- sizeof(protect_str),A_NORMAL,FALSE,' ',FALSE);
- }
-
- if(comm_ptr->comm_text)
- {
- cat(4,buf,indent_str,text_str,comm_ptr->text);
- put_buf(window,buf,&row,max_row,sizeof(indent_str) + sizeof(text_str),
- A_NORMAL,FALSE,' ',FALSE);
- }
-
- if(comm_ptr->comm_own)
- {
- cat(4,buf,indent_str,owner_str,get_owner(comm_ptr->owner));
- put_buf(window,buf,&row,max_row,sizeof(indent_str) + sizeof(owner_str),
- A_NORMAL,FALSE,' ',FALSE);
- }
-
- if(comm_ptr->comm_grp)
- {
- cat(4,buf,indent_str,group_str,get_group(comm_ptr->group));
- put_buf(window,buf,&row,max_row,sizeof(indent_str) + sizeof(group_str),
- A_NORMAL,FALSE,' ',FALSE);
- }
-
- if(comm_ptr->comm_del)
- {
- cat(3,buf,indent_str,delete_str);
- put_buf(window,buf,&row,max_row,sizeof(indent_str) +
- sizeof(delete_str),A_NORMAL,FALSE,' ',FALSE);
- }
- }
- else
- put_buf(window,"File commands: None",&row,max_row,0,A_NORMAL,
- FALSE,' ',FALSE);
-
-
- put_buf(window," ",&row,max_row,0,A_REVERSE,TRUE,' ',TRUE);
- delwin(window); /* get rid of the window */
- return(SUCCESS);
-
- } /*** info ***/
-