示例#1
0
文件: rmc_ifce.c 项目: ic-hep/emi3
rmc_register_alias (const char *guid, const char *lfn, char *errbuf, int errbufsz)
{
	struct rmc__addAliasResponse out;
	int ret;
	int sav_errno = 0;
	struct soap soap;

	if (rmc_init (&soap, errbuf, errbufsz) < 0)
		return (-1);

	if ((ret = soap_call_rmc__addAlias (&soap, rmc_endpoint, "",
				(char *) guid, (char *) lfn, &out))) {
		if (ret == SOAP_FAULT) {
			if (strstr (soap.fault->faultcode, "ALIASEXISTS"))
				sav_errno = EEXIST;
			else if (strstr (soap.fault->faultcode, "VALUETOOLONG"))
				sav_errno = ENAMETOOLONG;
			else {
				gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "%s", soap.fault->faultstring);
				sav_errno = ECOMM;
			}
		} else {
			gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "%s", soap.fault->faultstring);
			sav_errno = ECOMM;
		}
		soap_end (&soap);
		soap_done (&soap);
		errno = sav_errno;
		return (-1);
	}
	soap_end (&soap);
	soap_done (&soap);
	return (0);
}
示例#2
0
文件: rmc_ifce.c 项目: ic-hep/emi3
	static int
rmc_init (struct soap *soap, char *errbuf, int errbufsz)
{
	int flags;

	soap_init (soap);
	soap->namespaces = namespaces_rmc;

	if (rmc_endpoint == NULL && (rmc_endpoint = getenv ("RMC_ENDPOINT")) == NULL) {
		if (!gfal_is_nobdii ()) {
			if (get_rls_endpoints (&lrc_endpoint, &rmc_endpoint, errbuf, errbufsz) != 0) {
				errno = EINVAL;
				return (-1);
			}
		} else {
			gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR,
					"You have to define 'RMC_ENDPOINT' and 'LRC_ENDPOINT' environment variables, when BDII calls are disabled");
			errno = EINVAL;
			return (-1);
		}
	}

#ifdef GFAL_SECURE
	if (strncmp (rmc_endpoint, "https", 5) == 0) {
		flags = CGSI_OPT_SSL_COMPATIBLE;
		soap_register_plugin_arg (soap, client_cgsi_plugin, &flags);
	}
#endif
	gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR,
			"RMC/LRC are obsolete! Please use LFC instead.");
	return (0);
}
示例#3
0
文件: rmc_ifce.c 项目: ic-hep/emi3
	char *
rmc_guidfromlfn (const char *lfn, char *errbuf, int errbufsz)
{
	struct rmc__guidForAliasResponse out;
	char *p;
	int ret;
	int sav_errno = 0;
	struct soap soap;

	if (rmc_init (&soap, errbuf, errbufsz) < 0)
		return (NULL);

	if ((ret = soap_call_rmc__guidForAlias (&soap, rmc_endpoint, "",
				(char *) lfn, &out))) {
		if (ret == SOAP_FAULT && strstr (soap.fault->faultcode, "NOSUCHALIAS"))
			sav_errno = ENOENT;
		else {
			gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "%s", soap.fault->faultstring);
			sav_errno = ECOMM;
		}
		soap_end (&soap);
		soap_done (&soap);
		errno = sav_errno;
		return (NULL);
	} else {
		p = strdup (out._guidForAliasReturn);
		soap_end (&soap);
		soap_done (&soap);
		return (p);
	}
}
示例#4
0
文件: lrc_ifce.c 项目: ic-hep/emi3
lrc_setfilesize (const char *pfn, GFAL_LONG64 filesize, char *errbuf, int errbufsz)
{
	struct lrc__setStringPfnAttributeResponse out;
	int ret;
	int sav_errno = 0;
	struct soap soap;
	char tmpbuf[21];

	if (lrc_init (&soap, errbuf, errbufsz) < 0)
		return (-1);

	sprintf (tmpbuf, GFAL_LONG64_FORMAT, filesize);
	if ((ret = soap_call_lrc__setStringPfnAttribute (&soap, lrc_endpoint,
				"", (char *) pfn, "size", tmpbuf, &out))) {
		if (ret == SOAP_FAULT && strstr (soap.fault->faultcode, "NOSUCHPFN")) {
			sav_errno = ENOENT;
		} else {
			gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "%s", soap.fault->faultstring);
			sav_errno = ECOMM;
		}
		soap_end (&soap);
		soap_done (&soap);
		errno = sav_errno;
		return (-1);
	}
	soap_end (&soap);
	soap_done (&soap);
	return (0);
}
示例#5
0
文件: lrc_ifce.c 项目: ic-hep/emi3
	char *
