/Home/aooliver/work/stagersvc/org.glite.data.lcg_gfal/src/mds_ifce.c File Reference

#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <lber.h>
#include <ldap.h>

Go to the source code of this file.

Defines

#define ERROR_STR_LEN   255

Functions

 get_bdii (char *bdii_server, int buflen, int *bdii_port, char *errbuf, int errbufsz)
 get_ce_ap (const char *host, char **ce_ap)
 get_ce_apx (const char *host, char **ce_ap, char *errbuf, int errbufsz)
 get_rls_endpoints (char **lrc_endpoint, char **rmc_endpoint)
 get_rls_endpointsx (char **lrc_endpoint, char **rmc_endpoint, char *errbuf, int errbufsz)
 get_lfc_endpoint (char **lfc_endpoint, char *errbuf, int errbufsz)
 get_sa_root (const char *host, const char *vo, char **sa_root)
 get_sa_rootx (const char *host, const char *vo, char **sa_root, char *errbuf, int errbufsz)
 get_sa_path (const char *host, const char *vo, char **sa_path, char **sa_root, char *errbuf, int errbufsz)
 get_se_endpoint (const char *host, char **se_endpoint)
 get_se_endpointx (const char *host, char **se_endpoint, char *errbuf, int errbufsz)
 get_se_port (const char *host, int *se_port)
 get_se_portx (const char *host, int *se_port, char *errbuf, int errbufsz)
 get_se_type (const char *host, char **se_type)
 get_se_typex (const char *host, char **se_type, char *errbuf, int errbufsz)
 get_seap_info (const char *host, char ***access_protocol, int **port)
 get_seap_infox (const char *host, char ***access_protocol, int **port, char *errbuf, int errbufsz)

Variables

static char * dn = "mds-vo-name=local,o=grid"


Define Documentation

#define ERROR_STR_LEN   255
 

Definition at line 17 of file mds_ifce.c.

Referenced by get_ce_apx(), get_lfc_endpoint(), get_rls_endpointsx(), get_sa_path(), get_sa_rootx(), get_se_endpointx(), get_se_portx(), get_se_typex(), and get_seap_infox().


Function Documentation

get_bdii char *  bdii_server,
int  buflen,
int *  bdii_port,
char *  errbuf,
int  errbufsz
 

Definition at line 20 of file mds_ifce.c.

References gfal_errmsg().

Referenced by get_ce_apx(), get_lfc_endpoint(), get_rls_endpointsx(), get_sa_path(), get_sa_rootx(), get_se_endpointx(), get_se_portx(), get_se_typex(), and get_seap_infox().

00021 {
00022         char *bdii_env;
00023         char *p;
00024 
00025         if ((bdii_env = getenv ("LCG_GFAL_INFOSYS")) == NULL ||
00026             strlen (bdii_env) >= buflen) {
00027                 gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_INFOSYS not set or invalid");
00028                 errno = EINVAL;
00029                 return (-1);
00030         }
00031         strcpy (bdii_server, bdii_env);
00032         if ((p = strchr (bdii_server, ':')) == NULL) {
00033                 gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_INFOSYS invalid");
00034                 errno = EINVAL;
00035                 return (-1);
00036         }
00037         *p = '\0';
00038         *bdii_port = atoi (p + 1);
00039         return (0);
00040 }

get_ce_ap const char *  host,
char **  ce_ap
 

Definition at line 44 of file mds_ifce.c.

References get_ce_apx().

00045 {
00046         return (get_ce_apx (host, ce_ap, NULL, 0));
00047 }

get_ce_apx const char *  host,
char **  ce_ap,
char *  errbuf,
int  errbufsz
 

Definition at line 49 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_ce_ap().

