home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / inetray / utils.c < prev    next >
C/C++ Source or Header  |  1992-06-25  |  2KB  |  81 lines

  1. /*======================================================================
  2.                     U T I L S . C 
  3.                     doc: Mon Mar 23 11:42:27 1992
  4.                     dlm: Fri Jun 26 11:32:02 1992
  5.                     (c) 1992 ant@ips.id.ethz.ch
  6.                     uE-Info: 34 0 T 0 0 72 2 2 8 ofnI
  7. ======================================================================*/
  8.  
  9. #include    <stdio.h>
  10. #include    <pwd.h>
  11. #include    <string.h>
  12. #include    <sys/types.h>
  13. #include    <sys/param.h>
  14. #include    <rpc/rpc.h>
  15. #include    "common.h"
  16.  
  17. #ifdef SNAKE_QUIRK            /* provide ``std'' funs */
  18.  
  19. char *getwd(path)
  20. char path[MAXPATHLEN];
  21. {
  22.     char *getcwd();
  23.     return getcwd(path,MAXPATHLEN);
  24. }
  25.  
  26. setreuid(ruid,euid)
  27. long ruid,euid;
  28. {
  29.     return setresuid(ruid,euid,-1);
  30. }
  31.     
  32. #endif
  33.  
  34. void VersionPrint() {}            /* the raylibs need that */
  35.     
  36. void stripHome(uid,path)        /* home -> ~ */
  37. uid_t uid; char *path;
  38. {
  39.     int    i = 0,t = 0;
  40.     char    cwd[MAXPATHLEN],home[MAXPATHLEN];
  41.     struct passwd *p;
  42.  
  43.     if (path[0] != '/')        /* errmes from getwd */
  44.         return;
  45.     getwd(cwd);            /* save current wdir */
  46.     p = getpwuid(geteuid());    /* get real home dir */
  47.     if (p == NULL) return;
  48.     if (chdir(p->pw_dir) < 0)    /* can't access home */ 
  49.         strncpy(home,cwd,MAXPATHLEN);
  50.     else                 /* real name of home */
  51.         getwd(home);        /* automount ... */
  52.     if (chdir(cwd) < 0)         /* shouldn't happen at all! */
  53.         getwd(path);
  54.  
  55.     while ((home[i] != '\0') &&    /* strip out home */
  56.            (path[i] == home[i])) i++;
  57.     if (home[i] != '\0') return;
  58.  
  59.     path[t++] = '~';        /* add tilde */
  60.     while ((path[t++] = path[i++]) != '\0') ; /* copy rest */
  61. }
  62.  
  63. void addHome(uid,pIn,pOut)        /* ~ -> home */
  64. uid_t uid; char *pIn,*pOut;
  65. {
  66.     int    s = 0,t = 0,i = 0;
  67.     struct passwd *p;
  68.  
  69.     if (pIn[s] == '~') {        /* do subst */
  70.         s++;
  71.         p = getpwuid(geteuid());
  72.         if (p == NULL) 
  73.             pOut[t++] = '.';
  74.         else
  75.             while (p->pw_dir[i] != '\0')
  76.                 pOut[t++] = p->pw_dir[i++];
  77.     }
  78.     while ((pOut[t++] = pIn[s++]) != '\0') ;
  79. }
  80.         
  81.