Пример #1
0
int DLL_DECL
Cns_deleteclass(char *server, int classid, char *class_name)
{
	int c;
	char func[16];
	gid_t gid;
	int msglen;
	char *q;
	char *sbp;
	char sendbuf[REQBUFSZ];
	struct Cns_api_thread_info *thip;
	uid_t uid;

	strcpy (func, "Cns_deleteclass");
	if (Cns_apiinit (&thip))
		return (-1);
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		Cns_errmsg (func, NS053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, CNS_MAGIC);
	marshall_LONG (sbp, CNS_DELCLASS);
	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_LONG (sbp, classid);
	if (class_name) {
		marshall_STRING (sbp, class_name);
	} else {
		marshall_STRING (sbp, "");
	}

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

	c = send2nsd (NULL, server, sendbuf, msglen, NULL, 0);

	if (c && serrno == SENAMETOOLONG) serrno = ENAMETOOLONG;
	return (c);
}
Пример #2
0
int DLL_DECL
Cns_getusrbynam(char *username, uid_t *uid)
{
	int c;
	char func[16];
	int msglen;
	int n;
	char *q;
	char *rbp;
	char repbuf[256];
	char *sbp;
	char sendbuf[REQBUFSZ];
	struct Cns_api_thread_info *thip;

	strcpy (func, "Cns_getusrbynam");
	if (Cns_apiinit (&thip))
		return (-1);

	if (! username || ! uid) {
		serrno = EFAULT;
		return (-1);
	}

	/* Build request header */

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

	/* Build request body */

	marshall_STRING (sbp, username);

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

	c = send2nsd (NULL, NULL, sendbuf, msglen, repbuf, sizeof(repbuf));

	if (c == 0) {
		rbp = repbuf;
		unmarshall_LONG (rbp, n);
		*uid = n;
	}
	return (c);
}
Пример #3
0
int DLL_DECL
Cns_setrtype(const char *sfn, const char type)
{
	int c;
	char func[16];
	gid_t gid;
	int msglen;
	char *q;
	char *sbp;
	char sendbuf[REQBUFSZ];
	struct Cns_api_thread_info *thip;
	uid_t uid;
	u_signed64 zero = 0;
 
	strcpy (func, "Cns_setrtype");
	if (Cns_apiinit (&thip))
		return (-1);
	uid = getuid();
	gid = getgid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		Cns_errmsg (func, NS053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

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

	if (strlen (sfn) > CA_MAXSFNLEN) {
		serrno = ENAMETOOLONG;
		return (-1);
	}

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, CNS_MAGIC);
	marshall_LONG (sbp, CNS_SETRTYPE);
	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, sfn);
	marshall_BYTE (sbp, type);

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

	c = send2nsd (NULL, NULL, sendbuf, msglen, NULL, 0);

	if (c && serrno == SENAMETOOLONG) serrno = ENAMETOOLONG;
	return (c);
}
Пример #4
0
sendrep(int rpfd, int rep_type, ...)
{
	va_list args;
	char func[16];
	char *msg;
	int n;
	char *p;
	char prtbuf[PRTBUFSZ];
	char *q;
	char *rbp;
	int rc;
	char repbuf[REPBUFSZ+12];
	int repsize;

	strcpy (func, "sendrep");
	rbp = repbuf;
	marshall_LONG (rbp, CNS_MAGIC2);
	va_start (args, rep_type);
	marshall_LONG (rbp, rep_type);
	switch (rep_type) {
	case MSG_ERR:
		msg = va_arg (args, char *);
		vsprintf (prtbuf, msg, args);
		marshall_LONG (rbp, strlen (prtbuf) + 1);
		marshall_STRING (rbp, prtbuf);
		nslogit (func, "%s", prtbuf);
		break;
	case MSG_DATA:
	case MSG_LINKS:
	case MSG_REPLIC:
	case MSG_REPLICP:
	case MSG_REPLICX:
	case MSG_REPLICS:
	case MSG_GROUPS:
	case MSG_STATUSES:
	case MSG_FILEST:
	case MSG_GRPINFO:
	case MSG_USRINFO:
		n = va_arg (args, int);
		marshall_LONG (rbp, n);
		msg = va_arg (args, char *);
		memcpy (rbp, msg, n);	/* marshalling already done */
		rbp += n;
		break;
	case CNS_IRC:
	case CNS_RC:
		rc = va_arg (args, int);
		marshall_LONG (rbp, rc);
		break;
	}
	va_end (args);
	repsize = rbp - repbuf;
	if (netwrite (rpfd, repbuf, repsize) != repsize) {
		nslogit (func, NS002, "send", neterror());
		if (rep_type == CNS_RC)
			netclose (rpfd);
		return (-1);
	}
	if (rep_type == CNS_RC)
		netclose (rpfd);
	return (0);
}
Пример #5
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);
}
Пример #6
0
int DLL_DECL
dpm_abortreq (char *r_token)
{
	int c;
	char errstring[256];
	char func[16];
	gid_t gid;
	int msglen;
	char *q;
	char *rbp;
	char repbuf[4+256];
	char *sbp;
	char sendbuf[REQBUFSZ];
	struct dpm_api_thread_info *thip;
	uid_t uid;

	strcpy (func, "dpm_abortreq");
	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 (! r_token) {
		serrno = EFAULT;
		return (-1);
	}

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, DPM_MAGIC);
	marshall_LONG (sbp, DPM_ABORTREQ);
	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, r_token);

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

	c = send2dpm (NULL, sendbuf, msglen, repbuf, sizeof(repbuf), NULL, NULL);
	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);
}
Пример #7
0
int DLL_DECL
Cns_setacl(const char *path, int nentries, struct Cns_acl *acl)
{
	char *actual_path;
	int c;
	char func[16];
	gid_t gid;
	int i;
	int msglen;
	char *q;
	char *sbp;
	char sendbuf[REQBUFSZ];
	char server[CA_MAXHOSTNAMELEN+1];
	struct Cns_api_thread_info *thip;
	uid_t uid;
 
	strcpy (func, "Cns_setacl");
	if (Cns_apiinit (&thip))
		return (-1);
	uid = getuid();
	gid = getgid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		Cns_errmsg (func, NS053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

	if (! path || ! acl) {
		serrno = EFAULT;
		return (-1);
	}

	if (strlen (path) > CA_MAXPATHLEN) {
		serrno = ENAMETOOLONG;
		return (-1);
	}
	if (nentries <= 0 || nentries > CA_MAXACLENTRIES) {
		serrno = EINVAL;
		return (-1);
	}

	if (Cns_selectsrvr (path, thip->server, server, &actual_path))
		return (-1);

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, CNS_MAGIC);
	marshall_LONG (sbp, CNS_SETACL);
	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_HYPER (sbp, thip->cwd);
	marshall_STRING (sbp, actual_path);
	marshall_WORD (sbp, nentries);
	for (i = 0; i < nentries; i++) {
		marshall_BYTE (sbp, acl->a_type);
		marshall_LONG (sbp, acl->a_id);
		marshall_BYTE (sbp, acl->a_perm);
		acl++;
	}

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

	c = send2nsd (NULL, server, sendbuf, msglen, NULL, 0);

	if (c && serrno == SENAMETOOLONG) serrno = ENAMETOOLONG;
	return (c);
}
Пример #8
0
int DLL_DECL
Cns_getidmapc (const char *username, const char *user_ca, int nbgroups, const char **groupnames, uid_t *userid, gid_t *gids)
{
	int c;
	char func[16];
	int i;
	int msglen;
	int n;
	char *q;
	char *rbp;
	char repbuf[REPBUFSZ];
	char *sbp;
	char *sendbuf;
	struct Cns_api_thread_info *thip;

	strcpy (func, "Cns_getidmap");
	if (Cns_apiinit (&thip))
		return (-1);

	if (! username || ! userid || ! gids) {
		serrno = EFAULT;
		return (-1);
	}
	if (nbgroups < 0) {
		serrno = EINVAL;
		return (-1);
	}

	/* Compute size of send buffer */

	msglen = 3 * LONGSIZE;
	msglen += strlen (username) + 1;
	msglen += LONGSIZE;
	if (groupnames) {
		for (i = 0; i < nbgroups; i++)
			msglen += strlen (groupnames[i]) + 1;
	}
	if (user_ca)
		msglen += strlen (user_ca) + 1;
	else
		msglen++;

	/* Allocate send buffer */

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

	/* Build request header */

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

	/* Build request body */

	marshall_STRING (sbp, username);
	marshall_LONG (sbp, nbgroups);
	if (groupnames) {
		for (i = 0; i < nbgroups; i++) {
			marshall_STRING (sbp, groupnames[i]);
		}
	}
	if (user_ca) {
		marshall_STRING (sbp, user_ca);
	} else {
		marshall_STRING (sbp, "");
	}

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

	c = send2nsd (NULL, NULL, sendbuf, msglen, repbuf, sizeof(repbuf));
	free (sendbuf);

	if (c == 0) {
		rbp = repbuf;
		unmarshall_LONG (rbp, n);
		*userid = n;
		if (nbgroups == 0)
			nbgroups = 1;
		for (i = 0; i < nbgroups; i++) {
			unmarshall_LONG (rbp, n);
			*(gids+i) = n;
		}
	}
	return (c);
}
Пример #9
0
struct Cns_linkinfo *
Cns_listlinks(const char *path, const char *guid, int flags, Cns_list *listp)
{
	char *actual_path;
	int bol = 0;
	int c;
	char func[16];
	gid_t gid;
	int listentsz = sizeof(struct Cns_linkinfo);
	struct Cns_linkinfo *lp;
	int msglen;
	int nbentries;
	char *p;
	char *q;
	char *rbp;
	char repbuf[LISTBUFSZ+4];
	char *sbp;
	char sendbuf[REQBUFSZ];
	char server[CA_MAXHOSTNAMELEN+1];
	struct Cns_api_thread_info *thip;
	uid_t uid;

	strcpy (func, "Cns_listlinks");
	if (Cns_apiinit (&thip))
		return (NULL);
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		Cns_errmsg (func, NS053);
		serrno = SENOMAPFND;
		return (NULL);
	}