00050 {
00051         static char ce_ap_atnm[] = "GlueCESEBindCEAccesspoint";
00052         static char *template = "(GlueCESEBindSEUniqueID=%s)";
00053         char *attr;
00054         static char *attrs[] = {ce_ap_atnm, NULL};
00055         int bdii_port;
00056         char bdii_server[75];
00057         LDAPMessage *entry;
00058         char filter[128];
00059         LDAP *ld;
00060         int rc = 0;
00061         LDAPMessage *reply;
00062         struct timeval timeout;
00063         char **value;
00064         char error_str[ERROR_STR_LEN];
00065 
00066         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00067                 return (-1);
00068         if (strlen (template) + strlen (host) - 2 >= sizeof(filter)) {
00069                 snprintf(error_str, ERROR_STR_LEN, "BDII Hostname too long: %s:%d", bdii_server, bdii_port);
00070                 gfal_errmsg (errbuf, errbufsz, error_str);
00071                 errno = EINVAL;
00072                 return (-1);
00073         }
00074         sprintf (filter, template, host);
00075 
00076         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00077                 return (-1);
00078         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00079                 ldap_unbind (ld);
00080                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00081                 gfal_errmsg(errbuf, errbufsz, error_str);
00082                 errno = ECONNREFUSED;
00083         return (-1);
00084         }
00085         timeout.tv_sec = 15;
00086         timeout.tv_usec = 0;
00087         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00088             &timeout, &reply)) != LDAP_SUCCESS) {
00089                 ldap_unbind (ld);
00090                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00091                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00092                         gfal_errmsg(errbuf, errbufsz, error_str);
00093                         errno = ETIMEDOUT;
00094                 } else {
00095                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00096                                   ldap_err2string(rc));
00097                         gfal_errmsg(errbuf, errbufsz, error_str);
00098                         errno = EINVAL;
00099                 }
00100                 return (-1);
00101 
00102         }
00103         entry = ldap_first_entry (ld, reply);
00104         if (entry) {
00105                 value = ldap_get_values (ld, entry, ce_ap_atnm);
00106                 if (value == NULL) {
00107                         snprintf(error_str, ERROR_STR_LEN, "CE Accesspoint not found for host : %s", host);
00108                         gfal_errmsg (errbuf, errbufsz, error_str);
00109                         errno = EINVAL;
00110                         rc = -1;
00111 
00112                 } else {
00113                   if ((*ce_ap = strdup (value[0])) == NULL)
00114                     rc = -1;
00115                   ldap_value_free (value);
00116                 }
00117         } else {
00118                 snprintf(error_str, ERROR_STR_LEN, "No GlueCESEBind found for host : %s", host);
00119                 gfal_errmsg (errbuf, errbufsz, error_str);
00120                 errno = EINVAL;
00121                 rc = -1;
00122         }
00123         ldap_msgfree (reply);
00124         ldap_unbind (ld);
00125         return (rc);
00126 }

get_lfc_endpoint char **  lfc_endpoint,
char *  errbuf,
int  errbufsz
 

Definition at line 248 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by lfc_init().

00249 {
00250         static char ep[] = "GlueServiceAccessPointURL";
00251         static char type[] = "GlueServiceType";
00252         static char *template = "(&(GlueServiceType=*)(GlueServiceAccessControlRule=%s))";
00253         char *attr;
00254         static char *attrs[] = {type, ep, NULL};
00255         int bdii_port;
00256         char bdii_server[75];
00257         BerElement *ber;
00258         LDAPMessage *entry;
00259         char filter[128];
00260         LDAP *ld;
00261         int rc = 0;
00262         LDAPMessage *reply;
00263         char *service_type;
00264         char *service_url;
00265         struct timeval timeout;
00266         char **value;
00267         char *vo;
00268         char error_str[ERROR_STR_LEN];
00269         
00270         *lfc_endpoint = NULL;
00271         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00272                 return (-1);
00273         if ((vo = getenv ("LCG_GFAL_VO")) == NULL) {
00274                 gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_VO not set");
00275                 errno = EINVAL;
00276                 return (-1);
00277         }
00278         if (strlen (template) + strlen (vo) - 2 >= sizeof(filter)) {
00279                 gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_VO too long");
00280                 errno = EINVAL;
00281                 return (-1);
00282         }
00283         sprintf (filter, template, vo);
00284 
00285         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00286                 return (-1);
00287         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00288                 ldap_unbind (ld);
00289                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00290                 gfal_errmsg(errbuf, errbufsz, error_str);
00291                 errno = ECONNREFUSED;
00292                 return (-1);
00293         }
00294         timeout.tv_sec = 15;
00295         timeout.tv_usec = 0;
00296         if (ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00297             &timeout, &reply) != LDAP_SUCCESS) {
00298                 ldap_unbind (ld);
00299                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00300                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00301                         gfal_errmsg(errbuf, errbufsz, error_str);
00302                         errno = ETIMEDOUT;
00303                 } else {
00304                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00305                                  ldap_err2string(rc));
00306                         gfal_errmsg(errbuf, errbufsz, error_str);
00307                         errno = EINVAL;
00308                 }
00309                 return (-1);
00310         }
00311         for (entry = ldap_first_entry (ld, reply);
00312              entry != NULL;
00313              entry = ldap_next_entry (ld, entry)) {
00314                 service_type = NULL;
00315                 service_url = NULL;
00316                 for (attr = ldap_first_attribute (ld, entry, &ber);
00317                      attr != NULL;
00318                      attr = ldap_next_attribute (ld, entry, ber)) {
00319                         value = ldap_get_values (ld, entry, attr);
00320                         if (value == NULL) {
00321                                 rc = -1;
00322                                 continue;
00323                         }
00324                         if (strcmp (attr, "GlueServiceType") == 0) {
00325                                 if((service_type = strdup (value[0])) == NULL)
00326                                         rc = -1;
00327                         } else {        /* GlueServiceAccessPointURL */
00328                                 if((service_url = strdup (value[0])) == NULL)
00329                                         rc = -1;
00330                         }
00331                         ldap_value_free (value);
00332                 }
00333                 if (rc == 0) {
00334                         if (strcmp (service_type, "lcg-file-catalog") == 0) {
00335                           if ((*lfc_endpoint = strdup (service_url)) == NULL)
00336                             rc = -1;
00337                         }
00338                 }
00339                 free (service_type);
00340                 free (service_url);
00341         }
00342         if (*lfc_endpoint == NULL) {
00343                 gfal_errmsg (errbuf, errbufsz, "LFC endpoint not found");
00344                 errno = EINVAL;
00345                 rc = -1;
00346         }
00347         ldap_msgfree (reply);
00348         ldap_unbind (ld);
00349         return (rc);
00350 }

