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 >
Text File  |  1991-07-02  |  4KB  |  143 lines

  1. Newsgroups: alt.sources
  2. From: robert@lunatix.uucp (Robert Sexton)
  3. Subject: fixnice - Change default nice value for users on SCO Unix
  4. Date: Mon, 01 Jul 1991 15:59:10 GMT
  5. Message-ID: <1991Jul01.155910.24760@lunatix.uucp>
  6.  
  7. Well here is a handy dandy little utility I wrote because I
  8. thought the sysadmsh interface was too clumsy.  syntax:
  9. fixnice <nicevalue> <user1> <user2> ...... <userN>
  10. it is designed to take a list of users either from the standard
  11. input or on the command line.  You need the following lines in
  12. your Makefile to compile it:
  13.  
  14. CFLAGS = -DSecureWare
  15. LDFLAGS = -lmalloc -lc_s -lprot
  16.  
  17.  
  18. /*
  19.  * Fixnice.c             
  20.  * Set users /tcb file entries to a certain nice value.
  21.  * For SCO unix 3.2, or any other poor saps who use SecureWare.
  22.  * Robert Sexton 5/7/91  robert@lunatix.UUCP
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include <memory.h>
  27. /* TCB requirements */
  28. #include <sys/types.h>
  29. #include <sys/security.h>
  30. #include <sys/audit.h>
  31. #include <prot.h>
  32. /* extras */
  33.  
  34. int changenice(char *username,int nice) ;
  35.  
  36. main(int argc, char *argv[])
  37. {
  38. int desired_nice;
  39.  
  40. int index; /* step through userlist */
  41. int errorcode = 0;
  42. int status;
  43.  
  44. char username[9]; /* We pass this to changenice */
  45.  
  46. /* first do the security bullshit call */
  47. set_auth_parameters(argc,argv);
  48.  
  49. /* stupidity check */
  50. if ( argc < 2 ) {
  51.     fprintf(stderr,"Usage: fixnice [nice value] user1 user2 ... \n");
  52.     fprintf(stderr,"  or: userlist|fixnice [nice value] \n");
  53.     exit(1);
  54.     }
  55. /* get nice value, and do a little error check */
  56. desired_nice = atoi(argv[1]);
  57.  
  58. if ( desired_nice < -20 || desired_nice > 20 ) {
  59.     fprintf(stderr,"Acceptable nice values lie between -20 and 20\n");
  60.     exit(1);
  61.     }
  62.  
  63. if ( argc == 2 ) {
  64.     while ( scanf("%s[\n\t ]",username) != EOF ) {
  65.         if (changenice(username,desired_nice))
  66.             errorcode++;
  67.         }
  68.     }
  69. else {
  70.     for (index=2;index < argc;index++) {
  71.         sscanf(argv[index],"%s",username) ;
  72.         if (changenice(username,desired_nice))
  73.             errorcode++;
  74.         }
  75.     }
  76. exit(errorcode);
  77. } /* main() */
  78.  
  79.     
  80. int changenice(char *username,int niceval) {
  81.     
  82.     struct pr_passwd *cur_usr;    /* we have to make a personal copy */
  83.     struct pr_passwd *tmp_entry; /* getprpwname puts it's stuff here */
  84.     
  85.     tmp_entry = getprpwnam(username); /* get the pointer */
  86.  
  87.     /* sanity checks we do therse before any memcpys */
  88.  
  89.     if ( tmp_entry == NULL ) {
  90.         fprintf(stderr,"Error looking up user %s\n",username);    
  91.         return(1);
  92.         }
  93.  
  94.     /* now we copy the static data someplace where we can modify it */
  95.  
  96.     /* malloc some memory */
  97.     cur_usr = (struct pr_passwd *) malloc(sizeof(struct pr_passwd));
  98.  
  99.     memcpy(cur_usr,tmp_entry,sizeof(struct pr_passwd));
  100.  
  101. #ifdef DEBUG    
  102.     fprintf(stderr,"%s old nice value:%d\n",username,cur_usr->ufld.fd_nice);
  103.     fprintf(stderr,"system nice value:%d\n",cur_usr->sfld.fd_nice);
  104. #endif    
  105.  
  106.     /* this is it, one field change */    
  107.     cur_usr->ufld.fd_nice = niceval;
  108.  
  109.     /* now we tell it we changed a field.  We check against the */
  110.     /* system defaults */
  111.  
  112.     if ( cur_usr->ufld.fd_nice != cur_usr->sfld.fd_nice ) {
  113.         cur_usr->uflg.fg_nice = 1;
  114.         fprintf(stderr,"Set user %s to nice value %d\n",\
  115.             username,cur_usr->ufld.fd_nice);
  116.         }
  117.     else {
  118.         cur_usr->uflg.fg_nice = 0;
  119.         fprintf(stderr,"Set user %s to default nice value %d\n",\
  120.             username,cur_usr->sfld.fd_nice);
  121.         }
  122.  
  123.     if ( putprpwnam(username,cur_usr) == NULL ) {
  124.         fprintf(stderr,"Error writing user %s\n",username);    
  125.         return(1);
  126.         }
  127.     /* We don't want this data lying around */
  128.     memset(cur_usr,0,sizeof(struct pr_passwd));
  129.     free(cur_usr);
  130. }
  131.  
  132.  
  133.  
  134. Robert Sexton,  Lexington Public Access Unix  (lunatix)
  135. robert@lunatix.UUCP ukma!lunatix!robert
  136. Bringing you the wonderful world of Unix since 1990.
  137. `Money for nothing and your scripts for free'
  138. -- 
  139. Robert Sexton,  Lexington Public Access Unix  (lunatix)
  140. robert@lunatix.UUCP ukma!lunatix!robert
  141. Bringing you the wonderful world of Unix since 1990.
  142. `Money for nothing and your scripts for free'
  143.