home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / COMMS / PSIONMAI / PMFULLSO / SUNMAIL / SCCS / S8.C < prev    next >
Encoding:
Text File  |  1995-07-06  |  5.5 KB  |  306 lines

  1. h25617
  2. s 00031/00014/00215
  3. d D 1.4 95/07/06 20:13:16 tim 4 3
  4. c user the getpass command to get the users password as it is secure. modified getstr so is the field is secure and there is an existing string a - will remove the data
  5. e
  6. s 00001/00000/00228
  7. d D 1.3 95/07/06 14:49:16 tim 3 2
  8. c forgot to include pwd.h, now fixed
  9. e
  10. s 00013/00000/00215
  11. d D 1.2 95/07/06 14:12:37 tim 2 1
  12. c getuname moved from talktopopconfig to talktopopconf so it is available to
  13. c talktopop
  14. e
  15. s 00215/00000/00000
  16. d D 1.1 95/07/06 14:00:28 tim 1 0
  17. c 
  18. e
  19. u
  20. U
  21. f e 0
  22. t
  23. T
  24. I 1
  25. /* this is a library of routines to read / write config files
  26.    and deal with passwords etc. */
  27. /* the file format is
  28.    username
  29.    password
  30.    pop server name
  31.    number of output file to start with
  32.    delete flag
  33.    extract from start or end of mail file 
  34.    verbose flag
  35.    max size of email to retrieve
  36.    max number of emails to retrieve
  37.    pop server name (e.g. pop-3)
  38.    pop protocol name (e.g. tcp)
  39.    */
  40.  
  41.  
  42. #include "talktopop.h"
  43. #include <stdio.h> 
  44. #include <string.h> 
  45. I 4
  46. #include <stdlib.h>
  47. E 4
  48. I 3
  49. #include <pwd.h>
  50. E 3
  51. extern char popserver [] ;
  52. extern char popname [] ;
  53. extern char protname [] ;
  54. extern char uname [] ;
  55. extern char passwd [] ;
  56. extern int filestartno ;
  57. extern int dodel ;
  58. extern int direction ;
  59. extern int verbose ;
  60. extern int maxsize ;
  61. extern int maxemail ;
  62. extern int hnset, unset, pwset ;
  63.  
  64. confinit()
  65. {
  66.     strcpy(popserver, "") ;
  67.     strcpy(popname, POPNAME) ;
  68.     strcpy(protname, PROTNAME) ;
  69.     strcpy(uname, "") ;
  70.     strcpy(passwd, "") ;
  71.     filestartno = 0 ;
  72.     dodel - FALSE ;
  73.     direction = TRUE ;
  74.     verbose = FALSE ;
  75.     maxsize = MAXSIZE ;
  76.     maxemail = MAXCOUNT ;
  77.     hnset = unset = pwset = FALSE ;
  78. }
  79.  
  80. readconf()
  81. {
  82.     FILE * fd ;
  83.     char  tmp[1024] ;
  84.     int ret ;
  85.     if ((fd = fopen(POPCONF, "r")) == NULL)
  86.         return ;
  87.     if (getline(fd, uname) == TRUE) /* username */
  88.         unset = TRUE ;
  89.     if (getline(fd, passwd) == TRUE) /* password */
  90.         pwset = TRUE ;
  91.     if (getline(fd, popserver) == TRUE) /* server name */
  92.         hnset = TRUE ;
  93.     if (getline(fd, tmp) == TRUE) /* output file start number */
  94.         filestartno = atoi(tmp) ;
  95.     if (getline(fd, tmp) == TRUE) /* delete flag */
  96.     {
  97.         if (tmp[0] == 'T')
  98.             dodel = TRUE ;
  99.         else
  100.             dodel = FALSE ;
  101.     }
  102.     if (getline(fd, tmp) == TRUE) /* start from begining or end of mail file */
  103.     {
  104.         if (tmp[0] == 'T')
  105.             direction = TRUE ;
  106.         else
  107.             direction = FALSE ;
  108.     }
  109.     if (getline(fd, tmp) == TRUE) /* be verbose or not */
  110.     {
  111.         if (tmp[0] == 'T')
  112.             verbose = TRUE ;
  113.         else
  114.             verbose = FALSE ;
  115.     }
  116.     if (getline(fd, tmp) == TRUE) /* max email size */
  117.         maxsize = atoi(tmp) ;
  118.     if (getline(fd, tmp) == TRUE) /* max emails to retrieve */
  119.         maxemail = atoi(tmp) ;
  120.     getline(fd, popname) ;
  121.     getline(fd, protname) ;
  122.     fclose(fd) ;
  123. }
  124.  
  125. writeconf()
  126. {
  127.     FILE * fd ;
  128.     if ((fd = fopen(POPCONF, "w")) == NULL)
  129.     {
  130.         printf("ERROR, Cant open %s to write pop output file\n") ;
  131.         return ;
  132.     }
  133.     fprintf(fd, "%s\n", uname) ;
  134.     fprintf(fd, "%s\n", passwd) ;
  135.     fprintf(fd, "%s\n", popserver) ;
  136.     fprintf(fd, "%d\n", filestartno) ;
  137.     if (dodel == TRUE)
  138.         fprintf(fd, "TRUE\n") ;
  139.     else
  140.         fprintf(fd, "FALSE\n") ;
  141.     if (direction == TRUE)
  142.         fprintf(fd, "TRUE\n");
  143.     else
  144.         fprintf(fd, "FALSE\n") ;
  145.     if (verbose == TRUE)
  146.         fprintf(fd, "TRUE\n") ;
  147.     else
  148.         fprintf(fd, "FALSE\n") ;
  149.     fprintf(fd, "%d\n", maxsize) ;
  150.     fprintf(fd, "%d\n", maxemail) ;
  151.     fprintf(fd, "%s\n", popname) ;
  152.     fprintf(fd, "%s\n", protname) ;
  153.     fclose(fd) ;
  154. }
  155. getyn(prompt, current)
  156. char * prompt ;
  157. int * current ;
  158. {
  159.     char tmp[1024] ;
  160.     printf("Please enter %s [%s]\n", prompt, (*current == TRUE) ? "TRUE" : "FALSE") ;
  161.     gets(tmp) ;
  162.     if (tmp[0] == '\0')
  163.     {
  164.         return ;
  165.     }
  166.     else
  167.     {
  168.         *current = ((tmp[0] == 't') || (tmp[0] == 'T')) ? TRUE : FALSE ;
  169.         return ;
  170.     }
  171. }
  172.     
  173. getline(fd, str)
  174. FILE * fd ;
  175. char * str ;
  176. {
  177.     int len ;
  178.     char * ret ;
  179.     char tmp[1024] ;
  180.     ret = fgets(tmp, 1024, fd) ;
  181.     if (ret == NULL)
  182.         return(FALSE) ;
  183.     /* remove the newline */
  184.     len = strlen(tmp) ;
  185.     if (tmp[len-1] == '\n')
  186.         tmp[len-1] = '\0' ;
  187.     if (len -1 <= 0)
  188.         return(FALSE) ;
  189.     /* we have a string with data in it */
  190.     strcpy(str, tmp) ;
  191.     return(TRUE) ;
  192. }
  193.  
  194. getno(number, prompt)
  195. int * number ;
  196. char * prompt;
  197. {
  198.     char tmp[1024] ;
  199.     printf("Please enter %s [%d]\n", prompt, *number) ;
  200.     gets(tmp) ;
  201.     if (tmp[0] == '\0')
  202.     {
  203.         return ;
  204.     }
  205.     else
  206.     {
  207.         *number = atoi(tmp) ;
  208.         return ;
  209.     }
  210. }
  211.  
  212. getstr(str, prompt, noecho)
  213. int noecho ;
  214. char * str, * prompt ;
  215. {
  216. D 4
  217.     char tmp[1024] ;
  218.     if (noecho == TRUE)
  219. E 4
  220. I 4
  221.     char tmp[1024], tmp1[1024] ;
  222.     char * strptr ;
  223.     if (str[0] == '\0')
  224. E 4
  225.     {
  226. D 4
  227.         /* turn of terminal echoing */
  228.         printf("Please enter %s\n", prompt) ;
  229.         gets(str) ;
  230.         /* reset the terminal state */
  231. E 4
  232. I 4
  233.         sprintf(tmp1, "Please enter %s : ", prompt) ;
  234.         if (noecho == TRUE)
  235.         {
  236.             strptr = getpass(tmp1) ;
  237.             strcpy(str, strptr) ;
  238.         }
  239.         else
  240.         {
  241.             printf("%s", tmp1) ;
  242.             gets(str) ;
  243.         }
  244. E 4
  245.         return ;
  246.     }
  247. D 4
  248.     if (str[0] == 0)
  249.     {
  250.         printf("Please enter %s\n", prompt) ;
  251.         gets(str) ;
  252.         return ;
  253.     }
  254. E 4
  255.     else
  256.     {
  257. D 4
  258.         printf("Please enter %s [%s]\n", prompt, str) ;
  259.         gets(tmp) ;
  260. E 4
  261. I 4
  262.         if (noecho == TRUE)
  263.         {
  264.             sprintf(tmp1, "Please enter %s [exiting value not pronted for security reasons], - to empty this field : ", prompt) ;
  265.             strptr = getpass(tmp1) ;
  266.             strcpy(tmp, strptr) ;
  267.             if (tmp[0] == '-')
  268.             {
  269.                 str[0] = '\0' ;
  270.                 return ;
  271.             }
  272.         }
  273.         else
  274.         {
  275.             printf("Please enter %s [%s] : ", prompt, str) ;
  276.             gets(tmp) ;
  277.         }
  278. E 4
  279.         if (tmp[0] == '\0')
  280.         {
  281.             return ;
  282.         }
  283.         else
  284.         {
  285.             strcpy(str, tmp) ;
  286.             return ;
  287.         }
  288.     }
  289. }
  290. I 2
  291.  
  292.  
  293. getuname(str)
  294. char * str ;
  295. {
  296.     uid_t uid ;
  297.     struct passwd *pwent ;
  298.     uid = getuid() ;
  299.     pwent = getpwuid(uid) ;
  300.     if (pwent == NULL)
  301.         return ;
  302.     strcpy(str, pwent->pw_name) ;
  303. }
  304. E 2
  305. E 1
  306.