Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

lcmaps_information.c

00001 /*
00002  * Copyright (c) 2001 EU DataGrid.
00003  * For license conditions see http://www.eu-datagrid.org/license.html
00004  *
00005  * Copyright (c) 2001, 2002 by
00006  *     Oscar Koeroo <okoeroo@nikhef.nl>,
00007  *     NIKHEF Amsterdam, the Netherlands
00008  */
00009 
00010 /*****************************************************************************
00011                             Include header files
00012 ******************************************************************************/
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 #include <string.h>
00016 #include <pwd.h>
00017  
00018 #include "lcmaps_config.h"
00019 #include "lcmaps_modules.h"
00020 #include "lcmaps_arguments.h"
00021 #include "lcmaps_cred_data.h"
00022 
00023 #include "lcmaps_vo_data.h"
00024 
00025 #include "lcmaps_information.h" 
00026 /******************************************************************************
00027                                 Definitions
00028 ******************************************************************************/
00029  
00030 /******************************************************************************
00031                           Module specific prototypes
00032 ******************************************************************************/
00033  
00034 /******************************************************************************
00035                        Define module specific variables
00036 ******************************************************************************/
00037  
00038 /******************************************************************************
00039 Function:   strgetinfo
00040 Description:
00041     Will return a char * with al the credentials available in cred_data
00042 Parameters:
00043     argc, argv
00044     argv[0]: the name of the plugin
00045 Returns:
00046     LCMAPS_MOD_SUCCESS : succes
00047     LCMAPS_MOD_FAIL    : failure
00048     LCMAPS_MOD_NOFILE  : db file not found (will halt LCMAPS initialization)
00049 ******************************************************************************/    
00050 
00051 int strgetinfo(char ** info)
00052 {
00053     char *tmp_info = NULL;
00054 
00055     // Credentials      
00056     int              i              = 0;
00057     int              count          = 0;
00058     char            *dn             = NULL;
00059     char           **VoCredString   = NULL;
00060     uid_t           *uid            = NULL;
00061     gid_t           *priGid         = NULL;
00062     gid_t           *secGid         = NULL;
00063     struct passwd   *user_info      = NULL;   
00064     struct group    *grp_info       = NULL;
00065 
00066     // Time
00067     char       *datetime;
00068     int         res;
00069     time_t      clock;
00070     struct tm  *tmp;
00071  
00072 
00073     time(&clock);
00074     tmp = localtime(&clock);
00075  
00076     datetime = malloc(sizeof(char) * 20);
00077  
00078     res=snprintf(datetime, 20, "%04d-%02d-%02d.%02d:%02d:%02d",
00079            tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
00080            tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
00081 
00082     
00083     // Tmp sollution
00084     tmp_info = malloc(sizeof(char) * 10000);
00085 
00086     // Set time
00087     sprintf(tmp_info, "%s:", datetime);
00088 
00089 
00090     // Get DN
00091     dn = *((char **)getCredentialData(DN, &count));
00092     sprintf(tmp_info, "dn=%s", dn);
00093 
00094     // Get VoCredStrings
00095     VoCredString = getCredentialData(LCMAPS_VO_CRED_STRING, &count);
00096     for (i = 0 ; i < count; i++)
00097     {
00098        sprintf(tmp_info, "%s:%s", tmp_info, VoCredString[i]);
00099     }
00100 
00101 
00102     // Get POSIX UID credentials
00103     uid = getCredentialData(UID, &count);
00104     for (i = 0 ; i < count; i++)
00105     {
00106        user_info = getpwuid(uid[i]);
00107        if (user_info != NULL)
00108        {
00109            sprintf(tmp_info, "%s:uid=%d(%s)", tmp_info, uid[i], user_info->pw_name);
00110        }
00111        else
00112        {
00113            sprintf(tmp_info, "%s:uid=%d",     tmp_info, uid[i]);
00114        }
00115     }
00116 
00117 
00118     // Get POSIX GID credentials
00119     priGid = getCredentialData(PRI_GID, &count);
00120     for (i = 0 ; i < count; i++)
00121     {
00122        grp_info = getgrgid(priGid[i]);
00123        if (grp_info != NULL)
00124        {
00125            sprintf(tmp_info, "%s:gid=%d(%s)", tmp_info, priGid[i], grp_info->gr_name);
00126        }
00127        else
00128        {
00129            sprintf(tmp_info, "%s:gid=%d",     tmp_info, priGid[i]);
00130        }
00131     }
00132 
00133 
00134     // Get POSIX GROUPS credentials
00135     secGid = getCredentialData(SEC_GID, &count);
00136     for (i = 0 ; i < count; i++)
00137     {
00138        grp_info = getgrgid(secGid[i]);
00139        if (grp_info != NULL)
00140        {
00141            sprintf(tmp_info, "%s:groups=%d(%s)", tmp_info, secGid[i], grp_info->gr_name);
00142        }
00143        else
00144        {
00145            sprintf(tmp_info, "%s:groups=%d",     tmp_info, secGid[i]);
00146        }
00147     }
00148 
00149     *info = strdup(tmp_info);
00150 
00151     return LCMAPS_MOD_SUCCESS;
00152 }
00153 
00154 
00155 
00156 /*
00157     char *      datetime;
00158     int         res;
00159     time_t      clock;
00160     struct tm * tmp;
00161  
00162     time(&clock);
00163     tmp = localtime(&clock);
00164  
00165     datetime = malloc(sizeof(char) * 20);
00166  
00167     res=snprintf(datetime, 20, "%04d-%02d-%02d.%02d:%02d:%02d",
00168            tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
00169            tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
00170 
00171 */

Generated at Thu Mar 4 17:39:03 2004 for edg-lcmaps by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001