home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
3
/
3569
< prev
next >
Wrap
Text File
|
1991-07-02
|
4KB
|
143 lines
Newsgroups: alt.sources
From: robert@lunatix.uucp (Robert Sexton)
Subject: fixnice - Change default nice value for users on SCO Unix
Date: Mon, 01 Jul 1991 15:59:10 GMT
Message-ID: <1991Jul01.155910.24760@lunatix.uucp>
Well here is a handy dandy little utility I wrote because I
thought the sysadmsh interface was too clumsy. syntax:
fixnice <nicevalue> <user1> <user2> ...... <userN>
it is designed to take a list of users either from the standard
input or on the command line. You need the following lines in
your Makefile to compile it:
CFLAGS = -DSecureWare
LDFLAGS = -lmalloc -lc_s -lprot
/*
* Fixnice.c
* Set users /tcb file entries to a certain nice value.
* For SCO unix 3.2, or any other poor saps who use SecureWare.
* Robert Sexton 5/7/91 robert@lunatix.UUCP
*/
#include <stdio.h>
#include <memory.h>
/* TCB requirements */
#include <sys/types.h>
#include <sys/security.h>
#include <sys/audit.h>
#include <prot.h>
/* extras */
int changenice(char *username,int nice) ;
main(int argc, char *argv[])
{
int desired_nice;
int index; /* step through userlist */
int errorcode = 0;
int status;
char username[9]; /* We pass this to changenice */
/* first do the security bullshit call */
set_auth_parameters(argc,argv);
/* stupidity check */
if ( argc < 2 ) {
fprintf(stderr,"Usage: fixnice [nice value] user1 user2 ... \n");
fprintf(stderr," or: userlist|fixnice [nice value] \n");
exit(1);
}
/* get nice value, and do a little error check */
desired_nice = atoi(argv[1]);
if ( desired_nice < -20 || desired_nice > 20 ) {
fprintf(stderr,"Acceptable nice values lie between -20 and 20\n");
exit(1);
}
if ( argc == 2 ) {
while ( scanf("%s[\n\t ]",username) != EOF ) {
if (changenice(username,desired_nice))
errorcode++;
}
}
else {
for (index=2;index < argc;index++) {
sscanf(argv[index],"%s",username) ;
if (changenice(username,desired_nice))
errorcode++;
}
}
exit(errorcode);
} /* main() */
int changenice(char *username,int niceval) {
struct pr_passwd *cur_usr; /* we have to make a personal copy */
struct pr_passwd *tmp_entry; /* getprpwname puts it's stuff here */
tmp_entry = getprpwnam(username); /* get the pointer */
/* sanity checks we do therse before any memcpys */
if ( tmp_entry == NULL ) {
fprintf(stderr,"Error looking up user %s\n",username);
return(1);
}
/* now we copy the static data someplace where we can modify it */
/* malloc some memory */
cur_usr = (struct pr_passwd *) malloc(sizeof(struct pr_passwd));
memcpy(cur_usr,tmp_entry,sizeof(struct pr_passwd));
#ifdef DEBUG
fprintf(stderr,"%s old nice value:%d\n",username,cur_usr->ufld.fd_nice);
fprintf(stderr,"system nice value:%d\n",cur_usr->sfld.fd_nice);
#endif
/* this is it, one field change */
cur_usr->ufld.fd_nice = niceval;
/* now we tell it we changed a field. We check against the */
/* system defaults */
if ( cur_usr->ufld.fd_nice != cur_usr->sfld.fd_nice ) {
cur_usr->uflg.fg_nice = 1;
fprintf(stderr,"Set user %s to nice value %d\n",\
username,cur_usr->ufld.fd_nice);
}
else {
cur_usr->uflg.fg_nice = 0;
fprintf(stderr,"Set user %s to default nice value %d\n",\
username,cur_usr->sfld.fd_nice);
}
if ( putprpwnam(username,cur_usr) == NULL ) {
fprintf(stderr,"Error writing user %s\n",username);
return(1);
}
/* We don't want this data lying around */
memset(cur_usr,0,sizeof(struct pr_passwd));
free(cur_usr);
}
Robert Sexton, Lexington Public Access Unix (lunatix)
robert@lunatix.UUCP ukma!lunatix!robert
Bringing you the wonderful world of Unix since 1990.
`Money for nothing and your scripts for free'
--
Robert Sexton, Lexington Public Access Unix (lunatix)
robert@lunatix.UUCP ukma!lunatix!robert
Bringing you the wonderful world of Unix since 1990.
`Money for nothing and your scripts for free'