Enlightenment CVS committal

Author  : xcomputerman
Project : e17
Module  : apps/entrance

Dir     : e17/apps/entrance/src/daemon


Modified Files:
        auth.c 


Log Message:
- Add function to remove user cookies
- Enhance randomness of cookie generation a bit

===================================================================
RCS file: /cvsroot/enlightenment/e17/apps/entrance/src/daemon/auth.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- auth.c      22 Mar 2004 06:51:39 -0000      1.3
+++ auth.c      22 Mar 2004 22:38:21 -0000      1.4
@@ -22,16 +22,26 @@
 
 char * entranced_cookie_new (void) 
 {
-   int fd;
-   int r, i;
-   unsigned char buf[BUFSIZE];
-   unsigned char digest[MD5_HASHBYTES];
-   char *cookie;
-   Entranced_MD5_Context *ctx = NULL;
+   int                     fd;
+   int                     r, i;
+   unsigned char           buf[BUFSIZE];
+   unsigned char           digest[MD5_HASHBYTES];
+   double                  ctime;
+   pid_t                   pid;
+   char                    *cookie;
+   Entranced_MD5_Context   *ctx = NULL;
 
    entranced_md5_init(ctx);
 
-   if ((fd = open("/dev/urandom", O_RDONLY|O_NONBLOCK)) < 0) {
+   ctime = ecore_time_get();
+   entranced_md5_update(ctx, (unsigned char *) &ctime, sizeof(ctime));
+   pid = getpid();
+   entranced_md5_update(ctx, (unsigned char *) &pid, sizeof(pid));
+   pid = getppid();
+   entranced_md5_update(ctx, (unsigned char *) &pid, sizeof(pid));
+   
+
+   if ((fd = open("/dev/random", O_RDONLY|O_NONBLOCK)) < 0) {
       entranced_debug("Cookie generation failed: could not open /dev/urandom\n");
       return NULL;
    }
@@ -285,7 +295,7 @@
 }
 
 int
-entranced_auth_user_add(Entranced_Display *d, uid_t user, const char *homedir)
+entranced_auth_user_add(Entranced_Display *d, const char *homedir)
 {
    FILE              *auth_file;
    int               ret = TRUE;
@@ -295,7 +305,7 @@
    if (!d || !homedir)
       return FALSE;
 
-   entranced_debug("entranced_auth_user_add: Adding auth cookie for UID %d\n", user);
+   entranced_debug("entranced_auth_user_add: Adding auth cookie\n");
 
    while(1)
    {
@@ -367,10 +377,49 @@
 
    fclose(auth_file);
    XauUnlockAuth(d->user_authfile);
-   entranced_debug("entranced_auth_user_add: Finished writing auth entries for uid 
%s", user);
+   entranced_debug("entranced_auth_user_add: Finished writing auth entries to %s", 
d->user_authfile);
 
    return ret;
       
 }
 
+void
+entranced_auth_user_remove (Entranced_Display *d)
+{
+   FILE     *auth_file;
+
+   if (!d || !d->user_authfile)
+      return;
+
+   entranced_debug("entranced_auth_user_remove: Removing cookie from %s\n", 
d->user_authfile);
+
+   /* TODO: Permissions check on auth file */
+   /* Get a lock */
+   if (XauLockAuth(d->user_authfile, 3, 3, 0) != LOCK_SUCCESS)
+   {
+      free(d->user_authfile);
+      d->user_authfile = NULL;
+      return;
+   }
+
+   /* Open the file */
+   if (!(auth_file = fopen(d->user_authfile, "a+")))
+   {
+      XauUnlockAuth(d->user_authfile);
+      free(d->user_authfile);
+      d->user_authfile = NULL;
+      return;
+   }
+
+   /* Remove cookies for this display */
+   _entranced_auth_purge(d, auth_file);
+   
+   /* Close and unlock */
+   fclose(auth_file);
+   XauUnlockAuth(d->user_authfile);
+
+   free(d->user_authfile);
+   d->user_authfile = NULL;
+}
+
 




-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to