get_rls_endpoints char **  lrc_endpoint,
char **  rmc_endpoint
 

Definition at line 130 of file mds_ifce.c.

References get_rls_endpointsx().

00131 {
00132         return (get_rls_endpointsx (lrc_endpoint, rmc_endpoint, NULL, 0));
00133 }

get_rls_endpointsx char **  lrc_endpoint,
char **  rmc_endpoint,
char *  errbuf,
int  errbufsz
 

Definition at line 135 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_rls_endpoints(), lrc_init(), and rmc_init().

00136 {
00137         static char rls_ep[] = "GlueServiceAccessPointURL";
00138         static char rls_type[] = "GlueServiceType";
00139         static char *template = "(&(GlueServiceType=*)(GlueServiceAccessControlRule=%s))";
00140         char *attr;
00141         static char *attrs[] = {rls_type, rls_ep, NULL};
00142         int bdii_port;
00143         char bdii_server[75];
00144         BerElement *ber;
00145         LDAPMessage *entry;
00146         char filter[128];
00147         LDAP *ld;
00148         int rc = 0;
00149         LDAPMessage *reply;
00150         char *service_type;
00151         char *service_url;
00152         struct timeval timeout;
00153         char **value;
00154         char *vo;
00155         char error_str[ERROR_STR_LEN];
00156 
00157         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00158                 return (-1);
00159         if ((vo = getenv ("LCG_GFAL_VO")) == NULL) {
00160                 gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_VO not set");
00161                 errno = EINVAL;
00162                 return (-1);
00163         }
00164         if (strlen (template) + strlen (vo) - 2 >= sizeof(filter)) {
00165                 gfal_errmsg (errbuf, errbufsz, "LCG_GFAL_VO too long");
00166                 errno = EINVAL;
00167                 return (-1);
00168         }
00169         sprintf (filter, template, vo);
00170 
00171         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00172                 return (-1);
00173         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00174                 ldap_unbind (ld);
00175                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00176                 gfal_errmsg(errbuf, errbufsz, error_str);
00177                 errno = ECONNREFUSED;
00178                 return (-1);
00179         }
00180         timeout.tv_sec = 15;
00181         timeout.tv_usec = 0;
00182         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00183             &timeout, &reply)) != LDAP_SUCCESS) {
00184                 ldap_unbind (ld);
00185                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00186                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00187                         gfal_errmsg(errbuf, errbufsz, error_str);
00188                         errno = ETIMEDOUT;
00189                 } else {
00190                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00191                                  ldap_err2string(rc));
00192                         gfal_errmsg(errbuf, errbufsz, error_str);
00193                         errno = EINVAL;
00194                 }
00195                 return (-1);
00196         }
00197         for (entry = ldap_first_entry (ld, reply);
00198              entry != NULL;
00199              entry = ldap_next_entry (ld, entry)) {
00200                 service_type = NULL;
00201                 service_url = NULL;
00202                 for (attr = ldap_first_attribute (ld, entry, &ber);
00203                      attr != NULL;
00204                      attr = ldap_next_attribute (ld, entry, ber)) {
00205                         value = ldap_get_values (ld, entry, attr);
00206                         if (value != NULL) {
00207                                 if (strcmp (attr, "GlueServiceType") == 0) {
00208                                         if((service_type = strdup (value[0])) == NULL)
00209                                                 rc = -1;
00210                                 } else {        /* GlueServiceAccessPointURL */
00211                                         if((service_url = strdup (value[0])) == NULL)
00212                                                 rc = -1;
00213                                 }
00214                                 ldap_value_free (value);
00215                         }
00216                         else 
00217                                 rc = -1;
00218                 }
00219                 if (rc == 0) {
00220                         if (strcmp (service_type, "edg-replica-metadata-catalog") == 0) {
00221                                 if ((*rmc_endpoint = strdup (service_url)) == NULL)
00222                                         rc = -1;
00223                         } else if (strcmp (service_type, "edg-local-replica-catalog") == 0) {
00224                                 if ((*lrc_endpoint = strdup (service_url)) == NULL)
00225                                         rc = -1;
00226                         }
00227                 }
00228                 free (service_type);
00229                 free (service_url);
00230         }
00231         if (*lrc_endpoint == NULL) {
00232                 gfal_errmsg (errbuf, errbufsz, "LRC endpoint not found");
00233                 errno = EINVAL;
00234                 rc = -1;
00235         }
00236         if (*rmc_endpoint == NULL) {
00237                 gfal_errmsg (errbuf, errbufsz, "RMC endpoint not found");
00238                 errno = EINVAL;
00239                 rc = -1;
00240         }
00241         ldap_msgfree (reply);
00242         ldap_unbind (ld);
00243         return (rc);
00244 }

