home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / XBBS7200.ZIP / XBBS7200.TAR / purguser / purguser.c
Encoding:
C/C++ Source or Header  |  1989-10-12  |  4.3 KB  |  195 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <pwd.h>
  4.  
  5. struct name_list {
  6.     char fname[99] ;
  7.     char lname[99] ;
  8.     struct name_list *next ;
  9. } ;
  10.  
  11. struct name_list *nlhead ;
  12.  
  13. void add_to_nl();
  14. void clean_up_nl() ;
  15.  
  16. main()
  17. {
  18. FILE *inbuf, *outbuf;
  19. struct passwd *pw ;
  20. int code;
  21. int count;
  22. char infile[99], outfile[99];
  23. char cut_off[99] ;
  24. char u_fname[99], u_lname[99], u_password[99], u_time1[99];
  25. char u_date1[99], u_time2[99], u_date2[99], u_city[99];
  26. char l_m_base[5], l_f_base[5], xprt[3], toggle[3];
  27. long priv, l1, l2 ;
  28.  
  29. nlhead = (struct name_list *)NULL ;
  30. printf("\nPurguser : a user purge by date program for XBBS\n");
  31. printf("by Chuck Brandt 89.10.12 CIMTECHNOLOGIES XBBS (515)232-0072\n");
  32. printf("This program will remove users who have not logged on your XBBS\n");
  33. printf("since the date you specify.  It modifies users.bbs and userpriv.bbs\n");
  34. printf("and saves backups of each file with an additional extension of .o\n");
  35. printf("If you don't want to do this press <DEL> now!\n") ;
  36.  
  37. printf("\nInput the full path name of the user file: ");
  38. scanf("%s", outfile);
  39. printf("\n");
  40. printf("\nEnter cut off date in the form MM/DD/YY: ") ;
  41. scanf("%s", cut_off) ;
  42. printf("\n") ;
  43. strcpy(infile,outfile) ;
  44. strcat(infile,".o") ;
  45. unlink(infile) ;
  46. link(outfile,infile) ;
  47. unlink(outfile) ;
  48. if((inbuf = fopen(infile, "r" )) == NULL) {
  49.     printf("\n\rError opening input users file.\n\r");
  50.     exit(1);
  51. }
  52. if((outbuf = fopen(outfile, "w" )) == NULL) {
  53.     printf("\n\rError opening output users file.\n\r");
  54.     exit(1);
  55. }
  56.  
  57. while(1) {
  58.     code = fscanf(inbuf,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~\n",
  59.     u_fname, u_lname, u_password, u_time1, u_date1,
  60.     u_time2, u_date2, u_city, l_m_base, l_f_base, xprt, toggle);
  61.     if(code < 12 ) break;
  62.     if ((date_compare(cut_off,u_date2)) <= 0) 
  63.         fprintf(outbuf,"%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~%s~\n",
  64.         u_fname, u_lname, u_password, u_time1, u_date1,
  65.         u_time2, u_date2, u_city, l_m_base, l_f_base, xprt, toggle);
  66.     else
  67.         add_to_nl( u_fname, u_lname ) ;
  68. }
  69.  
  70. fclose(inbuf);
  71. fclose(outbuf) ;
  72. chmod(outfile,0660) ;
  73. pw = getpwnam("bbs") ;
  74.  
  75. if (pw != (struct passwd *)NULL) 
  76.     chown(outfile,pw->pw_uid,pw->pw_gid) ;    
  77.  
  78. /* update userpriv.bbs */
  79. printf("\nInput the full path name of the userpriv file: ");
  80. scanf("%s", outfile);
  81. printf("\n");
  82. strcpy(infile,outfile) ;
  83. strcat(infile,".o") ;
  84. unlink(infile) ;
  85. link(outfile,infile) ;
  86. unlink(outfile) ;
  87. if((inbuf = fopen(infile, "r" )) == NULL) {
  88.     printf("\n\rError opening input userpriv file.\n\r");
  89.     exit(1);
  90. }
  91. if((outbuf = fopen(outfile, "w" )) == NULL) {
  92.     printf("\n\rError opening output userpriv file.\n\r");
  93.     exit(1);
  94. }
  95. while (1) {
  96.     code = fscanf(inbuf,"%s %s %ld %ld %ld\n",u_fname, u_lname, &priv, &l1, &l2) ;    
  97.     if (code != 5) break ;
  98.     if (!in_list(u_fname, u_lname))
  99.         fprintf(outbuf,"%s %s %ld %ld %ld\n",u_fname, u_lname, priv, l1, l2) ;
  100. }
  101. clean_up_nl() ;
  102. fclose(inbuf);
  103. fclose(outbuf) ;
  104. chmod(outfile,0660) ;
  105. pw = getpwnam("bbs") ;
  106.  
  107. if (pw != (struct passwd *)NULL) 
  108.     chown(outfile,pw->pw_uid,pw->pw_gid) ;    
  109.     
  110. }
  111.  
  112. void add_to_nl( first, last ) 
  113. char *first, *last ;
  114. {
  115. struct name_list *cur, *new ;
  116.  
  117. new = (struct name_list *)malloc(sizeof(struct name_list)) ;
  118. if (new == (struct name_list *)NULL) {
  119.     fprintf(stderr,"purguser : ran out of memory!\n") ;
  120.     return;
  121. }
  122. new->next = (struct name_list *)NULL ;
  123. strcpy(new->fname,first) ;
  124. strcpy(new->lname,last) ;
  125.  
  126. if (nlhead == (struct name_list *)NULL)  {
  127.     nlhead = new ;
  128.     return ;
  129. }
  130. cur = nlhead ;
  131. while (cur->next != (struct name_list *)NULL)
  132.     cur = cur->next ;
  133. cur->next = new ;
  134. return ;
  135. }
  136.  
  137. int in_list(first, last)
  138. char *first, *last ;
  139. {
  140. struct name_list *cur ;
  141.  
  142. cur = nlhead ;
  143. while (cur) {
  144.     if ((!strcmp(first,cur->fname)) && (!strcmp(last,cur->lname)))
  145.         return(1) ;
  146.     cur = cur->next ;
  147. }
  148. return(0) ;
  149. }
  150.  
  151. void clean_up_nl()
  152. {
  153. struct name_list *cur, *pv ;
  154.  
  155. cur = nlhead ;
  156. while (cur) {
  157.     pv = cur ;
  158.     cur = cur->next ;
  159.     free(pv) ;
  160. }
  161. }
  162.  
  163. int date_compare( d1, d2 )
  164. char *d1, *d2 ;
  165. {
  166. int mon1, day1, yr1, mon2, day2, yr2 ;
  167.  
  168. sscanf(d1,"%d/%d/%d", &mon1, &day1, &yr1) ;
  169. sscanf(d2,"%d/%d/%d", &mon2, &day2, &yr2) ;
  170. yr1 = yr1 + 1900 ;
  171. yr2 = yr2 + 1900 ;
  172.  
  173. if (yr1 == yr2) {
  174.     if (mon1 == mon2) {
  175.         if (day1 == day2) 
  176.             return(0) ;
  177.         else { 
  178.             if (day1 > day2) 
  179.                 return(1) ;
  180.             else 
  181.                 return(-1) ;
  182.         }
  183.     }
  184.     else  {
  185.               if (mon1 > mon2) 
  186.             return(1) ;
  187.          else 
  188.             return(-1) ;
  189.     }
  190. }
  191. if (yr1 > yr2) return(1) ;
  192. else return(-1) ;
  193. }
  194.  
  195.