nfs-ganesha 1.4

fsal_init.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  */
00004 
00014 #ifdef HAVE_CONFIG_H
00015 #include "config.h"
00016 #endif
00017 
00018 #include "fsal.h"
00019 #include "fsal_internal.h"
00020 #include "fsal_common.h"
00021 #include "HPSSclapiExt/hpssclapiext.h"
00022 
00023 #if HPSS_MAJOR_VERSION >= 6
00024 #include <hpss_Getenv.h>
00025 
00026 static hpss_authn_mech_t FSAL_auth_mech;
00027 
00028 #endif
00029 
00030 static char FSAL_PrincipalName[HPSS_MAX_PRINCIPAL_NAME];
00031 static char FSAL_KeytabPath[HPSS_MAX_PATH_NAME];
00032 
00034 static int HPSSFSAL_SecInit(hpssfs_specific_initinfo_t * hpss_init_info)
00035 {
00036 
00037   int rc;
00038 
00039 #if HPSS_MAJOR_VERSION == 5
00040 
00042   rc = hpss_SetLoginContext(FSAL_PrincipalName, FSAL_KeytabPath);
00043 
00044   LogDebug(COMPONENT_FSAL, "FSAL SEC INIT: DCE principal is set to '%s'",
00045                     FSAL_PrincipalName);
00046   LogDebug(COMPONENT_FSAL, "FSAL SEC INIT: Keytab is set to '%s'",
00047                     FSAL_KeytabPath);
00048 
00049 #elif HPSS_MAJOR_VERSION >= 6
00050   hpss_rpc_auth_type_t auth_type;
00051 
00052   rc = hpss_GetAuthType(FSAL_auth_mech, &auth_type);
00053   if(rc != 0)
00054     return rc;
00055 
00056   if(auth_type != hpss_rpc_auth_type_keytab && auth_type != hpss_rpc_auth_type_keyfile)
00057     {
00058       return ERR_FSAL_INVAL;
00059     }
00060 
00061   rc = hpss_SetLoginCred(FSAL_PrincipalName,
00062                          FSAL_auth_mech,
00063                          auth_type, hpss_rpc_cred_client, (void *)FSAL_KeytabPath);
00064 
00065   LogDebug(COMPONENT_FSAL, "FSAL SEC INIT: Auth Mech is set to '%s'",
00066                     hpss_AuthnMechTypeString(FSAL_auth_mech));
00067   LogDebug(COMPONENT_FSAL, "FSAL SEC INIT: Auth Type is set to '%s'",
00068                     hpss_AuthenticatorTypeString(auth_type));
00069   LogDebug(COMPONENT_FSAL, "FSAL SEC INIT: Principal is set to '%s'",
00070                     FSAL_PrincipalName);
00071   LogDebug(COMPONENT_FSAL, "FSAL SEC INIT: Keytab is set to '%s'",
00072                     FSAL_KeytabPath);
00073 
00074 #endif
00075 
00076   return rc;
00077 
00078 }
00079 
00080 /* Macros for analysing parameters. */
00081 #define SET_BITMAP_PARAM( api_cfg, p_init_info, _field )      \
00082     switch( (p_init_info)->behaviors._field ){                \
00083       case FSAL_INIT_FORCE_VALUE :                            \
00084         /* force the value in any case */                     \
00085         api_cfg._field = (p_init_info)->hpss_config._field;   \
00086         break;                                                \
00087       case FSAL_INIT_MAX_LIMIT :                              \
00088         /* remove the flags not specified by user (AND) */    \
00089         api_cfg._field &= (p_init_info)->hpss_config._field;  \
00090         break;                                                \
00091       case FSAL_INIT_MIN_LIMIT :                              \
00092         /* add the flags specified by user (OR) */            \
00093         api_cfg._field |= (p_init_info)->hpss_config._field;  \
00094         break;                                                \
00095     /* In the other cases, we keep the default value. */      \
00096     }                                                         \
00097 
00098 
00099 #define SET_INTEGER_PARAM( api_cfg, p_init_info, _field )         \
00100     switch( (p_init_info)->behaviors._field ){                    \
00101     case FSAL_INIT_FORCE_VALUE :                                  \
00102         /* force the value in any case */                         \
00103         api_cfg._field = (p_init_info)->hpss_config._field;       \
00104         break;                                                \
00105     case FSAL_INIT_MAX_LIMIT :                                    \
00106       /* check the higher limit */                                \
00107       if ( api_cfg._field > (p_init_info)->hpss_config._field )   \
00108         api_cfg._field = (p_init_info)->hpss_config._field ;      \
00109         break;                                                \
00110     case FSAL_INIT_MIN_LIMIT :                                    \
00111       /* check the lower limit */                                 \
00112       if ( api_cfg._field < (p_init_info)->hpss_config._field )   \
00113         api_cfg._field = (p_init_info)->hpss_config._field ;      \
00114         break;                                                \
00115     /* In the other cases, we keep the default value. */          \
00116     }                                                             \
00117 
00118 
00119 #define SET_STRING_PARAM( api_cfg, p_init_info, _field )          \
00120     switch( (p_init_info)->behaviors._field ){                    \
00121     case FSAL_INIT_FORCE_VALUE :                                  \
00122       /* force the value in any case */                           \
00123       strcpy(api_cfg._field,(p_init_info)->hpss_config._field);   \
00124       break;                                                \
00125     /* In the other cases, we keep the default value. */          \
00126     }                                                             \
00127 
00128 
00129 static int HPSSFSAL_Init_internal(hpssfs_specific_initinfo_t * hpss_init_info)
00130 {
00131 
00132   int rc = 0;
00133   api_config_t hpss_config;
00134 
00135   if(!hpss_init_info)
00136     return ERR_FSAL_FAULT;
00137 
00138   /* First, get current values for config. */
00139 
00140   if(rc = hpss_GetConfiguration(&hpss_config))
00141     return rc;
00142 
00143 #if HPSS_MAJOR_VERSION == 5
00144 
00145   /* Then analyze user's init info. */
00146 
00147   SET_STRING_PARAM(hpss_config, hpss_init_info, PrincipalName)
00148       SET_STRING_PARAM(hpss_config, hpss_init_info, KeytabPath)
00149       /* retrieve authentication values. */
00150       strcpy(FSAL_PrincipalName, hpss_config.PrincipalName);
00151   strcpy(FSAL_KeytabPath, hpss_config.KeytabPath);
00152 
00153 #elif HPSS_MAJOR_VERSION >= 6
00154 
00155 #define API_DEBUG_ERROR    (1)
00156 #define API_DEBUG_REQUEST  (2)
00157 #define API_DEBUG_TRACE    (4)
00158 
00159   hpss_config.Flags |= API_USE_CONFIG;
00160 
00161   /* retrieve authentication mechanism */
00162 
00163   if(hpss_init_info->behaviors.AuthnMech == FSAL_INIT_FORCE_VALUE)
00164     {
00165       FSAL_auth_mech = hpss_init_info->hpss_config.AuthnMech;
00166       hpss_config.AuthnMech = hpss_init_info->hpss_config.AuthnMech;
00167     }
00168   else
00169     {
00170       FSAL_auth_mech = hpss_config.AuthnMech;
00171     }
00172 
00173   if(hpss_init_info->behaviors.NumRetries == FSAL_INIT_FORCE_VALUE)
00174     hpss_config.NumRetries = hpss_init_info->hpss_config.NumRetries;
00175 
00176   if(hpss_init_info->behaviors.BusyRetries == FSAL_INIT_FORCE_VALUE)
00177     hpss_config.BusyRetries = hpss_init_info->hpss_config.BusyRetries;
00178 
00179   if(hpss_init_info->behaviors.BusyDelay == FSAL_INIT_FORCE_VALUE)
00180     hpss_config.BusyDelay = hpss_init_info->hpss_config.BusyDelay;
00181 
00182   if(hpss_init_info->behaviors.BusyRetries == FSAL_INIT_FORCE_VALUE)
00183     hpss_config.BusyRetries = hpss_init_info->hpss_config.BusyRetries;
00184 
00185   if(hpss_init_info->behaviors.MaxConnections == FSAL_INIT_FORCE_VALUE)
00186     hpss_config.MaxConnections = hpss_init_info->hpss_config.MaxConnections;
00187 
00188   if(hpss_init_info->behaviors.Principal == FSAL_INIT_FORCE_VALUE)
00189     strcpy(FSAL_PrincipalName, hpss_init_info->Principal);
00190 
00191   if(hpss_init_info->behaviors.KeytabPath == FSAL_INIT_FORCE_VALUE)
00192     strcpy(FSAL_KeytabPath, hpss_init_info->KeytabPath);
00193 
00194   if(hpss_init_info->behaviors.DebugPath == FSAL_INIT_FORCE_VALUE)
00195     {
00196       strcpy(hpss_config.DebugPath, hpss_init_info->hpss_config.DebugPath);
00197       hpss_config.DebugValue |= API_DEBUG_ERROR | API_DEBUG_REQUEST | API_DEBUG_TRACE;
00198       hpss_config.Flags |= API_ENABLE_LOGGING;
00199     }
00200 
00201   /* Display Clapi configuration */
00202 
00203   LogDebug(COMPONENT_FSAL, "HPSS Client API configuration:");
00204   LogDebug(COMPONENT_FSAL, "  Flags: %08X", hpss_config.Flags);
00205   LogDebug(COMPONENT_FSAL, "  TransferType: %d", hpss_config.TransferType);
00206   LogDebug(COMPONENT_FSAL, "  NumRetries: %d", hpss_config.NumRetries);
00207   LogDebug(COMPONENT_FSAL, "  BusyDelay: %d", hpss_config.BusyDelay);
00208   LogDebug(COMPONENT_FSAL, "  BusyRetries: %d", hpss_config.BusyRetries);
00209   LogDebug(COMPONENT_FSAL, "  TotalDelay: %d", hpss_config.TotalDelay);
00210   LogDebug(COMPONENT_FSAL, "  LimitedRetries: %d",
00211                     hpss_config.LimitedRetries);
00212   LogDebug(COMPONENT_FSAL, "  MaxConnections: %d",
00213                     hpss_config.MaxConnections);
00214   LogDebug(COMPONENT_FSAL, "  ReuseDataConnections: %d",
00215                     hpss_config.ReuseDataConnections);
00216   LogDebug(COMPONENT_FSAL, "  UsePortRange: %d", hpss_config.UsePortRange);
00217   LogDebug(COMPONENT_FSAL, "  RetryStageInp: %d",
00218                     hpss_config.RetryStageInp);
00219   LogDebug(COMPONENT_FSAL, "  DebugValue: %#X", hpss_config.DebugValue);
00220   LogDebug(COMPONENT_FSAL, "  DebugPath: %s", hpss_config.DebugPath);
00221 
00222 #endif
00223 
00224   strcpy(hpss_config.DescName, "hpss.ganesha.nfsd");
00225 
00226   /* set the final configuration */
00227   rc = hpss_SetConfiguration(&hpss_config);
00228 
00229   return rc;
00230 
00231 }
00232 
00254 fsal_status_t HPSSFSAL_Init(fsal_parameter_t * init_info        /* IN */
00255     )
00256 {
00257 
00258   fsal_status_t status;
00259   hpss_fileattr_t rootattr;
00260   int rc;
00261 
00262   /* sanity check.  */
00263 
00264   if(!init_info)
00265     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_Init);
00266 
00267 #if HPSS_MAJOR_VERSION == 5
00268 
00269   if(init_info->fs_specific_info.behaviors.KeytabPath == FSAL_INIT_FS_DEFAULT)
00270     {
00271       /* issue a warning on stderr if no credential is specified */
00272       LogCrit(COMPONENT_FSAL,
00273           "FSAL INIT: *** WARNING: No keytab file specified for HPSS, default client keytab will be used...");
00274       LogCrit(COMPONENT_FSAL,
00275           "FSAL INIT: ***          Set %s::KeytabPath into config file to use another keytab",
00276            CONF_LABEL_FS_SPECIFIC);
00277     }
00278 
00279   if(init_info->fs_specific_info.behaviors.PrincipalName == FSAL_INIT_FS_DEFAULT)
00280     {
00281       /* issue a warning on stderr if no credential is specified */
00282       LogCrit(COMPONENT_FSAL,
00283           "FSAL INIT: *** WARNING: No principal name specified for HPSS, default will be used...");
00284       LogCrit(COMPONENT_FSAL,
00285           "FSAL INIT: ***          Set %s::PrincipalName into config file to use another principal",
00286            CONF_LABEL_FS_SPECIFIC);
00287     }
00288 #elif HPSS_MAJOR_VERSION >= 6
00289 
00290   if(init_info->fs_specific_info.behaviors.AuthnMech == FSAL_INIT_FS_DEFAULT)
00291     {
00292       /* issue a warning on stderr if no credential is specified */
00293       LogCrit(COMPONENT_FSAL,
00294           "FSAL INIT: *** WARNING: No authentication mechanism specified for HPSS, default authentication mechanism will be used...");
00295       LogCrit(COMPONENT_FSAL,
00296           "FSAL INIT: ***          Set %s::AuthMech into config file to use another Authentication Mechanism",
00297            CONF_LABEL_FS_SPECIFIC);
00298     }
00299 
00300   if(init_info->fs_specific_info.behaviors.KeytabPath == FSAL_INIT_FS_DEFAULT)
00301     {
00302       /* issue a warning on stderr if no credential is specified */
00303       LogCrit(COMPONENT_FSAL,
00304           "FSAL INIT: *** WARNING: No keytab file specified for HPSS, default client keytab will be used...");
00305       LogCrit(COMPONENT_FSAL,
00306           "FSAL INIT: ***          Set %s::KeytabPath into config file to use another keytab",
00307            CONF_LABEL_FS_SPECIFIC);
00308     }
00309 
00310   if(init_info->fs_specific_info.behaviors.Principal == FSAL_INIT_FS_DEFAULT)
00311     {
00312       /* issue a warning on stderr if no credential is specified */
00313       LogCrit(COMPONENT_FSAL,
00314           "FSAL INIT: *** WARNING: No principal name specified for HPSS, default principal name will be used...");
00315       LogCrit(COMPONENT_FSAL,
00316           "FSAL INIT: ***          Set %s::PrincipalName into config file to use another principal",
00317            CONF_LABEL_FS_SPECIFIC);
00318     }
00319 #endif
00320 
00321   /* proceeds FSAL internal initialization */
00322 
00323   status = fsal_internal_init_global(&(init_info->fsal_info),
00324                                      &(init_info->fs_common_info));
00325 
00326   if(FSAL_IS_ERROR(status))
00327     Return(status.major, status.minor, INDEX_FSAL_Init);
00328 
00329   /* configure HPSS cl api  
00330      (and retrieve current PrincipalName and KeytabName) */
00331 
00332   if(rc = HPSSFSAL_Init_internal(&init_info->fs_specific_info))
00333     Return(ERR_FSAL_BAD_INIT, -rc, INDEX_FSAL_Init);
00334 
00335   /* Init security context */
00336 
00337   if(rc = HPSSFSAL_SecInit(&init_info->fs_specific_info))
00338     Return(ERR_FSAL_SEC, -rc, INDEX_FSAL_Init);
00339 
00340   /* sets the credential renewal time */
00341 
00342   switch (init_info->fs_specific_info.behaviors.CredentialLifetime)
00343     {
00344     case FSAL_INIT_FORCE_VALUE:
00345       /* force the value in any case */
00346       fsal_internal_SetCredentialLifetime(init_info->fs_specific_info.CredentialLifetime);
00347       break;
00348       /* In the other cases, we keep the default value. */
00349     }
00350 
00351   /* sets behavior for inconsistent directory entries */
00352 
00353   switch (init_info->fs_specific_info.behaviors.ReturnInconsistentDirent)
00354     {
00355     case FSAL_INIT_FORCE_VALUE:
00356       /* force the value in any case */
00357       fsal_internal_SetReturnInconsistentDirent(init_info->fs_specific_info.
00358                                                 ReturnInconsistentDirent);
00359       break;
00360       /* In the other cases, we keep the default value. */
00361     }
00362 
00363   /* Everything went OK. */
00364 
00365   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_Init);
00366 
00367 }
00368 
00369 /* To be called before exiting */
00370 fsal_status_t HPSSFSAL_terminate()
00371 {
00372   ReturnCode(ERR_FSAL_NO_ERROR, 0);
00373 }