get_sa_path const char *  host,
const char *  vo,
char **  sa_path,
char **  sa_root,
char *  errbuf,
int  errbufsz
 

Definition at line 432 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), get_sa_rootx(), and gfal_errmsg().

00433 {
00434         static char sa_path_atnm[] = "GlueSAPath";
00435         static char sa_root_atnm[] = "GlueSARoot";
00436         static char *template = "(&(GlueSALocalID=%s)(GlueChunkKey=GlueSEUniqueID=%s))";
00437         char *attr;
00438         static char *attrs[] = {sa_root_atnm, sa_path_atnm, NULL};
00439         int bdii_port;
00440         char bdii_server[75];
00441         LDAPMessage *entry;
00442         char filter[128];
00443         LDAP *ld;
00444         int rc = 0;
00445         LDAPMessage *reply;
00446         struct timeval timeout;
00447         char **value;
00448         char error_str[ERROR_STR_LEN];
00449 
00450         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00451                 return (-1);
00452         if (strlen (template) + strlen (vo) + strlen (host) - 4 >= sizeof(filter)) {
00453                 gfal_errmsg (errbuf, errbufsz, "vo or host too long");
00454                 errno = EINVAL;
00455                 return (-1);
00456         }
00457         sprintf (filter, template, vo, host);
00458 
00459         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00460                 return (-1);
00461         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00462                 ldap_unbind (ld);
00463                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00464                 gfal_errmsg(errbuf, errbufsz, error_str);
00465                 errno = ECONNREFUSED;
00466                 return (-1);
00467         }
00468         timeout.tv_sec = 15;
00469         timeout.tv_usec = 0;
00470         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00471             &timeout, &reply)) != LDAP_SUCCESS) {
00472                 ldap_unbind (ld);
00473                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00474                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00475                         gfal_errmsg(errbuf, errbufsz, error_str);
00476                         errno = ETIMEDOUT;
00477                 } else {
00478                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00479                                  ldap_err2string(rc));
00480                         gfal_errmsg(errbuf, errbufsz, error_str);
00481                         errno = EINVAL;
00482                 }
00483                 return (-1);
00484         }
00485         *sa_path = NULL;
00486         *sa_root = NULL;
00487         entry = ldap_first_entry (ld, reply);
00488         if (entry) {
00489                 value = ldap_get_values (ld, entry, sa_path_atnm);
00490                 if (value != NULL) {
00491                         /* We deal with pre-LCG 2.7.0 where SA Path was incorrect and had vo: prefix */
00492                         if ((strncmp(value[0], vo, strlen(vo)) == 0) && (*(value[0] + strlen(vo)) == ':')) {
00493                                 if ((*sa_path = strdup (value[0] + strlen (vo) + 1)) == NULL)
00494                                         rc = -1;
00495                         } else
00496                                 if ((*sa_path = strdup (value[0])) == NULL)
00497                                         rc = -1;
00498                 }
00499                 ldap_value_free (value);
00500                 
00501                 value = ldap_get_values (ld, entry, sa_root_atnm);
00502                 if (value != NULL) {
00503                         if ((*sa_root = strdup (value[0] + strlen (vo) + 1)) == NULL)
00504                                 rc = -1;
00505                 }
00506                 ldap_value_free (value);
00507 
00508         } else {
00509                 /* try and get SA root via old method for pre-2.5 SEs */
00510                 if (get_sa_rootx (host, vo, sa_root, errbuf, errbufsz) < 0 ) {
00511                         snprintf(error_str, ERROR_STR_LEN, "No GlueSA information found for SE (vo) : %s (%s)", host, vo);
00512                         gfal_errmsg (errbuf, errbufsz, error_str);
00513                         errno = EINVAL;
00514                         rc = -1;               
00515                 } 
00516                 
00517         }
00518         if (rc == 0) 
00519                 if (*sa_path == NULL && *sa_root == NULL) {
00520                         snprintf(error_str, ERROR_STR_LEN, 
00521                                  "Both SAPath and SARoot not set for SE (vo) : %s (%s)", 
00522                                  host, vo);
00523                         gfal_errmsg (errbuf, errbufsz, error_str);
00524                         errno = EINVAL;
00525                         rc = -1;
00526                 }
00527         ldap_msgfree (reply);
00528         ldap_unbind (ld);
00529         return (rc);
00530 }

