nfs-ganesha 1.4
|
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 <pwd.h> 00022 #include <errno.h> 00023 #include <stdlib.h> 00024 #include <string.h> 00025 00028 /* define your specific NFS export options here : */ 00029 enum 00030 { 00031 YOUR_OPTION_1 = 0, 00032 YOUR_OPTION_2 = 1, 00033 YOUR_OPTION_3 = 2, 00034 YOUR_OPTION_4 = 3, 00035 }; 00036 00037 const char *fs_specific_opts[] = { 00038 "option1", 00039 "option2", 00040 "option3", 00041 "option4", 00042 NULL 00043 }; 00044 00049 static int Getsubopt(char **optionp, const char *const *tokens, char **valuep) 00050 { 00051 char *endp, *vstart; 00052 int cnt; 00053 00054 if(**optionp == '\0') 00055 return -1; 00056 00057 /* Find end of next token. */ 00058 endp = strchr(*optionp, ','); 00059 if(endp == NULL) 00060 endp = strchr(*optionp, '\0'); 00061 00062 /* Find start of value. */ 00063 vstart = memchr(*optionp, '=', endp - *optionp); 00064 if(vstart == NULL) 00065 vstart = endp; 00066 00067 /* Try to match the characters between *OPTIONP and VSTART against 00068 one of the TOKENS. */ 00069 for(cnt = 0; tokens[cnt] != NULL; ++cnt) 00070 if(memcmp(*optionp, tokens[cnt], vstart - *optionp) == 0 00071 && tokens[cnt][vstart - *optionp] == '\0') 00072 { 00073 /* We found the current option in TOKENS. */ 00074 *valuep = vstart != endp ? vstart + 1 : NULL; 00075 00076 if(*endp != '\0') 00077 *endp++ = '\0'; 00078 *optionp = endp; 00079 00080 return cnt; 00081 } 00082 00083 /* The current suboption does not match any option. */ 00084 *valuep = *optionp; 00085 00086 if(*endp != '\0') 00087 *endp++ = '\0'; 00088 *optionp = endp; 00089 00090 return -1; 00091 } 00092 00105 fsal_status_t FSAL_BuildExportContext(fsal_export_context_t * p_export_context, /* OUT */ 00106 fsal_path_t * p_export_path, /* IN */ 00107 char *fs_specific_options /* IN */ 00108 ) 00109 { 00110 char subopts[256]; 00111 char *p_subop; 00112 char *value; 00113 00114 int rc; 00115 00116 /* sanity check */ 00117 if(!p_export_context) 00118 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_BuildExportContext); 00119 00120 /* Save pointer to fsal_staticfsinfo_t in export context */ 00121 p_export_context->fe_static_fs_info = &global_fs_info; 00122 00123 if((fs_specific_options != NULL) && (fs_specific_options[0] != '\0')) 00124 { 00125 00126 /* copy the option string (because it is modified by getsubopt call) */ 00127 strncpy(subopts, fs_specific_options, 256); 00128 subopts[255] = '\0'; 00129 p_subop = subopts; /* set initial pointer */ 00130 00131 /* parse the FS specific option string */ 00132 00133 switch (Getsubopt(&p_subop, fs_specific_opts, &value)) 00134 { 00135 case YOUR_OPTION_1: 00136 /* analyze your option 1 and fill the export_context structure */ 00137 break; 00138 00139 case YOUR_OPTION_2: 00140 /* analyze your option 2 and fill the export_context structure */ 00141 break; 00142 00143 case YOUR_OPTION_3: 00144 /* analyze your option 3 and fill the export_context structure */ 00145 break; 00146 00147 case YOUR_OPTION_4: 00148 /* analyze your option 4 and fill the export_context structure */ 00149 break; 00150 00151 default: 00152 { 00153 LogCrit(COMPONENT_CONFIG, 00154 "FSAL LOAD PARAMETER: ERROR: Invalid suboption found in EXPORT::FS_Specific : %s : xxxxxx expected.", 00155 value); 00156 Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_BuildExportContext); 00157 } 00158 } 00159 00160 } 00161 00162 /* >> you can then deal with the global config of your export 00163 * and finish initializing it << */ 00164 00165 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_BuildExportContext); 00166 00167 } 00168 00169 fsal_status_t FSAL_InitClientContext(fsal_op_context_t * p_thr_context) 00170 { 00171 00172 int rc, i; 00173 00174 /* sanity check */ 00175 if(!p_thr_context) 00176 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_InitClientContext); 00177 00178 /* initialy set the export entry to none */ 00179 p_thr_context->export_context = NULL; 00180 00181 /* >> initialize thread specific structures here << */ 00182 00183 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_InitClientContext); 00184 00185 } 00186 00210 fsal_status_t FSAL_GetClientContext(fsal_op_context_t * p_thr_context, /* IN/OUT */ 00211 fsal_export_context_t * p_export_context, /* IN */ 00212 fsal_uid_t uid, /* IN */ 00213 fsal_gid_t gid, /* IN */ 00214 fsal_gid_t * alt_groups, /* IN */ 00215 fsal_count_t nb_alt_groups /* IN */ 00216 ) 00217 { 00218 00219 fsal_status_t st; 00220 00221 /* sanity check */ 00222 if(!p_thr_context || !p_export_context) 00223 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_GetClientContext); 00224 00225 /* set the specific export context */ 00226 p_thr_context->export_context = p_export_context; 00227 00228 /* >> you can manage user's authentication and adjust thread specific 00229 * stuff you need for the subsequent request << */ 00230 00231 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_GetClientContext); 00232 00233 } 00234 00235 /* @} */