lrc_guidforpfn (const char *pfn, char *errbuf, int errbufsz)
{
	struct lrc__guidForPfnResponse out;
	char *p;
	int ret;
	int sav_errno = 0;
	struct soap soap;

	if (lrc_init (&soap, errbuf, errbufsz) < 0)
		return (NULL);

	if ((ret = soap_call_lrc__guidForPfn (&soap, lrc_endpoint, "",
					(char *) pfn, &out))) {
		if (ret == SOAP_FAULT && strstr (soap.fault->faultcode, "NOSUCHPFN")) {
			sav_errno = ENOENT;
		} else {
			gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "%s", soap.fault->faultstring);
			sav_errno = ECOMM;
		}
		soap_end (&soap);
		soap_done (&soap);
		errno = sav_errno;
		return (NULL);
	}
	p = strdup (out._guidForPfnReturn);
	soap_end (&soap);
	soap_done (&soap);
	return (p);
}
示例#6
0
文件: lrc_ifce.c 项目: ic-hep/emi3
	int
lrc_replica_exists (const char *guid, char *errbuf, int errbufsz)
{
	struct lrc__getPfnsResponse out;
	int ret;
	int sav_errno = 0;
	struct soap soap;

	if (lrc_init (&soap, errbuf, errbufsz) < 0)
		return (-1);

	if ((ret = soap_call_lrc__getPfns (&soap, lrc_endpoint, "",
					(char *) guid, &out))) {
		if (ret == SOAP_FAULT && strstr (soap.fault->faultcode, "NOSUCHGUID")) {
			sav_errno = 0;
		} else {
			gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "%s", soap.fault->faultstring);
			sav_errno = ECOMM;
		}
		soap_end (&soap);
		soap_done (&soap);
		// return 'false' if guid does not exist in LRC
		if(sav_errno == 0)
			return (0);

		errno = sav_errno;
		return (-1);
	}
	soap_end (&soap);
	soap_done (&soap);
	return (out._getPfnsReturn->__size==0?0:1);
}
示例#7
0
lcg_lg2 (char *file, int nobdii, char *vo, char *guid, char *errbuf, int errbufsz)
{
	char *actual_guid;
	char actual_file[GFAL_PATH_MAXLEN];

	if (file == NULL || guid == NULL) {
		errno = EFAULT;
		return (-1);
	}
	if (vo && vo[0]) {
		if (strlen (vo) > GFAL_VO_MAXLEN) {
			gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "VO name too long.");
			errno = ENAMETOOLONG;
			return (-1);
		}
		if (gfal_set_vo (vo) < 0)
			return (-1);
	}

	if (canonical_url (file, NULL, actual_file, GFAL_PATH_MAXLEN, errbuf, GFAL_ERRMSG_LEN) < 0)
		return (-1);

	gfal_set_nobdii (nobdii);

	if (strncmp (actual_file, "lfn:", 4) == 0) {
		if ((actual_guid = guidfromlfn (actual_file + 4, errbuf, errbufsz)) == NULL)
			return (-1);
	} else if (strncmp (actual_file, "srm:", 4) == 0 || strncmp (actual_file, "sfn:", 4) == 0) {
		if ((actual_guid = gfal_guidforpfn (actual_file, errbuf, errbufsz)) == NULL)
			return (-1);
	} else {
		gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR,
				"%s: File starts with neither \"lfn:\", \"srm:\" nor \"sfn:\".", file);
		errno = EINVAL;
		return (-1);
	}
	strcpy (guid, actual_guid);
	free (actual_guid);
	return (0);
}
示例#8
0
文件: rmc_ifce.c 项目: ic-hep/emi3
rmc_unregister_alias (const char *guid, const char *lfn, char *errbuf, int errbufsz)
{
	struct rmc__removeAliasResponse out;
	int ret;
	struct soap soap;

	if (rmc_init (&soap, errbuf, errbufsz) < 0)
		return (-1);

	if ((ret = soap_call_rmc__removeAlias (&soap, rmc_endpoint, "",
				(char *) guid, (char *) lfn, &out))) {
		gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "%s", soap.fault->faultstring);
		soap_end (&soap);
		soap_done (&soap);
		errno = ECOMM;
		return (-1);
	}
	soap_end (&soap);
	soap_done (&soap);
	return (0);
}
示例#9
0
文件: lrc_ifce.c 项目: ic-hep/emi3
lrc_guid_exists (const char *guid, char *errbuf, int errbufsz)
{
	struct lrc__guidExistsResponse out;
	int ret;
	struct soap soap;

	if (lrc_init (&soap, errbuf, errbufsz) < 0)
		return (-1);

	if ((ret = soap_call_lrc__guidExists (&soap, lrc_endpoint, "",
				(char *) guid, &out))) {
		gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "%s", soap.fault->faultstring);
		soap_end (&soap);
		soap_done (&soap);	
		errno = ECOMM;
		return (-1);
	}
	ret = out._guidExistsReturn ? 1 : 0;
	soap_end (&soap);
	soap_done (&soap);
	return (ret);
}
示例#10
0
char *
lcg_compute_checksum (const char *file, enum gfal_cksm_type cksmtype, char *errbuf, int errbufsz)
{
	unsigned long cksm = 0;
	EVP_MD_CTX evpctx;
	int fd = -1;
	unsigned int nbread = 0;
	char buffer[GFAL_CKSM_BUFSIZE];
	char checksum[2 * EVP_MAX_MD_SIZE + 1];
	unsigned char cksm_raw[EVP_MAX_MD_SIZE + 1];
	int cksmsize = 0;

	if (file == NULL || cksmtype == GFAL_CKSM_NONE) {
		gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "[LCG-UTIL][compute_checksum][] Invalid arguments");
		errno = EINVAL;
		return (NULL);
	}

	memset (checksum, 0, (2 * EVP_MAX_MD_SIZE + 1) * sizeof (char));

	if (cksmtype == GFAL_CKSM_CRC32 || cksmtype == GFAL_CKSM_ADLER32) {
		zlib_handle = dlopen ("libz.so", RTLD_LAZY);
		if (zlib_handle == NULL) {
			gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "[LCG-UTIL][compute_checksum][] CRC32/ADLER32 need zlib!");
			errno = ELIBACC;
			return (NULL);
		}

		zlib_crc32 = (unsigned long (*) (unsigned long, const char *, unsigned int)) dlsym (zlib_handle, "crc32");
		zlib_adler32 = (unsigned long (*) (unsigned long, const char *, unsigned int)) dlsym (zlib_handle, "adler32");
		if (zlib_crc32 == NULL || zlib_adler32 == NULL) {
			gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "[LCG-UTIL][compute_checksum][] invalid zlib library!");
			errno = ELIBBAD;
			return (NULL);
		}
	}

	fd = gfal_open (file, O_RDONLY, 0);
	if (fd < 0)
		return (NULL);

	if (cksmtype == GFAL_CKSM_ADLER32)
		cksm = zlib_adler32 (0L, 0, 0);
	else if (cksmtype == GFAL_CKSM_CRC32)
		cksm = zlib_crc32 (0L, 0, 0);
	else {
		if (cksmtype == GFAL_CKSM_MD5)
			EVP_DigestInit (&evpctx, EVP_md5());
		else
			EVP_DigestInit (&evpctx, EVP_sha1());
	}

	while ((nbread = (unsigned int) gfal_read (fd, buffer, GFAL_CKSM_BUFSIZE)) > 0) {
		if (cksmtype == GFAL_CKSM_ADLER32)
			cksm = zlib_adler32 (cksm, buffer, nbread);
		else if (cksmtype == GFAL_CKSM_CRC32)
			cksm = zlib_crc32 (cksm, buffer, nbread);
		else
			EVP_DigestUpdate(&evpctx, buffer, (size_t) nbread);
	}

	gfal_close (fd);

	if (nbread < 0)
		return (NULL);

	if (cksmtype == GFAL_CKSM_ADLER32 || cksmtype == GFAL_CKSM_CRC32) {
		sprintf(checksum, "%08x", (unsigned int) cksm);
	} else {
		char *p;
		int i;

		EVP_DigestFinal (&evpctx, cksm_raw, &cksmsize);

		for (i = 0, p = checksum; i < cksmsize; ++i, p = p + 2)
			sprintf(p, "%02x", cksm_raw[i]);
	}

	return (strdup (checksum));
}
示例#11
0
int
check_surls (int nbsurls, char **surls, char *errbuf, int errbufsz) {
	char *p1 = NULL, *p2 = NULL;
	char beginning[GFAL_PATH_MAXLEN];
	int i, len;

	beginning[0] = 0;

	if (nbsurls < 1 || surls == NULL) {
		gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "You must specify SURLs");
		errno = EINVAL;
		return (-1);
	}

	for (i = 0; i < nbsurls; ++i) {
		if ((p1 = strchr (surls[i], ':')) == NULL) {
			gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "%s: Invalid SURL", surls[i]);
			errno = EINVAL;
			return (-1);
		}
		if (beginning[0] != 0 && strncmp (beginning, surls[i], p1 - surls[i] + 1) != 0) {
			gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "All SURLs must have the same type (lfn:, srm:, ...)");
			errno = EINVAL;
			return (-1);
		}
		if (strncmp (surls[i], "srm", p1 - surls[i]) == 0) {
			if (*(p1 + 1) != '/' || *(p1 + 2) != '/' ||
					((p2 = strchr (p1 + 3, '?')) == NULL &&
					 (p2 = strchr (p1 + 3, '/')) == NULL)) {
				gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "%s: Invalid SURL", surls[i]);
				errno = EINVAL;
				return (-1);
			}
			if (beginning[0] != 0) {
				int len_tmp = p2 - surls[i];

				/* The 1st SURL must have the most complete endpoint
				 * Others' endpoint can be only a part of it
				 * eg. 1. srm://lxdpm102.cern.ch:8446/srm/managerv2?SFN=/dpm/...
				 *        srm://lxdpm102.cern.ch/dpm/... */
				if (strncmp (surls[i], beginning, len_tmp) != 0 ||
						(beginning[len_tmp] != '/' &&
						 beginning[len_tmp] != ':' &&
						 beginning[len_tmp] != '?')) {
					gfal_errmsg (errbuf, errbufsz, GFAL_ERRLEVEL_ERROR, "All SURLs must be from the same SE endpoint");
					errno = EINVAL;
					return (-1);
				}
			}
			else {
				len = p2 - surls[i] + 1;
				snprintf (beginning, len + 1, "%s", surls[i]);
			}
		}
		else { /* for lfn:, guid:, sfn:, gsiftp:, file:, ... */
			if (beginning[0] == 0) {
				len = p1 - surls[i] + 1;
				snprintf (beginning, len + 1, "%s", surls[i]);
			}
		}
	}

	return (0);
}