get_sa_root const char *  host,
const char *  vo,
char **  sa_root
 

Definition at line 354 of file mds_ifce.c.

References get_sa_rootx().

00355 {
00356         return (get_sa_rootx (host, vo, sa_root, NULL, 0));
00357 }

get_sa_rootx const char *  host,
const char *  vo,
char **  sa_root,
char *  errbuf,
int  errbufsz
 

Definition at line 359 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_sa_path(), and get_sa_root().

00360 {
00361         static char sa_root_atnm[] = "GlueSARoot";
00362         static char *template = "(&(GlueSARoot=%s:*)(GlueChunkKey=GlueSEUniqueID=%s))";
00363         char *attr;
00364         static char *attrs[] = {sa_root_atnm, NULL};
00365         int bdii_port;
00366         char bdii_server[75];
00367         LDAPMessage *entry;
00368         char filter[128];
00369         LDAP *ld;
00370         int rc = 0;
00371         LDAPMessage *reply;
00372         struct timeval timeout;
00373         char **value;
00374         char error_str[ERROR_STR_LEN];
00375 
00376         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00377                 return (-1);
00378         if (strlen (template) + strlen (vo) + strlen (host) - 4 >= sizeof(filter)) {
00379                 gfal_errmsg (errbuf, errbufsz, "vo or host too long");
00380                 errno = EINVAL;
00381                 return (-1);
00382         }
00383         sprintf (filter, template, vo, host);
00384 
00385         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00386                 return (-1);
00387         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00388                 ldap_unbind (ld);
00389                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00390                 gfal_errmsg(errbuf, errbufsz, error_str);
00391                 errno = ECONNREFUSED;
00392                 return (-1);
00393         }
00394         timeout.tv_sec = 15;
00395         timeout.tv_usec = 0;
00396         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00397             &timeout, &reply)) != LDAP_SUCCESS) {
00398                 ldap_unbind (ld);
00399                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00400                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00401                         gfal_errmsg(errbuf, errbufsz, error_str);
00402                         errno = ETIMEDOUT;
00403                 } else {
00404                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00405                                  ldap_err2string(rc));
00406                         gfal_errmsg(errbuf, errbufsz, error_str);
00407                         errno = EINVAL;
00408                 }
00409                 return (-1);
00410         }
00411         entry = ldap_first_entry (ld, reply);
00412         if (entry) {
00413                 value = ldap_get_values (ld, entry, sa_root_atnm);
00414                 if (value == NULL) 
00415                         goto notfound;
00416                 if ((*sa_root = strdup (value[0] + strlen (vo) + 1)) == NULL)
00417                         rc = -1;
00418                 ldap_value_free (value);
00419         } else {
00420 notfound:       snprintf(error_str, ERROR_STR_LEN, "SA Root not found for host : %s", host);
00421                 gfal_errmsg (errbuf, errbufsz, error_str);
00422                 errno = EINVAL;
00423                 rc = -1;
00424         }
00425         ldap_msgfree (reply);
00426         ldap_unbind (ld);
00427         return (rc);
00428 }

get_se_endpoint const char *  host,
char **  se_endpoint
 

Definition at line 535 of file mds_ifce.c.

References get_se_endpointx().

00536 {
00537         return (get_se_endpointx (host, se_endpoint, NULL, 0));
00538 }

get_se_endpointx const char *  host,
char **  se_endpoint,
char *  errbuf,
int  errbufsz
 

Definition at line 540 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_se_endpoint().

