From 35cd1a78428a15ee7ce587e28c3c03e8df2b5568 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Mon, 24 Oct 2016 10:02:58 -0400 Subject: [PATCH] client: add C bindings for UserPerm constructor and destructor Signed-off-by: Jeff Layton --- src/include/cephfs/libcephfs.h | 31 +++++++++++++++++++++++++++++++ src/libcephfs.cc | 11 +++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 117e7368a254..f333937423e3 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -97,6 +97,9 @@ typedef struct vinodeno_t vinodeno; #endif /* ! __cplusplus */ +struct UserPerm; +typedef struct UserPerm UserPerm; + struct Inode; typedef struct Inode Inode; @@ -121,6 +124,34 @@ struct CephContext; # define CEPHFS_ERROR_NEW_CLIENT 1002 # define CEPHFS_ERROR_MESSENGER_START 1003 +/** + * Create a UserPerm credential object. + * + * Some calls (most notably, the ceph_ll_* ones), take a credential object + * that represents the credentials that the calling program is using. This + * function creates a new credential object for this purpose. Returns a + * pointer to the object, or NULL if it can't be allocated. + * + * Note that the gidlist array is used directly and is not copied. It must + * remain valid over the lifetime of the created UserPerm object. + * + * @param uid uid to be used + * @param gid gid to be used + * @param ngids number of gids in supplemental grouplist + * @param gidlist array of gid_t's in the list of groups + */ +UserPerm *ceph_userperm_new(uid_t uid, gid_t gid, int ngids, gid_t *gidlist); + +/** + * Destroy a UserPerm credential object. + * + * @param perm pointer to object to be destroyed + * + * Currently this just frees the object. Note that the gidlist array is not + * freed. The caller must do so if it's necessary. + */ +void ceph_userperm_destroy(UserPerm *perm); + /** * @defgroup libcephfs_h_init Setup and Teardown * These are the first and last functions that should be called diff --git a/src/libcephfs.cc b/src/libcephfs.cc index f5e31c9ccbdd..8b33968346c9 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -284,6 +284,17 @@ static void do_out_buffer(string& outbl, char **outbuf, size_t *outbuflen) *outbuflen = outbl.length(); } +extern "C" UserPerm *ceph_userperm_new(uid_t uid, gid_t gid, int ngids, + gid_t *gidlist) +{ + return new (std::nothrow) UserPerm(uid, gid, ngids, gidlist); +} + +extern "C" void ceph_userperm_destroy(UserPerm *perm) +{ + delete perm; +} + extern "C" const char *ceph_version(int *pmajor, int *pminor, int *ppatch) { int major, minor, patch; -- 2.47.3