home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / secure / part01 next >
Encoding:
Text File  |  1989-05-04  |  8.7 KB  |  337 lines

  1. Path: uunet!island!argv
  2. From: argv@island.uu.net (Dan Heller)
  3. Newsgroups: comp.sources.x
  4. Subject: v03i100:  patches/additions to provide extra security in X, Part01/01
  5. Message-ID: <734@island.uu.net>
  6. Date: 3 May 89 18:00:30 GMT
  7. Organization: Island Graphics, Marin County, California
  8. Lines: 326
  9. Approved: island!argv@sun.com
  10.  
  11. Submitted-by: Mike Rowan <mtr@mentor.cc.purdue.edu>
  12. Posting-number: Volume 3, Issue 100
  13. Archive-name: secure/part01
  14.  
  15. [ I didn't apply the patch or test this stuff, sorry.  I did read the README
  16.   and it seems like a great idea.  --argv ]
  17.  
  18. #!/bin/sh
  19. # shar:    Shell Archiver
  20. #    Run the following text with /bin/sh to create:
  21. #    AUTHOR
  22. #    Patch.authorize
  23. #    README
  24. #    XAuthorize.c
  25. # This archive created: Wed May  3 11:17:57 1989
  26. # By:    Michael Rowan (Unix Groupie)
  27. cat << \SHAR_EOF > AUTHOR
  28. Mike Rowan, mtr@mentor.cc.purdue.edu
  29. Unix Group Systems Programmer
  30. Purdue University Computing Center
  31. SHAR_EOF
  32. cat << \SHAR_EOF > Patch.authorize
  33. *** /tmp/,RCSt1024408    Tue May  2 21:46:41 1989
  34. --- ./lib/X/XConnDis.c    Thu Jan 12 15:59:19 1989
  35. ***************
  36. *** 406,411 ****
  37. --- 406,414 ----
  38.   
  39.           int bytes=0;
  40.   
  41. + #ifdef PUCC
  42. +     _XAuthorizeClient(&auth_proto, &auth_string);
  43. + #endif
  44.           auth_length = strlen(auth_proto);
  45.           auth_strlen = strlen(auth_string);
  46.           client->nbytesAuthProto = auth_length;
  47. *** /tmp/,RCSt1024461    Tue May  2 21:47:56 1989
  48. --- server/os/4.2bsd/connection.c    Thu Jan 12 22:07:20 1989
  49. ***************
  50. *** 122,127 ****
  51. --- 122,131 ----
  52.   
  53.   extern ConnectionInput inputBuffers[];
  54.   
  55. + #ifdef PUCC
  56. + extern char    *ServerReadAuthString;
  57. + #endif /* PUCC */
  58.   int swappedClients[MAXSOCKS];
  59.   
  60.   extern int AutoResetServer();
  61. ***************
  62. *** 505,510 ****
  63. --- 509,532 ----
  64.   #undef STR
  65.       }
  66.       auth_string[slen] = '\0';
  67. + #ifdef PUCC
  68. +     /*
  69. +      * Check the password sent in auth_string 
  70. +       */
  71. +     if(ServerReadAuthString != NULL && strcmp(auth_string, ServerReadAuthString)) {
  72. + #define STR "Invalid Authorization Code (PUCC localism)"
  73. +         static int iNumberOfRejects = 0;
  74. +         *reason = (char *) xalloc(sizeof(STR));
  75. +         strcpy(*reason, STR);
  76. +         if(iNumberOfRejects++ >= 3) {
  77. +             fprintf(stderr,"XAUTH: 3 denied requests.\n");
  78. +         }
  79. +         return 0;
  80. + #undef STR
  81. +     }
  82. + #endif /* PUCC */
  83.   
  84.       /* At this point, if the client is authorized to change the access control
  85.        * list, we should getpeername() information, and add the client to
  86. *** /tmp/,RCSt1024466    Tue May  2 21:48:19 1989
  87. --- server/os/4.2bsd/osinit.c    Thu Jan 19 20:43:34 1989
  88. ***************
  89. *** 44,49 ****
  90. --- 44,54 ----
  91.   int    havergb = 0;
  92.   extern char *display;
  93.   
  94. + #ifdef PUCC
  95. + char    *ServerReadAuthString;
  96. + int    ReadUsersAuthFile();
  97. + #endif /* PUCC */
  98.   OsInit()
  99.   {
  100.       static Bool been_here = FALSE;
  101. ***************
  102. *** 88,91 ****
  103. --- 93,178 ----
  104.           havergb = 1;
  105.           else
  106.           ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath );
  107. + #ifdef PUCC
  108. +     if(!ReadUsersAuthFile(&ServerReadAuthString)) {
  109. +         ServerReadAuthString = NULL;
  110. +     }
  111. + #endif /* PUCC */
  112.   }
  113. + #ifdef PUCC
  114. + #include <sys/stat.h>
  115. + #include <sys/file.h>
  116. + #define XENVAUTHFILE    "/.xauth"
  117. + #define OTHERANDGROUP    07777700
  118. + #define    MAXPASSWORDLEN    99
  119. + int
  120. + ReadUsersAuthFile(ppchAuthString)
  121. +     char    **ppchAuthString;
  122. + {
  123. +     char    *pchAuthFilename = NULL,
  124. +         *pchUsersHome = NULL,
  125. +         sbBuffer[MAXPASSWORDLEN + 1];
  126. +     extern  char     *getenv();
  127. +     static  char    *gethomedir();
  128. +     FILE    *pFauthfile;
  129. +     struct stat StatBuf;
  130. +     int    iFlaglocal = 0;
  131. +     if(NULL == (pchAuthFilename = getenv(XENVAUTHFILE))) {
  132. +         if(NULL == (pchUsersHome = getenv("HOME"))) {
  133. +             pchUsersHome = gethomedir();
  134. +         }
  135. +         pchAuthFilename = (char *)xalloc(strlen(pchUsersHome) + 
  136. +                     sizeof(XENVAUTHFILE) + 1);
  137. +         strcpy(pchAuthFilename, pchUsersHome);
  138. +         strcat(pchAuthFilename, XENVAUTHFILE);
  139. +     } else {
  140. +         iFlaglocal++;
  141. +     }
  142. +     if(-1 != access(pchAuthFilename, R_OK)) {
  143. +         if((FILE *) NULL == (pFauthfile = fopen(pchAuthFilename,"r"))) {
  144. +             return 0;
  145. +         }
  146. +         if(!fstat(fileno(pFauthfile), &StatBuf)) {
  147. +             if(((StatBuf.st_mode & S_IFMT) == S_IFLNK) || 
  148. +                     StatBuf.st_mode != 
  149. +                     (StatBuf.st_mode & OTHERANDGROUP)) {
  150. +                 fprintf(stderr,"XAuth: XAUTH file (%s) is publicly readable or is a symbolic link - authorizations turned off\n",pchAuthFilename);
  151. +                 (void) fclose(pFauthfile);
  152. +                 return 0;
  153. +             }
  154. +         } else {
  155. +             (void) fclose(pFauthfile);
  156. +             return 0;
  157. +         }
  158. +         if(NULL == fgets(sbBuffer, MAXPASSWORDLEN, pFauthfile)) {
  159. +             return 0;
  160. +         }
  161. +         (void) fclose(pFauthfile);
  162. +         *ppchAuthString = (char *) xalloc(strlen(sbBuffer) + 1);
  163. +         strcpy(*ppchAuthString, sbBuffer);
  164. +         return 1;
  165. +     }
  166. +     if(iFlaglocal) {
  167. +         fprintf(stderr,"XAuth: XAUTH file (%s) is not readable or does not exist!\n");
  168. +     }    
  169. +     return 0;
  170. + }
  171. + #include <pwd.h>
  172. + static char    *
  173. + gethomedir()
  174. + {
  175. +     struct passwd    *pwsLocal;
  176. +     pwsLocal = getpwuid(getuid());
  177. +     return pwsLocal->pw_dir;
  178. + }
  179. + #endif /* PUCC */
  180. *** /tmp/,RCSt1024491    Tue May  2 21:49:16 1989
  181. --- ./lib/X/Imakefile    Sun Apr  9 09:57:42 1989
  182. ***************
  183. *** 20,25 ****
  184. --- 20,26 ----
  185.       XAllCells.o \
  186.       XAllPlanes.o \
  187.       XAllowEv.o \
  188. +     XAuthorize.o \
  189.       XAutoRep.o \
  190.       XBackgnd.o \
  191.       XBdrWidth.o \
  192. SHAR_EOF
  193. cat << \SHAR_EOF > README
  194.  
  195. This is a simple addition to the X server and library to allow
  196. user level authentication.   The hooks were already there, I just
  197. added some pretty simplistic code - this all depends on the
  198. unix file system for security.  
  199.  
  200. You need to add a "-DPUCC" to your imake config files.  The
  201. XAuthorize.c file goes into ./lib/X, and there is a patch file
  202. rooted at $TOP.  
  203.  
  204. When the consortium comes out with its version of finer-than-host
  205. authentication - you can just undef PUCC from the imake files, and
  206. you are done.
  207.  
  208. ------
  209. Here is how it works:
  210.  
  211. checks either the file $HOME/.xauth or the filename contained in the
  212. $XAUTH enviorment variable.  If this file does not have its other and
  213. group modes set to 0 - the file is ignored and the user warned.
  214.  
  215. The server reads in the first line of this file and keeps it as a passwd.
  216.  
  217. Each client reads in the first line of this file and sends it in the 
  218. connecction request packet.  If it matches the servers version, the connection
  219. is ok'ed (as long as the other requirments like xhost stuff are meet)
  220.  
  221. The user needs to create a .xauth file (~/.xauth actually) and put a 
  222. password or some phrase in it via his favorite editor.  It can be up
  223. to 99 characters or so.  chmod it to something like 600 or 400.  then
  224. rdist it to all the hosts that he will run x applications on.  All done!
  225.  
  226. He can then run xhost + allowing all hosts to talk to him since we are running
  227. a user based password thingie.
  228.  
  229. If you make any improvments or fixes, send them to me please!
  230.  
  231. Mike Rowan
  232. mtr@mentor.cc.purdue.edu
  233. SHAR_EOF
  234. cat << \SHAR_EOF > XAuthorize.c
  235. #ifdef PUCC
  236.  
  237. #include <stdio.h>
  238. #include <X11/Xos.h>
  239. #include "Xlibint.h"
  240. #include <sys/stat.h>
  241.  
  242. #define XENVAUTHFILE    "XAUTH"
  243. #define XAUTHFILE    "/.xauth"
  244. #define OTHERANDGROUP    07777700
  245. #define    MAXPASSWORDLEN    99
  246.  
  247. int 
  248. _XAuthorizeClient (ppchAuthProto, ppchAuthString)
  249.     char     **ppchAuthProto;
  250.     char     **ppchAuthString;
  251. {
  252.     char    *pchAuthFilename = NULL,
  253.         *pchUsersHome = NULL,
  254.         sbBuffer[MAXPASSWORDLEN + 1];
  255.     extern  char     *getenv();
  256.     static  char    *gethomedir();
  257.     FILE    *pFauthfile;
  258.     struct stat    StatBuf;
  259.     int    iFlaglocal = 0;
  260.  
  261.     if(NULL == (pchAuthFilename = getenv(XENVAUTHFILE))) {
  262.         iFlaglocal++;
  263. #ifndef SYSV
  264.         if(NULL == (pchUsersHome = getenv("HOME"))) {
  265. #else /* SYSV */
  266.         if(NULL == (pchUsersHome = getenv("HOME"))) {
  267. #endif /* SYSV */
  268.             pchUsersHome = gethomedir();
  269.         }
  270.         pchAuthFilename = (char *)Xmalloc(strlen(pchUsersHome) + 
  271.                     sizeof(XAUTHFILE) + 1);
  272.         strcpy(pchAuthFilename, pchUsersHome);
  273.         strcat(pchAuthFilename, XAUTHFILE);
  274.     }
  275.     if(-1 != access(pchAuthFilename, R_OK)) {
  276.         if((FILE *) NULL == (pFauthfile = fopen(pchAuthFilename,"r"))) {
  277.             perror("fopen");
  278.             return 0;
  279.         }
  280.         if(!fstat(fileno(pFauthfile), &StatBuf)) {
  281.             if(((StatBuf.st_mode & S_IFMT) == S_IFLNK) || 
  282.                     StatBuf.st_mode != 
  283.                     (StatBuf.st_mode & OTHERANDGROUP)) {
  284.                 fprintf(stderr,"XAuth: XAUTH file (%s) is publicly readable or is a symbolic link - passwd ignored\n",pchAuthFilename);
  285.                 (void) fclose(pFauthfile);
  286.                 return 0;
  287.             }
  288.         } else {
  289.             perror("fstat:");
  290.             (void) fclose(pFauthfile);
  291.             return 0;
  292.         }
  293.         if(NULL == fgets(sbBuffer, MAXPASSWORDLEN, pFauthfile)) {
  294.             return 0;
  295.         }
  296.         (void) fclose(pFauthfile);
  297.         *ppchAuthString = (char *) Xmalloc(strlen(sbBuffer) + 1);
  298.         strcpy(*ppchAuthString, sbBuffer);
  299.         return 1;
  300.     }
  301.     /* now only bitch if he set his XAUTH enviroment var */
  302.     if(!iFlaglocal) {
  303.         fprintf(stderr,"XAuth: XAUTH file (%s) is not readable or does not exist!\n",pchAuthFilename);
  304.     }
  305.     return 0;
  306. }
  307.  
  308. #include <pwd.h> 
  309.  
  310. static char    *
  311. gethomedir()
  312. {
  313.     struct passwd    *pwsLocal;
  314.  
  315.     pwsLocal = getpwuid(getuid());
  316.     return pwsLocal->pw_dir;
  317. }
  318.  
  319. #endif PUCC
  320. SHAR_EOF
  321. #    End of shell archive
  322. exit 0
  323.