00541 {
00542         static char se_ep_atnm[] = "GlueServiceURI";
00543         static char *template = "(&(GlueServiceURI=*%s*)(GlueServiceType=srm_v1))";
00544         char *attr;
00545         static char *attrs[] = {se_ep_atnm, NULL};
00546         int bdii_port;
00547         char bdii_server[75];
00548         LDAPMessage *entry;
00549         char filter[128];
00550         LDAP *ld;
00551         int rc = 0;
00552         LDAPMessage *reply;
00553         struct timeval timeout;
00554         char **value;
00555         char error_str[ERROR_STR_LEN];
00556         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00557                 return (-1);
00558         if (strlen (template) + strlen (host) - 2 >= sizeof(filter)) {
00559                 gfal_errmsg (errbuf, errbufsz, "host too long");
00560                 errno = EINVAL;
00561                 return (-1);
00562         }
00563         sprintf (filter, template, host);
00564 
00565         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00566                 return (-1);
00567         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00568                 ldap_unbind (ld);
00569                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00570                 gfal_errmsg(errbuf, errbufsz, error_str);
00571                 errno = ECONNREFUSED;
00572                 return (-1);
00573         }
00574         timeout.tv_sec = 15;
00575         timeout.tv_usec = 0;
00576         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00577             &timeout, &reply)) != LDAP_SUCCESS) {
00578                 ldap_unbind (ld);
00579                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00580                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00581                         gfal_errmsg(errbuf, errbufsz, error_str);
00582                         errno = ETIMEDOUT;
00583                 } else {
00584                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00585                                  ldap_err2string(rc));
00586                         gfal_errmsg(errbuf, errbufsz, error_str);
00587                         errno = EINVAL;
00588                 }
00589                 return (-1);
00590         }
00591         entry = ldap_first_entry (ld, reply);
00592         if (entry) {
00593                 value = ldap_get_values (ld, entry, se_ep_atnm);
00594                 if (value == NULL) {
00595                         snprintf(error_str, ERROR_STR_LEN, "SE (SRM) endpoint not set for host : %s", host);
00596                         gfal_errmsg (errbuf, errbufsz, "SE (SRM) endpoint not set for host : %s");
00597                         errno = EINVAL;         
00598                         rc = -1;
00599                 }
00600                 else {
00601                         if ((*se_endpoint = strdup (value[0])) == NULL)
00602                                 rc = -1;
00603                         ldap_value_free (value);
00604                 }
00605         } else {
00606                 snprintf(error_str, ERROR_STR_LEN, "SE (SRM) service not found for host : %s", host);
00607                 gfal_errmsg (errbuf, errbufsz, error_str);
00608                 errno = EINVAL;
00609                 rc = -1;
00610         }
00611         ldap_msgfree (reply);
00612         ldap_unbind (ld);
00613         return (rc);
00614 }

get_se_port const char *  host,
int *  se_port
 

Definition at line 618 of file mds_ifce.c.

References get_se_portx().

00619 {
00620         return (get_se_portx (host, se_port, NULL, 0));
00621 }

get_se_portx const char *  host,
int *  se_port,
char *  errbuf,
int  errbufsz
 

Definition at line 623 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_se_port().

00624 {
00625         static char se_port_atnm[] = "GlueSEPort";
00626         static char *template = "(GlueSEUniqueID=%s)";
00627         char *attr;
00628         static char *attrs[] = {se_port_atnm, NULL};
00629         int bdii_port;
00630         char bdii_server[75];
00631         LDAPMessage *entry;
00632         char filter[128];
00633         LDAP *ld;
00634         int rc = 0;
00635         LDAPMessage *reply;
00636         struct timeval timeout;
00637         char **value;
00638         char error_str[ERROR_STR_LEN];
00639 
00640         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00641                 return (-1);
00642         if (strlen (template) + strlen (host) - 2 >= sizeof(filter)) {
00643                 gfal_errmsg (errbuf, errbufsz, "host too long");
00644                 errno = EINVAL;
00645                 return (-1);
00646         }
00647         sprintf (filter, template, host);
00648 
00649         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00650                 return (-1);
00651         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00652                 ldap_unbind (ld);
00653                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00654                 gfal_errmsg(errbuf, errbufsz, error_str);
00655                 errno = ECONNREFUSED;
00656                 return (-1);
00657         }
00658         timeout.tv_sec = 15;
00659         timeout.tv_usec = 0;
00660         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00661             &timeout, &reply)) != LDAP_SUCCESS) {
00662                 ldap_unbind (ld);
00663                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00664                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00665                         gfal_errmsg(errbuf, errbufsz, error_str);
00666                         errno = ETIMEDOUT;
00667                 } else {
00668                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00669                                  ldap_err2string(rc));
00670                         gfal_errmsg(errbuf, errbufsz, error_str);
00671                         errno = EINVAL;
00672                 }
00673                 return (-1);
00674         }
00675         entry = ldap_first_entry (ld, reply);
00676         if (entry) {
00677                 value = ldap_get_values (ld, entry, se_port_atnm);
00678                 if (value == NULL) {
00679                         snprintf(error_str, ERROR_STR_LEN, "SE port not found for host : %s", host);
00680                         gfal_errmsg (errbuf, errbufsz, error_str);
00681                         errno = EINVAL;
00682                         rc = -1;
00683                 } else {
00684                         *se_port = atoi (value[0]);
00685                         ldap_value_free (value);
00686                 }
00687         } else {
00688                 snprintf(error_str, ERROR_STR_LEN,"No information found for SE : %s", host);
00689                 gfal_errmsg (errbuf, errbufsz, error_str);
00690                 errno = EINVAL;
00691                 rc = -1;
00692         }
00693         ldap_msgfree (reply);
00694         ldap_unbind (ld);
00695         return (rc);
00696 }

