Exemplo n.º 1
0
int DLL_DECL
dpm_ping(char *host, char *info)
{
	int c;
	char func[16];
	gid_t gid;
	int msglen;
	char *q;
	char *rbp;
	char repbuf[256];
	char *sbp;
	char sendbuf[REQBUFSZ];
	struct dpm_api_thread_info *thip;
	uid_t uid;

	strcpy (func, "dpm_ping");
	if (dpm_apiinit (&thip))
		return (-1);
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		dpm_errmsg (func, DP053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

	if (! info) {
		serrno = EFAULT;
		return (-1);
	}

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, DPM_MAGIC);
	marshall_LONG (sbp, DPM_PING);
	q = sbp;	/* save pointer. The next field will be updated */
	msglen = 3 * LONGSIZE;
	marshall_LONG (sbp, msglen);

	/* Build request body */

	marshall_LONG (sbp, uid);
	marshall_LONG (sbp, gid);

	msglen = sbp - sendbuf;
	marshall_LONG (q, msglen);	/* update length field */

	c = send2dpm (host, sendbuf, msglen, repbuf, sizeof(repbuf), NULL, NULL);

	if (c == 0) {
		rbp = repbuf;
		unmarshall_STRING (rbp, info);
	}
	return (c);
}
Exemplo n.º 2
0
int DLL_DECL
dpm_put (int nbreqfiles, struct dpm_putfilereq *reqfiles, int nbprotocols, char **protocols, char *u_token, int overwrite, time_t retrytime, char *r_token, int *nbreplies, struct dpm_putfilestatus **filestatuses)
{
	int c;
	char errstring[256];
	char func[16];
	gid_t gid;
	int i;
	int msglen;
	char *rbp;
	char repbuf[4+256+CA_MAXDPMTOKENLEN+1];
	char *sbp;
	char *sendbuf;
	char surl[CA_MAXSFNLEN+1];
	struct dpm_api_thread_info *thip;
	uid_t uid;

	strcpy (func, "dpm_put");
	if (dpm_apiinit (&thip))
		return (-1);
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		dpm_errmsg (func, DP053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

	if (nbreqfiles <= 0 || nbprotocols <= 0) {
		serrno = EINVAL;
		return (-1);
	}
	if (! reqfiles || ! protocols || ! r_token || ! nbreplies || ! filestatuses) {
		serrno = EFAULT;
		return (-1);
	}

	/* Compute size of send buffer */

	msglen = 6 * LONGSIZE;
	for (i = 0; i < nbprotocols; i++)
		msglen += strlen (protocols[i]) + 1;
	if (u_token)
		msglen += strlen (u_token) + 1;
	else
		msglen++;
	msglen += LONGSIZE;
	msglen += TIME_TSIZE;
	msglen += LONGSIZE;
	for (i = 0; i < nbreqfiles; i++) {
		msglen += strlen ((reqfiles+i)->to_surl) + 1;
		msglen += TIME_TSIZE;
		msglen++;
		msglen += strlen ((reqfiles+i)->s_token) + 1;
		msglen += HYPERSIZE;
		msglen += TIME_TSIZE;
		msglen++;
		msglen++;
	}

	/* Allocate send buffer */

	if ((sendbuf = malloc (msglen)) == NULL) {
		serrno = ENOMEM;
		return (-1);
	}

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, DPM_MAGIC2);
	marshall_LONG (sbp, DPM_PUT);
	marshall_LONG (sbp, msglen);

	/* Build request body */

	marshall_LONG (sbp, uid);
	marshall_LONG (sbp, gid);
	marshall_LONG (sbp, nbprotocols);
	for (i = 0; i < nbprotocols; i++)
		marshall_STRING (sbp, protocols[i]);
	if (u_token) {
		marshall_STRING (sbp, u_token);
	} else {
		marshall_STRING (sbp, "");
	}
	marshall_LONG (sbp, overwrite);
	marshall_TIME_T (sbp, retrytime);
	marshall_LONG (sbp, nbreqfiles);
	for (i = 0; i < nbreqfiles; i++) {
		marshall_STRING (sbp, (reqfiles+i)->to_surl);
		marshall_TIME_T (sbp, (reqfiles+i)->lifetime);
		marshall_BYTE (sbp, (reqfiles+i)->f_type);
		marshall_STRING (sbp, (reqfiles+i)->s_token);
		marshall_HYPER (sbp, (reqfiles+i)->requested_size);
		marshall_TIME_T (sbp, (reqfiles+i)->f_lifetime);
		marshall_BYTE (sbp, (reqfiles+i)->ret_policy);
		marshall_BYTE (sbp, (reqfiles+i)->ac_latency);
	}
	c = send2dpm (NULL, sendbuf, msglen, repbuf, sizeof(repbuf),
	    (void **)filestatuses, nbreplies);
	free (sendbuf);

	if (c == 0) {
		rbp = repbuf;
		unmarshall_LONG (rbp, c);
		if ((c & 0xF000) == DPM_FAILED) {
			serrno = c - DPM_FAILED;
			c = -1;
		}
		unmarshall_STRING (rbp, errstring);
		if (*errstring)
			dpm_errmsg (func, "%s\n", errstring);
		unmarshall_STRING (rbp, r_token);
	}
	return (c);
}
Exemplo n.º 3
0
int DLL_DECL
dpm_getreqsummary (int nbtokens, char **r_tokens, int *nbreplies, struct dpm_reqsummary **summaries)
{
	int c;
	char errstring[256];
	char func[18];
	gid_t gid;
	int i;
	int msglen;
	char *rbp;
	char repbuf[4+256];
	char *sbp;
	char *sendbuf;
	struct dpm_api_thread_info *thip;
	uid_t uid;

	strcpy (func, "dpm_getreqsummary");
	if (dpm_apiinit (&thip))
		return (-1);
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		dpm_errmsg (func, DP053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

	if (nbtokens <= 0) {
		serrno = EINVAL;
		return (-1);
	}
	if (! r_tokens || ! nbreplies || ! summaries) {
		serrno = EFAULT;
		return (-1);
	}

	/* Compute size of send buffer */

	msglen = 6 * LONGSIZE;
	for (i = 0; i < nbtokens; i++) {
		msglen += strlen (r_tokens[i]) + 1;
	}

	/* Allocate send buffer */

	if ((sendbuf = malloc (msglen)) == NULL) {
		serrno = ENOMEM;
		return (-1);
	}

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, DPM_MAGIC);
	marshall_LONG (sbp, DPM_GETREQSUM);
	marshall_LONG (sbp, msglen);

	/* Build request body */

	marshall_LONG (sbp, uid);
	marshall_LONG (sbp, gid);
	marshall_LONG (sbp, nbtokens);
	for (i = 0; i < nbtokens; i++) {
		marshall_STRING (sbp, r_tokens[i]);
	}

	c = send2dpm (NULL, sendbuf, msglen, repbuf, sizeof(repbuf),
	    (void **)summaries, nbreplies);
	free (sendbuf);
	if (c == 0) { 
		rbp = repbuf;
		unmarshall_LONG (rbp, c);
		if (c) {
			serrno = c - DPM_FAILED;
			c = -1;
		}
		unmarshall_STRING (rbp, errstring);
		if (*errstring)
			dpm_errmsg (func, "%s\n", errstring);
	}
	return (c);
}
Exemplo n.º 4
0
int DLL_DECL
dpm_modifypool(struct dpm_pool *dpm_pool)
{
	int c;
	char func[16];
	gid_t gid;
	int i;
	int msglen;
	char *p;
	char *q;
	char *sbp;
	char sendbuf[REQBUFSZ];
	struct dpm_api_thread_info *thip;
	uid_t uid;

	strcpy (func, "dpm_modifypool");
	if (dpm_apiinit (&thip))
		return (-1);
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		dpm_errmsg (func, DP053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

	if (! dpm_pool) {
		serrno = EFAULT;
		return (-1);
	}

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, DPM_MAGIC3);
	marshall_LONG (sbp, DPM_MODPOOL);
	q = sbp;	/* save pointer. The next field will be updated */
	msglen = 3 * LONGSIZE;
	marshall_LONG (sbp, msglen);

	/* Build request body */

	marshall_LONG (sbp, uid);
	marshall_LONG (sbp, gid);
	marshall_STRING (sbp, dpm_pool->poolname);
	marshall_HYPER (sbp, dpm_pool->defsize);
	marshall_LONG (sbp, dpm_pool->gc_start_thresh);
	marshall_LONG (sbp, dpm_pool->gc_stop_thresh);
	marshall_LONG (sbp, dpm_pool->defpintime);
	marshall_STRING (sbp, dpm_pool->fss_policy);
	marshall_STRING (sbp, dpm_pool->gc_policy);
	marshall_STRING (sbp, dpm_pool->rs_policy);
	marshall_LONG (sbp, dpm_pool->nbgids > 0 ? dpm_pool->gids[0] : -1);
	marshall_BYTE (sbp, dpm_pool->s_type);
	marshall_STRING (sbp, dpm_pool->mig_policy);
	marshall_BYTE (sbp, dpm_pool->ret_policy);
	marshall_LONG (sbp, dpm_pool->def_lifetime);
	marshall_LONG (sbp, dpm_pool->max_lifetime);
	marshall_LONG (sbp, dpm_pool->maxpintime);
	marshall_LONG (sbp, dpm_pool->nbgids);
	for (i = 0; i < dpm_pool->nbgids; i++)
		marshall_LONG (sbp, dpm_pool->gids[i]);

	msglen = sbp - sendbuf;
	marshall_LONG (q, msglen);	/* update length field */

	c = send2dpm (NULL, sendbuf, msglen, NULL, 0, NULL, NULL);
	return (c);
}