00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 #include "lcas_config.h"
00082 #include <stdio.h>
00083 #include <stdlib.h>
00084 #include <string.h>
00085 
00086 #if HAVE_MALLOC_H
00087 #include <malloc.h>
00088 #endif
00089 
00090 #include "lcas_modules.h"
00091 #include "lcas_gridlist.h"
00092 
00093 
00094 
00095 
00096 
00097 #define USE_GRIDMAP 1
00098 
00099 
00100 
00101 
00102 static char *                 modname="lcas_userallow.mod";
00103 static char *                 userallow_db = NULL;
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 #if 0
00118 int plugin_initialize(char * plugin_db)
00119 #endif
00120 int plugin_initialize(int argc, char ** argv)
00121 {
00122     int                           rc;
00123     char *                        dummy = NULL;
00124 
00125 #if USE_GRIDMAP
00126     
00127     rc = lcas_gridlist("\0", &dummy, NULL, MATCH_ONLY_DN, NULL, NULL);
00128     if ( rc == LCAS_MOD_NOFILE )
00129     {
00130         lcas_log(LOG_NOTICE,"\t%s-plugin_initialize() error: cannot find gridmap file\n",
00131                  modname);
00132         if (dummy != NULL) free(dummy);
00133         return LCAS_MOD_NOFILE;
00134     }
00135 #else
00136     int                           i;
00137 
00138     lcas_log_debug(1,"%s-plugin_initialize(): passed arguments:\n", modname);
00139     for (i=0; i < argc; i++)
00140     {
00141         lcas_log_debug(1,"%s-plugin_initialize(): arg %d is %s\n",
00142              modname,i,argv[i]);
00143     }
00144 
00145     
00146     if (argc > 1)
00147         userallow_db = lcas_findfile(argv[1]);
00148 
00149     
00150     if (userallow_db == NULL)
00151     {
00152         lcas_log(0,"\t%s-plugin_initialize() error: allowed user file required !\n",
00153                    modname);
00154         return LCAS_MOD_NOFILE;
00155     }
00156     if (lcas_getfexist(1,userallow_db) == NULL)
00157     {
00158         lcas_log(0,
00159                  "\t%s-plugin_initialize() error: Cannot find allowed user file: %s\n",
00160                  modname,userallow_db
00161         );
00162         return LCAS_MOD_NOFILE;
00163     }
00164 #endif
00165     if (dummy != NULL) free(dummy);
00166     return LCAS_MOD_SUCCESS;
00167 }
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 int
00185 plugin_confirm_authorization(lcas_request_t request, lcas_cred_id_t lcas_cred)
00186 {
00187     int                           rc;
00188     char *                        dummy = NULL;
00189     char *                        user_dn = NULL;
00190 
00191     
00192 
00193 
00194     if ( (user_dn = lcas_get_dn(lcas_cred)) == NULL)
00195     {
00196         lcas_log(0, "lcas.mod-lcas_get_fabric_authorization() error: user DN empty\n");
00197         goto lcas_userallow_noauth;
00198     }
00199 
00200     
00201 #if USE_GRIDMAP
00202     lcas_log_debug(0,
00203     "\t%s-plugin_confirm_authorization(): checking allowed users in gridmapfile\n",
00204              modname);
00205     lcas_log_debug(0,
00206     "\t%s-plugin_confirm_authorization(): checking user %s\n",modname,user_dn);
00207 
00208     rc = lcas_gridlist(user_dn, &dummy, NULL, MATCH_ONLY_DN, NULL, NULL);
00209     lcas_log_debug(1,"got rc = %d from lcas_gridlist()\n",rc);
00210 #else
00211     lcas_log_debug(0,
00212     "\t%s-plugin_confirm_authorization(): checking allowed users in %s\n",
00213              modname,userallow_db);
00214 
00215     rc = lcas_gridlist(user_dn, &dummy, userallow_db, MATCH_ONLY_DN, NULL, NULL);
00216     lcas_log_debug(1,"got rc = %d from lcas_gridlist()\n",rc);
00217 #endif
00218     if ( rc == LCAS_MOD_NOENTRY )
00219     {
00220         
00221         lcas_log(0,"\t%s-plugin_confirm_authorization(): no entry found for %s\n",
00222                  modname,user_dn);
00223         goto lcas_userallow_noauth;
00224     }
00225     else if ( rc == LCAS_MOD_NOFILE )
00226     {
00227         
00228         lcas_log(0,
00229 #if USE_GRIDMAP
00230             "\t%s-plugin_confirm_authorization() error: Cannot find gridmapfile\n",
00231             modname);
00232 #else
00233             "\t%s-plugin_confirm_authorization() error: Cannot find allowed user file: %s\n",
00234             modname,userallow_db);
00235 #endif
00236         goto lcas_userallow_nofile;
00237     }
00238 
00239  lcas_userallow_auth:
00240     
00241     if (dummy != NULL) free(dummy);
00242     return LCAS_MOD_SUCCESS;
00243 
00244  lcas_userallow_noauth:
00245     
00246     if (dummy != NULL) free(dummy);
00247     return LCAS_MOD_FAIL;
00248 
00249  lcas_userallow_nofile:
00250     
00251     if (dummy != NULL) free(dummy);
00252     return LCAS_MOD_NOFILE;
00253 }
00254 
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 
00264 
00265 int plugin_terminate()
00266 {
00267     lcas_log_debug(1,"%s-plugin_terminate(): terminating\n",modname);
00268     if (userallow_db) { free(userallow_db); userallow_db=NULL; }
00269 
00270     return LCAS_MOD_SUCCESS;
00271 }