get_se_type const char *  host,
char **  se_type
 

Definition at line 700 of file mds_ifce.c.

References get_se_typex().

00701 {
00702         return (get_se_typex (host, se_type, NULL, 0));
00703 }

get_se_typex const char *  host,
char **  se_type,
char *  errbuf,
int  errbufsz
 

Definition at line 705 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_se_type(), and setypefromsurl().

00706 {
00707         static char se_type_atnm[] = "GlueSEName";
00708         static char *template = "(GlueSEUniqueID=%s)";
00709         char *attr;
00710         static char *attrs[] = {se_type_atnm, NULL};
00711         int bdii_port;
00712         char bdii_server[75];
00713         LDAPMessage *entry;
00714         char filter[128];
00715         LDAP *ld;
00716         char *p;
00717         int rc = 0;
00718         LDAPMessage *reply;
00719         struct timeval timeout;
00720         char **value;
00721         char error_str[ERROR_STR_LEN];
00722 
00723         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00724                 return (-1);
00725         if (strlen (template) + strlen (host) - 2 >= sizeof(filter)) {
00726                 gfal_errmsg (errbuf, errbufsz, "host too long");
00727                 errno = EINVAL;
00728                 return (-1);
00729         }
00730         sprintf (filter, template, host);
00731 
00732         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00733                 return (-1);
00734         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00735                 ldap_unbind (ld);
00736                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00737                 gfal_errmsg(errbuf, errbufsz, error_str);
00738                 errno = ECONNREFUSED;
00739                 return (-1);
00740         }
00741         timeout.tv_sec = 15;
00742         timeout.tv_usec = 0;
00743         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00744             &timeout, &reply)) != LDAP_SUCCESS) {
00745                 ldap_unbind (ld);
00746                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00747                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00748                         gfal_errmsg(errbuf, errbufsz, error_str);
00749                         errno = ETIMEDOUT;
00750                 } else {
00751                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00752                                  ldap_err2string(rc));
00753                         gfal_errmsg(errbuf, errbufsz, error_str);
00754                         errno = EINVAL;
00755                 }
00756                 return (-1);
00757         }
00758         entry = ldap_first_entry (ld, reply);
00759         if (entry) {
00760                 value = ldap_get_values (ld, entry, se_type_atnm);
00761                 if (value == NULL) {
00762                   snprintf(error_str, ERROR_STR_LEN,  "SE type not found for host : %s", host);
00763                   gfal_errmsg (errbuf, errbufsz, error_str);
00764                   errno = EINVAL;
00765                   rc = -1;
00766 
00767                 } else { 
00768                   if ((p = strchr (value[0], ':')))
00769                     p++;
00770                   else
00771                     p = value[0];
00772                   if ((*se_type = strdup (p)) == NULL)
00773                     rc = -1;
00774                   ldap_value_free (value);
00775                 }
00776         } else {
00777                 snprintf(error_str, ERROR_STR_LEN,  "No information found for SE : %s", host);
00778                 gfal_errmsg (errbuf, errbufsz, error_str);
00779                 errno = EINVAL;
00780                 rc = -1;
00781         }
00782         ldap_msgfree (reply);
00783         ldap_unbind (ld);
00784         return (rc);
00785 }

get_seap_info const char *  host,
char ***  access_protocol,
int **  port
 

Definition at line 791 of file mds_ifce.c.

References get_seap_infox().

00792 {
00793         return (get_seap_infox (host, access_protocol, port, NULL, 0));
00794 }

get_seap_infox const char *  host,
char ***  access_protocol,
int **  port,
char *  errbuf,
int  errbufsz
 

Definition at line 796 of file mds_ifce.c.

References dn, ERROR_STR_LEN, get_bdii(), and gfal_errmsg().

Referenced by get_seap_info().

