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); }
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); }
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); }
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); }