#endif

	if ((! path && ! guid) || ! listp) {
		serrno = EFAULT;
		return (NULL);
	}

	if ((path && strlen (path) > CA_MAXPATHLEN) ||
	    (guid && strlen (guid) > CA_MAXGUIDLEN)) {
		serrno = ENAMETOOLONG;
		return (NULL);
	}

	if (path && Cns_selectsrvr (path, thip->server, server, &actual_path))
		return (NULL);

	if (flags == CNS_LIST_BEGIN) {
		memset (listp, 0, sizeof(Cns_list));
		listp->fd = -1;
		if ((listp->buf = malloc (LISTBUFSZ)) == NULL) {
			serrno = ENOMEM;
			return (NULL);
		}
		bol = 1;
	}
	if (listp->len == 0 && listp->eol	/* all entries have been listed */
	    && flags != CNS_LIST_END)
		return (NULL);

	if (listp->buf == NULL)
		return (NULL);			/* buffer has already been freed */
	if (listp->len == 0	/* no data in the cache */
	    || flags == CNS_LIST_END) {

		/* Build request header */

		sbp = sendbuf;
		marshall_LONG (sbp, CNS_MAGIC);
		if (flags == CNS_LIST_END) {
			marshall_LONG (sbp, CNS_ENDLIST);
		} else {
			marshall_LONG (sbp, CNS_LISTLINKS);
		}
		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_WORD (sbp, listentsz);
		marshall_HYPER (sbp, thip->cwd);
		if (path) {
			marshall_STRING (sbp, actual_path);
		} else {
			marshall_STRING (sbp, "");
		}
		if (guid) {
			marshall_STRING (sbp, guid);
		} else {
			marshall_STRING (sbp, "");
		}
		marshall_WORD (sbp, bol);
	 
		msglen = sbp - sendbuf;
		marshall_LONG (q, msglen);	/* update length field */

		c = send2nsd (&listp->fd, path ? server : NULL, sendbuf,
		    msglen, repbuf, sizeof(repbuf));

		if (c < 0 || flags == CNS_LIST_END) {
			if (listp->buf)
				free (listp->buf);
			listp->buf = NULL;
			return (NULL);
		}
		rbp = repbuf;
		unmarshall_WORD (rbp, nbentries);
		if (nbentries == 0)
			return (NULL);		/* end of list */

		/* unmarshall reply into Cns_linkinfo structures */

		lp = (struct Cns_linkinfo *) listp->buf;
		while (nbentries--) {
			unmarshall_STRING (rbp, lp->path);
			lp++;
		}
		unmarshall_WORD (rbp, listp->eol);
		listp->len = (char *) lp - listp->buf;
	}
	lp = (struct Cns_linkinfo *) (listp->buf + listp->offset);
	listp->offset += sizeof(struct Cns_linkinfo);
	if (listp->offset >= listp->len) {	/* must refill next time */
		listp->offset = 0;
		listp->len = 0;
	}
	return (lp);
}
Пример #10
0
int DLL_DECL
Cns_modreplicax(const char *sfn, const char *setname, const char *poolname, const char *server, const char *fs, const char r_type)
{
	int c;
	int extended = 0;
	char func[16];
	gid_t gid;
	int msglen;
	char *q;
	char *sbp;
	char sendbuf[REQBUFSZ];
	struct Cns_api_thread_info *thip;
	uid_t uid;
	u_signed64 zero = 0;
 
	strcpy (func, "Cns_modreplica");
	if (Cns_apiinit (&thip))
		return (-1);
	uid = getuid();
	gid = getgid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		Cns_errmsg (func, NS053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

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

	if (strlen (sfn) > CA_MAXSFNLEN) {
		serrno = ENAMETOOLONG;
		return (-1);
	}
	if ((setname && strlen (setname) > 36) ||
	    (poolname && strlen (poolname) > CA_MAXPOOLNAMELEN) ||
	    (server && strlen (server) > CA_MAXHOSTNAMELEN)) {
		serrno = EINVAL;
		return (-1);
	}

	/* Build request header */

	if (r_type || (fs && strlen (fs) > 0))
		extended = 1;

	sbp = sendbuf;
	marshall_LONG (sbp, CNS_MAGIC);
	marshall_LONG (sbp, (extended ? CNS_MODREPLICAX : CNS_MODREPLICA));
	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, sfn);
	if (setname) {
		marshall_STRING (sbp, setname);
	} else {
		marshall_STRING (sbp, "");
	}
	if (poolname) {
		marshall_STRING (sbp, poolname);
	} else {
		marshall_STRING (sbp, "");
	}
	if (server) {
		marshall_STRING (sbp, server);
	} else {
		marshall_STRING (sbp, "");
	}
	if (extended) {
		if (fs) {
			marshall_STRING (sbp, fs);
		} else {
			marshall_STRING (sbp, "");
		}
		marshall_BYTE (sbp, r_type);
	}

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

	c = send2nsd (NULL, NULL, sendbuf, msglen, NULL, 0);

	if (c && serrno == SENAMETOOLONG) serrno = ENAMETOOLONG;
	return (c);
}
Пример #11
0
int DLL_DECL
Cns_du(const char *path, int Lflag, u_signed64 *nbbytes, u_signed64 *nbentries)
{
	char *actual_path;
	int c;
	char func[16];
	gid_t gid;
	int msglen;
	u_signed64 n;
	char *q;
	char *rbp;
	char repbuf[16];
	char *sbp;
	char sendbuf[REQBUFSZ];
	char server[CA_MAXHOSTNAMELEN+1];
	struct Cns_api_thread_info *thip;
	uid_t uid;
 
	strcpy (func, "Cns_du");
	if (Cns_apiinit (&thip))
		return (-1);
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		Cns_errmsg (func, NS053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

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

	if (strlen (path) > CA_MAXPATHLEN) {
		serrno = ENAMETOOLONG;
		return (-1);
	}

	if (Cns_selectsrvr (path, thip->server, server, &actual_path))
		return (-1);

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, CNS_MAGIC);
	marshall_LONG (sbp, CNS_DU);
	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_HYPER (sbp, thip->cwd);
	marshall_STRING (sbp, actual_path);
	marshall_WORD (sbp, Lflag);

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

	c = send2nsd (NULL, server, sendbuf, msglen, repbuf, sizeof(repbuf));

	if (c == 0) {
		rbp = repbuf;
		unmarshall_HYPER (rbp, n);
		if (nbbytes)
			*nbbytes = n;
		unmarshall_HYPER (rbp, n);
		if (nbentries)
			*nbentries = n;
	}
	if (c && serrno == SENAMETOOLONG) serrno = ENAMETOOLONG;
	return (c);
}
Пример #12
0
int DLL_DECL
Cns_delfilesbyguid(int nbguids, const char **guids, int force, int *nbstatuses, int **statuses)
{
	int argtype = 0;
	int c;
	char func[19];
	gid_t gid;
	int i;
	int msglen;
	char *q;
	char *rbp;
	char repbuf[4];
	char *sbp;
	char *sendbuf;
	struct Cns_api_thread_info *thip;
	uid_t uid;

	strcpy (func, "Cns_delfilesbyguid");
	if (Cns_apiinit (&thip))
		return (-1);
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		Cns_errmsg (func, NS053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

	if (nbguids <= 0) {
		serrno = EINVAL;
		return (-1);
	}
	if (! guids || ! nbstatuses || ! statuses) {
		serrno = EFAULT;
		return (-1);
	}

	/* Compute size of send buffer */

	msglen = 5 * LONGSIZE;
	msglen += WORDSIZE;
	msglen += WORDSIZE;
	msglen += LONGSIZE;
	for (i = 0; i < nbguids; i++) {
		msglen += strlen (guids[i]) + 1;
	}

	/* Allocate send buffer */

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

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, CNS_MAGIC);
	marshall_LONG (sbp, CNS_DELFILES);
	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_WORD (sbp, argtype);
	marshall_WORD (sbp, force);
	marshall_LONG (sbp, nbguids);
	for (i = 0; i < nbguids; i++) {
		marshall_STRING (sbp, guids[i]);
	}
 
	msglen = sbp - sendbuf;
	marshall_LONG (q, msglen);	/* update length field */

	c = send2nsdx (NULL, NULL, sendbuf,
	    msglen, repbuf, sizeof(repbuf), (void **)statuses, nbstatuses);
	free (sendbuf);

	if (c == 0) {
		rbp = repbuf;
		unmarshall_LONG (rbp, *nbstatuses);
		if (*nbstatuses == 0) {
			*statuses = NULL;
			return (0);
		}
	}
	return (c);
}
Пример #13
0
int DLL_DECL
Cns_statr(const char *sfn, struct Cns_filestatg *statbuf)
{
	int c, n;
	char func[16];
	gid_t gid;
	int msglen;
	char *q;
	char *rbp;
	char repbuf[132];
	char *sbp;
	char sendbuf[REQBUFSZ];
	struct Cns_api_thread_info *thip;
	uid_t uid;
 
	strcpy (func, "Cns_statr");
	if (Cns_apiinit (&thip))
		return (-1);
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		Cns_errmsg (func, NS053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

	if (! sfn || ! statbuf) {
		serrno = EFAULT;
		return (-1);
	}

	if (strlen (sfn) > CA_MAXSFNLEN) {
		serrno = ENAMETOOLONG;
		return (-1);
	}

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, CNS_MAGIC);
	marshall_LONG (sbp, CNS_STATR);
	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, sfn);

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

	c = send2nsd (NULL, NULL, sendbuf, msglen, repbuf, sizeof(repbuf));

	if (c == 0) {
		rbp = repbuf;
		unmarshall_HYPER (rbp, statbuf->fileid);
		unmarshall_STRING (rbp, statbuf->guid);
		unmarshall_WORD (rbp, statbuf->filemode);
		unmarshall_LONG (rbp, statbuf->nlink);
		unmarshall_LONG (rbp, statbuf->uid);
		unmarshall_LONG (rbp, statbuf->gid);
		unmarshall_HYPER (rbp, statbuf->filesize);
		unmarshall_TIME_T (rbp, statbuf->atime);
		unmarshall_TIME_T (rbp, statbuf->mtime);
		unmarshall_TIME_T (rbp, statbuf->ctime);
		unmarshall_WORD (rbp, statbuf->fileclass);
		unmarshall_BYTE (rbp, statbuf->status);
		unmarshall_STRING (rbp, statbuf->csumtype);
		unmarshall_STRING (rbp, statbuf->csumvalue);
	}
	if (c && serrno == SENAMETOOLONG) serrno = ENAMETOOLONG;
	return (c);
}
Пример #14
0
int DLL_DECL
Cns_lstat(const char *path, struct Cns_filestat *statbuf)
{
	char *actual_path;
	int c, n;
	char func[16];
	gid_t gid;
	int msglen;
	char *q;
	char *rbp;
	char repbuf[57];
	char *sbp;
	char sendbuf[REQBUFSZ];
	char server[CA_MAXHOSTNAMELEN+1];
	struct Cns_api_thread_info *thip;
	uid_t uid;
	u_signed64 zero = 0;
 
	strcpy (func, "Cns_lstat");
	if (Cns_apiinit (&thip))
		return (-1);
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		Cns_errmsg (func, NS053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

	if (! path || ! statbuf) {
		serrno = EFAULT;
		return (-1);
	}

	if (strlen (path) > CA_MAXPATHLEN) {
		serrno = ENAMETOOLONG;
		return (-1);
	}

	if (Cns_selectsrvr (path, thip->server, server, &actual_path))
		return (-1);

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, CNS_MAGIC2);
	marshall_LONG (sbp, CNS_LSTAT);
	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_HYPER (sbp, thip->cwd);
	marshall_HYPER (sbp, zero);
	marshall_STRING (sbp, actual_path);

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

	c = send2nsd (NULL, server, sendbuf, msglen, repbuf, sizeof(repbuf));

	if (c == 0) {
		rbp = repbuf;
		unmarshall_HYPER (rbp, statbuf->fileid);
		unmarshall_WORD (rbp, statbuf->filemode);
		unmarshall_LONG (rbp, statbuf->nlink);
		unmarshall_LONG (rbp, statbuf->uid);
		unmarshall_LONG (rbp, statbuf->gid);
		unmarshall_HYPER (rbp, statbuf->filesize);
		unmarshall_TIME_T (rbp, statbuf->atime);
		unmarshall_TIME_T (rbp, statbuf->mtime);
		unmarshall_TIME_T (rbp, statbuf->ctime);
		unmarshall_WORD (rbp, statbuf->fileclass);
		unmarshall_BYTE (rbp, statbuf->status);
	}
	if (c && serrno == SENAMETOOLONG) serrno = ENAMETOOLONG;
	return (c);
}
Пример #15
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);
}
Пример #16
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);
}
Пример #17
0
struct Cns_direnrep DLL_DECL *
Cns_readdirxr(Cns_DIR *dirp, char *se)
{
	int c;
	int direntsz;
	struct Cns_direnrep *dp;
	char func[16];
	int getattr = 5;
	gid_t gid;
	int i;
	struct Cns_rep_info *ir;
	int msglen;
	int n;
	int nbentries;
	char *q;
	char *rbp;
	struct Cns_rep_info *rep_entries;
	char repbuf[DIRBUFSZ+4];
	char *sbp;
	char sendbuf[REQBUFSZ];
	uid_t uid;
 
	strcpy (func, "Cns_readdirxr");
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		Cns_errmsg (func, NS053);
		serrno = SENOMAPFND;
		return (NULL);
	}