00797 {
00798         static char proto_port[] = "GlueSEAccessProtocolPort";
00799         static char proto_type[] = "GlueSEAccessProtocolType";
00800         static char *template = "(&(GlueSEAccessProtocolType=*)(GlueChunkKey=GlueSEUniqueID=%s))";
00801         char **ap;
00802         char *attr;
00803         static char *attrs[] = {proto_type, proto_port, NULL};
00804         int bdii_port;
00805         char bdii_server[75];
00806         BerElement *ber;
00807         LDAPMessage *entry;
00808         char filter[128];
00809         int i;
00810         int j;
00811         LDAP *ld;
00812         int nbentries;
00813         int *pn;
00814         int rc = 0;
00815         LDAPMessage *reply;
00816         struct timeval timeout;
00817         char **value;
00818         char error_str[ERROR_STR_LEN];
00819 
00820         if (get_bdii (bdii_server, sizeof(bdii_server), &bdii_port, errbuf, errbufsz) < 0)
00821                 return (-1);
00822         if (strlen (template) + strlen (host) - 2 >= sizeof(filter)) {
00823                 gfal_errmsg (errbuf, errbufsz, "host too long");
00824                 errno = EINVAL;
00825                 return (-1);
00826         }
00827         sprintf (filter, template, host);
00828 
00829         if ((ld = ldap_init (bdii_server, bdii_port)) == NULL)
00830                 return (-1);
00831         if (ldap_simple_bind_s (ld, "", "") != LDAP_SUCCESS) {
00832                 ldap_unbind (ld);
00833                 snprintf(error_str, ERROR_STR_LEN, "BDII Connection Refused: %s:%d", bdii_server, bdii_port);
00834                 gfal_errmsg(errbuf, errbufsz, error_str);
00835                 errno = ECONNREFUSED;
00836                 return (-1);
00837         }
00838         timeout.tv_sec = 15;
00839         timeout.tv_usec = 0;
00840         if ((rc = ldap_search_st (ld, dn, LDAP_SCOPE_SUBTREE, filter, attrs, 0,
00841             &timeout, &reply)) != LDAP_SUCCESS) {
00842                 ldap_unbind (ld);
00843                 if (rc == LDAP_TIMELIMIT_EXCEEDED || rc == LDAP_TIMEOUT) {
00844                         snprintf(error_str, ERROR_STR_LEN, "BDII Connection Timeout: %s:%d", bdii_server, bdii_port);
00845                         gfal_errmsg(errbuf, errbufsz, error_str);
00846                         errno = ETIMEDOUT;
00847                 } else {
00848                         snprintf(error_str, ERROR_STR_LEN, "BDII ERROR: %s:%d %s", bdii_server, bdii_port, 
00849                                  ldap_err2string(rc));
00850                         gfal_errmsg(errbuf, errbufsz, error_str);
00851                         errno = EINVAL;
00852                 }
00853                 return (-1);
00854         }
00855         nbentries = ldap_count_entries (ld, reply);
00856         nbentries++;
00857         if ((ap = calloc (nbentries, sizeof(char *))) == NULL) {
00858                 ldap_unbind (ld);
00859                 return (-1);
00860         }
00861         if ((pn = calloc (nbentries, sizeof(int))) == NULL) {
00862                 free (ap);
00863                 ldap_unbind (ld);
00864                 return (-1);
00865         }
00866         for (entry = ldap_first_entry (ld, reply), i = 0;
00867              entry != NULL;
00868              entry = ldap_next_entry (ld, entry), i++) {
00869                 for (attr = ldap_first_attribute (ld, entry, &ber);
00870                      attr != NULL;
00871                      attr = ldap_next_attribute (ld, entry, ber)) {
00872                         value = ldap_get_values (ld, entry, attr);
00873                         if (value == NULL) {
00874                                 rc = -1;
00875                                 continue;
00876                         }
00877                         if (strcmp (attr, "GlueSEAccessProtocolType") == 0) {
00878                                 if ((ap[i] = strdup (value[0])) == NULL)
00879                                         rc = -1;
00880                         } else
00881                                 pn[i] = atoi (value[0]);
00882                         ldap_value_free (value);
00883                 }
00884         }
00885         ldap_msgfree (reply);
00886         ldap_unbind (ld);
00887         if (rc) {
00888                 for (j = 0; j < i; j++)
00889                         free (ap[i]);
00890                 free (ap);
00891                 free (pn);
00892         } else {
00893                 *access_protocol = ap;
00894                 *port = pn;
00895         }
00896         return (rc);
00897 }


Variable Documentation

char* dn = "mds-vo-name=local,o=grid" [static]
 

Definition at line 15 of file mds_ifce.c.

Referenced by get_ce_apx(), get_lfc_endpoint(), get_rls_endpointsx(), get_sa_path(), get_sa_rootx(), get_se_endpointx(), get_se_portx(), get_se_typex(), and get_seap_infox().


Generated on Fri Sep 8 20:20:48 2006 for GFAL by  doxygen 1.4.6