open-src/app/xscreensaver/sun-src/driver/trusted-utils.c
changeset 17 151bef9509d4
child 487 6593510eb561
equal deleted inserted replaced
16:e0642423918d 17:151bef9509d4
       
     1 /*
       
     2  * Trusted xscreensaver
       
     3  *
       
     4  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
       
     5  *
       
     6  * Permission is hereby granted, free of charge, to any person obtaining a
       
     7  * copy of this software and associated documentation files (the
       
     8  * "Software"), to deal in the Software without restriction, including
       
     9  * without limitation the rights to use, copy, modify, merge, publish,
       
    10  * distribute, and/or sell copies of the Software, and to permit persons
       
    11  * to whom the Software is furnished to do so, provided that the above
       
    12  * copyright notice(s) and this permission notice appear in all copies of
       
    13  * the Software and that both the above copyright notice(s) and this
       
    14  * permission notice appear in supporting documentation.
       
    15  *
       
    16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
       
    17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
    18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
       
    19  * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
       
    20  * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
       
    21  * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
       
    22  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
       
    23  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
       
    24  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
       
    25  *
       
    26  * Except as contained in this notice, the name of a copyright holder
       
    27  * shall not be used in advertising or otherwise to promote the sale, use
       
    28  * or other dealings in this Software without prior written authorization
       
    29  * of the copyright holder.
       
    30  *
       
    31  *
       
    32  *
       
    33  * Based on work by Erwann Chenede, Ghee Teo
       
    34  *
       
    35  * Used to check if we are in a multilabel session and to load
       
    36  * additional functionality within the multilabel session.
       
    37  */
       
    38 
       
    39 #include <dlfcn.h>
       
    40 #include <link.h>
       
    41 #include <stdlib.h>
       
    42 #include <user_attr.h>
       
    43 #include <sys/types.h>
       
    44 #include <unistd.h>
       
    45 #include <strings.h>
       
    46 
       
    47 #include "trusted-utils.h"
       
    48 
       
    49 /* 
       
    50  * Checks for Multi label session 
       
    51  */
       
    52 gboolean
       
    53 tsol_is_multi_label_session (void)
       
    54 {
       
    55        static char *session = NULL;
       
    56 
       
    57        if (!session)
       
    58                session = (char *)getenv("TRUSTED_SESSION");
       
    59 
       
    60        if (!session)
       
    61                return FALSE;
       
    62 
       
    63        return TRUE;
       
    64 }
       
    65 
       
    66 /*
       
    67  * dynamicly load the libxtsol library
       
    68  */
       
    69 static
       
    70 void * dlopen_xtsol (void)
       
    71 {
       
    72    void  *handle = NULL;
       
    73 
       
    74    if ((handle = dlopen ("/usr/lib/libXtsol.so.1", RTLD_LAZY)) != NULL)
       
    75        return handle;
       
    76    if ((handle = dlopen ("/usr/openwin/lib/libXtsol.so.1", RTLD_LAZY)) != NULL)
       
    77        return handle;
       
    78 
       
    79    return handle;
       
    80 }
       
    81 
       
    82 /*
       
    83  * dynamicly load the libDtTsol library
       
    84  */
       
    85 static
       
    86 void * dlopen_gnometsol (void)
       
    87 {
       
    88    void  *handle = NULL;
       
    89 
       
    90    if ((handle = dlopen ("/usr/lib/libgnometsol.so.1", RTLD_LAZY)) != NULL)
       
    91        return handle;
       
    92 
       
    93    return handle;
       
    94 }
       
    95 
       
    96 xtsol_XTSOLgetWorkstationOwner      libxtsol_XTSOLgetWorkstationOwner = NULL;
       
    97 
       
    98 void
       
    99 XTSOLgetWorkstationOwner(Display *dpy, uid_t *WorkstationOwner)
       
   100 {
       
   101   static gpointer xtsol_handle = NULL;
       
   102   static gboolean _xtsol_initialized = FALSE;
       
   103 
       
   104   if ( ! _xtsol_initialized ) {
       
   105     _xtsol_initialized = TRUE;
       
   106     xtsol_handle = dlopen_xtsol ();
       
   107     if (xtsol_handle != NULL)
       
   108       libxtsol_XTSOLgetWorkstationOwner = (xtsol_XTSOLgetWorkstationOwner) dlsym(xtsol_handle,
       
   109 					     "XTSOLgetWorkstationOwner");
       
   110   }
       
   111 
       
   112   if (libxtsol_XTSOLgetWorkstationOwner == NULL) {
       
   113     *WorkstationOwner = getuid();
       
   114   } else
       
   115     libxtsol_XTSOLgetWorkstationOwner(dpy, WorkstationOwner);
       
   116 }
       
   117 
       
   118 gnome_tsol_get_usrattr_val		libgnome_tsol_get_usrattr_val = NULL;
       
   119 
       
   120 /*
       
   121  * Returns a value from uattr for the given key.
       
   122  * If there is no value in user_attr, then it returns the
       
   123  * system wide default from policy.conf or labelencodings
       
   124  * as appropriate.
       
   125  */
       
   126 char *
       
   127 getusrattrval(userattr_t *uattr, char *keywd)
       
   128 {
       
   129   static gpointer gnometsol_handle = NULL;
       
   130   static gboolean _gnometsol_initialized = FALSE;
       
   131   char *value;
       
   132 
       
   133   if ( ! _gnometsol_initialized ) {
       
   134     _gnometsol_initialized = TRUE;
       
   135     gnometsol_handle = dlopen_gnometsol ();
       
   136     if (gnometsol_handle != NULL)
       
   137       libgnome_tsol_get_usrattr_val = (gnome_tsol_get_usrattr_val) dlsym(gnometsol_handle,
       
   138 					     "gnome_tsol_get_usrattr_val");
       
   139   }
       
   140 
       
   141   if (libgnome_tsol_get_usrattr_val == NULL) {
       
   142     if (strcmp(keywd, USERATTR_IDLETIME_KW) == 0)
       
   143       value = strdup("15");
       
   144     else if (strcmp(keywd, USERATTR_IDLECMD_KW) == 0)
       
   145       value = strdup(USERATTR_IDLECMD_LOCK_KW);
       
   146   } else
       
   147     value = libgnome_tsol_get_usrattr_val(uattr, keywd);
       
   148   
       
   149   return ( value );
       
   150 }