#endif

	if (! dirp) {
		serrno = EFAULT;
		return (NULL);
	}
	if (se && strlen (se) > CA_MAXHOSTNAMELEN) {
		serrno = EINVAL;
		return (NULL);
	}
	/* compute size of client machine Cns_direnrep structure excluding d_name */

	dp = (struct Cns_direnrep *) dirp->dd_buf;
	direntsz = &dp->d_name[0] - (char *) dp;

	if (dirp->dd_size == 0) {	/* no data in the cache */
		if (dirp->replicas) {	/* free previous replica information */
			ir = (struct Cns_rep_info *) dirp->replicas;
			for (i = 0; i < dirp->nbreplicas; i++) {
				free (ir->host);
				free (ir->sfn);
				ir++;
			}
			free (dirp->replicas);
			dirp->nbreplicas = 0;
			dirp->replicas = NULL;
		}
		if (dirp->eod)
			return (NULL);

		/* Build request header */

		sbp = sendbuf;
		marshall_LONG (sbp, CNS_MAGIC);
		marshall_LONG (sbp, CNS_READDIR);
		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_WORD (sbp, getattr);
		marshall_WORD (sbp, direntsz);
		marshall_HYPER (sbp, dirp->fileid);
		marshall_WORD (sbp, dirp->bod);
		if (se) {
			marshall_STRING (sbp, se);
		} else {
			marshall_STRING (sbp, "");
		}

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

		c = send2nsdx (&dirp->dd_fd, NULL, sendbuf, msglen,
		    repbuf, sizeof(repbuf), (void **) &dirp->replicas,
		    &dirp->nbreplicas);

		if (c < 0)
			return (NULL);
		rbp = repbuf;
		unmarshall_WORD (rbp, nbentries);
		if (nbentries == 0)
			return (NULL);		/* end of directory */

		/* unmarshall reply into the Cns_direnrep structures */

		dp = (struct Cns_direnrep *) dirp->dd_buf;
		i = 0;
		rep_entries = (struct Cns_rep_info *) dirp->replicas;
		while (nbentries--) {
			unmarshall_HYPER (rbp, dp->fileid);
			unmarshall_STRING (rbp, dp->guid);
			unmarshall_WORD (rbp, dp->filemode);
			unmarshall_HYPER (rbp, dp->filesize);
			dp->nbreplicas = 0;
			dp->rep = NULL;
			for ( ; i < dirp->nbreplicas; i++) {
				if (dp->fileid != (rep_entries+i)->fileid) break;
				dp->nbreplicas++;
				if (dp->nbreplicas == 1)
					dp->rep = rep_entries + i;
			}
			unmarshall_STRING (rbp, dp->d_name);
			dp->d_reclen = ((direntsz + strlen (dp->d_name) + 8) / 8) * 8;
			dp = (struct Cns_direnrep *) ((char *) dp + dp->d_reclen);
		}
		dirp->bod = 0;
		unmarshall_WORD (rbp, dirp->eod);
		dirp->dd_size = (char *) dp - dirp->dd_buf;
	}
	dp = (struct Cns_direnrep *) (dirp->dd_buf + dirp->dd_loc);
	dirp->dd_loc += dp->d_reclen;
	if (dirp->dd_loc >= dirp->dd_size) {	/* must refill next time */
		dirp->dd_loc = 0;
		dirp->dd_size = 0;
	}
	return (dp);
}
Пример #18
0
int DLL_DECL
Cns_registerfiles(int nbfiles, struct Cns_filereg *files, int *nbstatuses, int **statuses)
{
	int c;
	char func[18];
	gid_t gid;
	int i;
	int msglen;
	char *q;
	char *rbp;
	char repbuf[4];
	char *sbp;
	char *sendbuf;
	struct Cns_api_thread_info *thip;
	uid_t uid;

	strcpy (func, "Cns_registerfiles");
	if (Cns_apiinit (&thip))
		return (-1);
	uid = geteuid();
	gid = getegid();
#if defined(_WIN32)
	if (uid < 0 || gid < 0) {
		Cns_errmsg (func, NS053);
		serrno = SENOMAPFND;
		return (-1);
	}
#endif

	if (nbfiles <= 0) {
		serrno = EINVAL;
		return (-1);
	}
	if (! files || ! nbstatuses || ! statuses) {
		serrno = EFAULT;
		return (-1);
	}

	/* Compute size of send buffer */

	msglen = 5 * LONGSIZE;
	msglen += WORDSIZE;
	msglen += HYPERSIZE;
	msglen += LONGSIZE;
	for (i = 0; i < nbfiles; i++) {
		msglen += strlen ((files+i)->lfn) + 1;
		if ((files+i)->guid) {
			msglen += strlen ((files+i)->guid) + 1;
		} else {
			msglen++;
		}
		msglen += LONGSIZE;
		msglen += HYPERSIZE;
		if ((files+i)->csumtype) {
			msglen += strlen ((files+i)->csumtype) + 1;
		} else {
			msglen++;
		}
		if ((files+i)->csumvalue) {
			msglen += strlen ((files+i)->csumvalue) + 1;
		} else {
			msglen++;
		}
		msglen += strlen ((files+i)->server) + 1;
		msglen += strlen ((files+i)->sfn) + 1;
	}

	/* Allocate send buffer */

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

	/* Build request header */

	sbp = sendbuf;
	marshall_LONG (sbp, CNS_MAGIC);
	marshall_LONG (sbp, CNS_REGFILES);
	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_WORD (sbp, thip->mask);
	marshall_HYPER (sbp, thip->cwd);
	marshall_LONG (sbp, nbfiles);
	for (i = 0; i < nbfiles; i++) {
		marshall_STRING (sbp, (files+i)->lfn);
		if ((files+i)->guid) {
			marshall_STRING (sbp, (files+i)->guid);
		} else {
			marshall_STRING (sbp, "");
		}
		marshall_LONG (sbp, (files+i)->mode);
		marshall_HYPER (sbp, (files+i)->size);
		if ((files+i)->guid) {
			marshall_STRING (sbp, (files+i)->csumtype);
		} else {
			marshall_STRING (sbp, "");
		}
		if ((files+i)->guid) {
			marshall_STRING (sbp, (files+i)->csumvalue);
		} else {
			marshall_STRING (sbp, "");
		}
		marshall_STRING (sbp, (files+i)->server);
		marshall_STRING (sbp, (files+i)->sfn);
	}
 
	msglen = sbp - sendbuf;
	marshall_LONG (q, msglen);	/* update length field */

	c = send2nsdx (NULL, NULL, sendbuf,
	    msglen, repbuf, sizeof(repbuf), (void **)statuses, nbstatuses);
	free (sendbuf);

	if (c == 0) {
		rbp = repbuf;
		unmarshall_LONG (rbp, *nbstatuses);
		if (*nbstatuses == 0) {
			*statuses = NULL;
			return (0);
		}
	}
	return (c);
}