X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Fl_getidentity.c;h=6f8dff6af43a7d69a116f85c394c0c3928a1e268;hb=ccabce23bd9e366c345c852f565766a799f61238;hp=94956437bf67825be3927cb9fddd68e3e6937f2f;hpb=59a59cc9d33f94fb857129b255ad42f393d7242e;p=fs%2Flustre-release.git diff --git a/lustre/utils/l_getidentity.c b/lustre/utils/l_getidentity.c index 9495643..6f8dff6 100644 --- a/lustre/utils/l_getidentity.c +++ b/lustre/utils/l_getidentity.c @@ -15,11 +15,7 @@ * * You should have received a copy of the GNU General Public License * version 2 along with this program; If not, see - * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf - * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * http://www.gnu.org/licenses/gpl-2.0.html * * GPL HEADER END */ @@ -27,13 +23,14 @@ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2011, 2014, Intel Corporation. + * Copyright (c) 2011, 2016, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ * Lustre is a trademark of Sun Microsystems, Inc. */ +#include #include #include #include @@ -48,11 +45,11 @@ #include #include +#include #include -#include -#include -#include -#include +#include +#include +#include #define PERM_PATHNAME "/etc/lustre/perm.conf" @@ -63,8 +60,8 @@ * '*' nid means any nid * '*' uid means any uid * the valid values for perms are: - * setuid/setgid/setgrp/rmtacl -- enable corresponding perm - * nosetuid/nosetgid/nosetgrp/normtacl -- disable corresponding perm + * setuid/setgid/setgrp -- enable corresponding perm + * nosetuid/nosetgid/nosetgrp -- disable corresponding perm * they can be listed together, separated by ',', * when perm and noperm are in the same line (item), noperm is preferential, * when they are in different lines (items), the latter is preferential, @@ -75,11 +72,12 @@ static char *progname; static void usage(void) { - fprintf(stderr, - "\nusage: %s {mdtname} {uid}\n" - "Normally invoked as an upcall from Lustre, set via:\n" - "/proc/fs/lustre/mdt/${mdtname}/identity_upcall\n", - progname); + fprintf(stderr, + "\nusage: %s {-d|mdtname} {uid}\n" + "Normally invoked as an upcall from Lustre, set via:\n" + "lctl set_param mdt.${mdtname}.identity_upcall={path to upcall}\n" + "\t-d: debug, print values to stdout instead of Lustre\n", + progname); } static int compare_u32(const void *v1, const void *v2) @@ -89,15 +87,15 @@ static int compare_u32(const void *v1, const void *v2) static void errlog(const char *fmt, ...) { - va_list args; + va_list args; - openlog(progname, LOG_PERROR | LOG_PID, LOG_AUTHPRIV); + openlog(progname, LOG_PERROR | LOG_PID, LOG_AUTHPRIV); - va_start(args, fmt); - vsyslog(LOG_NOTICE, fmt, args); - va_end(args); + va_start(args, fmt); + vsyslog(LOG_WARNING, fmt, args); + va_end(args); - closelog(); + closelog(); } int get_groups_local(struct identity_downcall_data *data, @@ -199,21 +197,21 @@ typedef struct { } perm_type_t; static perm_type_t perm_types[] = { - { "setuid", CFS_SETUID_PERM }, - { "setgid", CFS_SETGID_PERM }, - { "setgrp", CFS_SETGRP_PERM }, - { "rmtacl", CFS_RMTACL_PERM }, - { "rmtown", CFS_RMTOWN_PERM }, - { 0 } + { "setuid", CFS_SETUID_PERM }, + { "setgid", CFS_SETGID_PERM }, + { "setgrp", CFS_SETGRP_PERM }, + { "rmtacl", 0 }, + { "rmtown", 0 }, + { 0 } }; static perm_type_t noperm_types[] = { - { "nosetuid", CFS_SETUID_PERM }, - { "nosetgid", CFS_SETGID_PERM }, - { "nosetgrp", CFS_SETGRP_PERM }, - { "normtacl", CFS_RMTACL_PERM }, - { "normtown", CFS_RMTOWN_PERM }, - { 0 } + { "nosetuid", CFS_SETUID_PERM }, + { "nosetgid", CFS_SETGID_PERM }, + { "nosetgrp", CFS_SETGRP_PERM }, + { "normtacl", 0 }, + { "normtown", 0 }, + { 0 } }; int parse_perm(__u32 *perm, __u32 *noperm, char *str) @@ -412,18 +410,19 @@ static void show_result(struct identity_downcall_data *data) pdd = &data->idd_perms[i]; - printf(" "LPX64"\t0x%x\n", pdd->pdd_nid, pdd->pdd_perm); + printf(" %#jx\t0x%x\n", (uintmax_t)pdd->pdd_nid, + pdd->pdd_perm); } printf("\n"); } int main(int argc, char **argv) { - char *end; - struct identity_downcall_data *data = NULL; - char procname[1024]; - unsigned long uid; - int fd, rc = -EINVAL, size, maxgroups; + char *end; + struct identity_downcall_data *data = NULL; + glob_t path; + unsigned long uid; + int fd, rc = -EINVAL, size, maxgroups; progname = basename(argv[0]); if (argc != 3) { @@ -467,32 +466,39 @@ int main(int argc, char **argv) rc = get_perms(data); downcall: - if (getenv("L_GETIDENTITY_TEST")) { - show_result(data); - rc = 0; - goto out; - } + if (strcmp(argv[1], "-d") == 0 || getenv("L_GETIDENTITY_TEST")) { + show_result(data); + rc = 0; + goto out; + } - snprintf(procname, sizeof(procname), - "/proc/fs/lustre/mdt/%s/identity_info", argv[1]); - fd = open(procname, O_WRONLY); - if (fd < 0) { - errlog("can't open file %s: %s\n", procname, strerror(errno)); - rc = -1; - goto out; - } + rc = cfs_get_param_paths(&path, "mdt/%s/identity_info", argv[1]); + if (rc != 0) { + rc = -errno; + goto out; + } - rc = write(fd, data, size); - close(fd); - if (rc != size) { - errlog("partial write ret %d: %s\n", rc, strerror(errno)); - rc = -1; - } else { - rc = 0; - } + fd = open(path.gl_pathv[0], O_WRONLY); + if (fd < 0) { + errlog("can't open file '%s':%s\n", path.gl_pathv[0], + strerror(errno)); + rc = -errno; + goto out_params; + } + + rc = write(fd, data, size); + close(fd); + if (rc != size) { + errlog("partial write ret %d: %s\n", rc, strerror(errno)); + rc = -1; + } else { + rc = 0; + } +out_params: + cfs_free_param_data(&path); out: - if (data != NULL) - free(data); - return rc; + if (data != NULL) + free(data); + return rc; }