From patchwork Mon Dec 2 20:33:36 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 296005 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "aserp1040.oracle.com", Issuer "VeriSign Class 3 International Server CA - G3" (not verified)) by ozlabs.org (Postfix) with ESMTPS id BACF12C0087 for ; Tue, 3 Dec 2013 07:33:49 +1100 (EST) Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id rB2KXkM3020304 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 2 Dec 2013 20:33:47 GMT Received: from oss.oracle.com (oss-external.oracle.com [137.254.96.51]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rB2KXk0Z029810 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 2 Dec 2013 20:33:46 GMT Received: from localhost ([127.0.0.1] helo=oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1VnaBe-00060h-Bm; Mon, 02 Dec 2013 12:33:46 -0800 Received: from ucsinet21.oracle.com ([156.151.31.93]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1VnaBY-00060L-5w for fedfs-utils-devel@oss.oracle.com; Mon, 02 Dec 2013 12:33:40 -0800 Received: from aserp1030.oracle.com (aserp1030.oracle.com [141.146.126.68]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rB2KXdPu013281 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 2 Dec 2013 20:33:39 GMT Received: from mail-yh0-f54.google.com (mail-yh0-f54.google.com [209.85.213.54]) by aserp1030.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id rB2KXcK3018183 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 2 Dec 2013 20:33:38 GMT Received: by mail-yh0-f54.google.com with SMTP id z12so9419322yhz.27 for ; Mon, 02 Dec 2013 12:33:38 -0800 (PST) X-Received: by 10.236.141.132 with SMTP id g4mr2868764yhj.93.1386016418019; Mon, 02 Dec 2013 12:33:38 -0800 (PST) Received: from seurat.1015granger.net ([2604:8800:100:81fc:20c:29ff:fe44:ec31]) by mx.google.com with ESMTPSA id 48sm128069260yhq.11.2013.12.02.12.33.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Dec 2013 12:33:37 -0800 (PST) To: fedfs-utils-devel@oss.oracle.com From: Chuck Lever Date: Mon, 02 Dec 2013 15:33:36 -0500 Message-ID: <20131202203336.12541.89623.stgit@seurat.1015granger.net> In-Reply-To: <20131202201953.12541.27594.stgit@seurat.1015granger.net> References: <20131202201953.12541.27594.stgit@seurat.1015granger.net> User-Agent: StGit/0.16 MIME-Version: 1.0 X-Flow-Control-Info: class=Pass-to-MM reputation=ipRisk-All ip=209.85.213.54 ct-class=R5 ct-vol1=-88 ct-vol2=7 ct-vol3=7 ct-risk=50 ct-spam1=82 ct-spam2=7 ct-bulk=2 rcpts=1 size=23215 X-SPF-Info: PASS::mail-yh0-f54.google.com X-Sendmail-CM-Score: 0.00% X-Sendmail-CM-Analysis: v=2.1 cv=FfAOmvO6 c=1 sm=1 tr=0 a=zMVyw9OtciA3IUMQIpAzJg==:117 a=dzsqy3y4QnMA:10 a=jdl61F8rEf8A:10 a=dPGociXpb70A:10 a=IkcTkHD0fZMA:10 a=xqWC_Br6kY4A:10 a=yPCof4ZbAAAA:8 a=Lb1rMZzfAAAA:8 a=1XWaLZrsAAAA:8 a=bNy60hIhuCoA:10 a=OK-8mIdLAAAA: 8 a=c1g2R9Z3nzZk9YNM138A:9 a=6v0ZqzCL_cahDi7a:21 a=cguEzdrXjkKu7QmY:21 a=QEXdDO2ut3YA:10 a=nvz6EU7xhngA:10 a=7DSvI1NPTFQA:10 X-Sendmail-CT-Classification: not spam X-Sendmail-CT-RefID: str=0001.0A090205.529CEEA3.0003, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-MIME-Autoconverted: from 8bit to quoted-printable by ucsinet21.oracle.com id rB2KXdPu013281 Subject: [fedfs-utils] [PATCH 09/11] fedfsc: Convert fedfs-lookup-replication to use new libadmin API X-BeenThere: fedfs-utils-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list Reply-To: fedfs-utils Developers List-Id: fedfs-utils Developers List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: fedfs-utils-devel-bounces@oss.oracle.com Errors-To: fedfs-utils-devel-bounces@oss.oracle.com X-Source-IP: acsinet21.oracle.com [141.146.126.237] Signed-off-by: Chuck Lever --- doc/man/fedfs-lookup-replication.8 | 167 +++----------- src/fedfsc/fedfs-lookup-replication.c | 401 +++++++++++++-------------------- 2 files changed, 200 insertions(+), 368 deletions(-) diff --git a/doc/man/fedfs-lookup-replication.8 b/doc/man/fedfs-lookup-replication.8 index bb3c38f..898fdbc 100644 --- a/doc/man/fedfs-lookup-replication.8 +++ b/doc/man/fedfs-lookup-replication.8 @@ -5,7 +5,7 @@ .\" .\" -.\" Copyright 2011 Oracle. All rights reserved. +.\" Copyright 2011, 2013 Oracle. All rights reserved. .\" .\" This file is part of fedfs-utils. .\" @@ -33,6 +33,8 @@ fedfs-lookup-replication \- send a FEDFS_LOOKUP_REPLICATION ADMIN protocol reque .IR nettype ] .RB [ \-h .IR hostname ] +.RB [ \-s +.IR security ] .RB [ \-t .IR resolvetype ] .I path @@ -143,132 +145,21 @@ are The value is not case-sensitive. If this option is not specified, the default value is .BR none . -.SH EXIT CODES -The remote administration service returns a value that reflects the -success of the requested operation. -.TP -.B FEDFS_OK -The operation succeeded. -.TP -.B FEDFS_ERR_ACCESS -The caller does not have permission to perform the requested operation -on the remote server. -.TP -.B FEDFS_ERR_BADCHAR -The pathname contains a character which is not -supported by the remote server. -.TP -.B FEDFS_ERR_BADNAME -A component of the pathname consisted of valid UTF-8 characters -supported by the remote server, -but the name is not supported by the remote server -as a valid name for the current operation. -.TP -.B FEDFS_ERR_NAMETOOLONG -The length of the pathname exceeds the remote server’s implementation limit. -.TP -.B FEDFS_ERR_LOOP -Too many symbolic links were encountered in resolving the pathname. -.TP -.B FEDFS_ERR_BADXDR -The remote server encountered an XDR decoding error while -processing the request. -.TP -.B FEDFS_ERR_INVAL -One of the arguments was not valid. -.TP -.B FEDFS_ERR_IO -A hard error occurred on the remote server. -.TP -.B FEDFS_ERR_NOTJUNCT -The pathname does not end in a replication. -.TP -.B FEDFS_ERR_NOTLOCAL -The pathname contains a junction in any position other than the last component. -.TP -.B FEDFS_ERR_PERM -The operation was not allowed because the caller is -either not a privileged user or not the owner of an object that -would be modified by the operation. -.TP -.B FEDFS_ERR_SVRFAULT -An unanticipated non-protocol error occurred on the remote server. -.TP -.B FEDFS_ERR_NSDB_ROUTE -The remote server was unable to find a route to the NSDB. -.TP -.B FEDFS_ERR_NSDB_DOWN -The remote server determined that the NSDB was down. -.TP -.B FEDFS_ERR_NSDB_CONN -The remote server was unable to establish a connection with the NSDB. -.TP -.B FEDFS_ERR_NSDB_AUTH -The remote server was unable to authenticate -and establish a secure connection with the NSDB. -.TP -.B FEDFS_ERR_NSDB_LDAP -An LDAP error occurred on the connection between the remote server and NSDB. -.TP -.B FEDFS_ERR_NSDB_LDAP_VAL -Indicates the same error as FEDFS_ERR_NSDB_LDAP, -and allows an LDAP protocol error value to be returned to the client. -.TP -.B FEDFS_ERR_NSDB_NONCE -The remote server was unable to locate the NCE in the appropriate NSDB. -.TP -.B FEDFS_ERR_NSDB_NOFSN -The remote server was unable to locate the given FSN in the appropriate NSDB. -.TP -.B FEDFS_ERR_NSDB_NOFSL -The remote server was unable to locate any FSLs for the given FSN -in the appropriate NSDB. -.TP -.B FEDFS_ERR_NSDB_RESPONSE -The remote server received a malformed response from the NSDB. -This includes situations when an NSDB entry (e.g. FSN or FSL) -is missing a required attribute. -.TP -.B FEDFS_ERR_NSDB_FAULT -An unanticipated error related to the NSDB occurred. -.TP -.B FEDFS_ERR_NSDB_PARAMS -The remote server does not have any connection -parameters on record for the specified NSDB. -.TP -.B FEDFS_ERR_NSDB_LDAP_REFERRAL -The remote server received an LDAP referral that it was unable to follow. -.TP -.B FEDFS_ERR_NSDB_LDAP_REFERRAL_VAL -Indicates the same error as FEDFS_ERR_NSDB_LDAP_REFERRAL, -and allows an LDAP protocol error value to be returned back to the client. -.TP -.B FEDFS_ERR_NSDB_LDAP_REFERRAL_NOTFOLLOWED -The remote server received an LDAP referral that it chose not to follow, -either because the remote server does not support following LDAP referrals -or LDAP referral following is disabled. -.TP -.B FEDFS_ERR_NSDB_PARAMS_LDAP_REFERRAL -The remote server received an LDAP referral that it chose not to follow -because the remote server had no NSDB parameters for the NSDB -targeted by the LDAP referral. -.TP -.B FEDFS_ERR_PATH_TYPE_UNSUPP -The remote server does not support the specified FedFsPathType value. -.TP -.B FEDFS_ERR_NOTSUPP -The remote server does not support the specified procedure. -.TP -.B FEDFS_ERR_NO_CACHE -The remote server does not implement an FSN-to-FSL cache. -.TP -.B FEDFS_ERR_UNKNOWN_CACHE -The software receiving the ONC RPC request is unaware if the remote server -implements an FSN-to-FSL cache or unable to communicate with the -local FSN-to-FSL cache if it exists. -.TP -.B FEDFS_ERR_NO_CACHE_UPDATE -The remote server was unable to update its FSN-to-FSL cache. +.IP "\fB\-s, \-\-security=\fIflavor\fP" +Specifies the security flavor to use +when contacting the remote FedFS ADMIN service. +Valid flavors are +.BR sys , +.BR unix , +.BR krb5 , +.BR krb5i ", and" +.BR krb5p . +If this option is not specified, the +.B unix +flavor is used. +See the +.B SECURITY +section of this man page for details. .SH EXAMPLES Suppose you are the FedFS administrator of the .I example.net @@ -301,10 +192,30 @@ but the domain's NSDB has not yet been updated to contain a list of fileset locations for the UUID contained in the replication marker. The file server is therefore not able to resolve the replication. .SH SECURITY -RPCSEC GSSAPI authentication has not yet been implemented for this command. +By default, or if the +.B sys +and +.B unix +flavors are specified with the +.BI \-\-security= flavor +option, the +.BR fedfs-create-junction (8) +command uses AUTH_SYS security for the Remote Procedure Call. +AUTH_SYS has known weaknesses and should be avoided on untrusted networks. +.P +The RPC client uses the Kerberos v5 GSS mechanism +if a Kerberos security flavor is specified. +When specifying a Kerberos security flavor, +the user must first obtain a valid Kerberos ticket using +.BR kinit (1) +before running +.BR fedfs-create-junction (8). +.P +The AUTH_NONE security flavor is no longer supported by this implementation. .SH "SEE ALSO" .BR fedfs (7), .BR rpc.fedfsd (8), +.BR kinit (1), .BR rpc (3t) .sp RFC 5716 for FedFS requirements and overview diff --git a/src/fedfsc/fedfs-lookup-replication.c b/src/fedfsc/fedfs-lookup-replication.c index a845b32..bfa04e3 100644 --- a/src/fedfsc/fedfs-lookup-replication.c +++ b/src/fedfsc/fedfs-lookup-replication.c @@ -4,7 +4,7 @@ */ /* - * Copyright 2010 Oracle. All rights reserved. + * Copyright 2010, 2013 Oracle. All rights reserved. * * This file is part of fedfs-utils. * @@ -27,32 +27,27 @@ #include #include +#include #include #include #include #include #include -#include -#include #include #include "fedfs.h" #include "fedfs_admin.h" +#include "admin.h" #include "nsdb.h" #include "junction.h" #include "xlog.h" #include "gpl-boiler.h" /** - * Default RPC request timeout - */ -static struct timeval fedfs_lookup_replication_timeout = { 25, 0 }; - -/** * Short form command line options */ -static const char fedfs_lookup_replication_opts[] = "?dh:n:t:"; +static const char fedfs_lookup_replication_opts[] = "?dh:n:t:s:"; /** * Long form command line options @@ -63,6 +58,7 @@ static const struct option fedfs_lookup_replication_longopts[] = { { "hostname", 1, NULL, 'h', }, { "nettype", 1, NULL, 'n', }, { "resolvetype", 1, NULL, 't', }, + { "security", 1, NULL, 's', }, { NULL, 0, NULL, 0, }, }; @@ -70,8 +66,9 @@ static const struct option fedfs_lookup_replication_longopts[] = { * Display program synopsis * * @param progname NUL-terminated C string containing name of program + * @return program exit status */ -static void +static int fedfs_lookup_replication_usage(const char *progname) { fprintf(stderr, "\n%s version " VERSION "\n", progname); @@ -83,269 +80,171 @@ fedfs_lookup_replication_usage(const char *progname) fprintf(stderr, "\t-n, --nettype RPC transport (default: 'netpath')\n"); fprintf(stderr, "\t-h, --hostname ADMIN server hostname (default: 'localhost')\n"); fprintf(stderr, "\t-t, --resolvetype Type of desired result (default: 'none')\n"); + fprintf(stderr, "\t-s, --security RPC security level\n"); fprintf(stderr, "%s", fedfs_gpl_boilerplate); - exit((int)FEDFS_ERR_INVAL); + return EXIT_FAILURE; } /** - * Parse name of resolvetype to resolvetype number - * - * @param resolvetype NUL-terminated C string containing name of requested resolvetype - * @param resolve OUT: resolvetype number - * @return true if "resolvetype" is a valid resolvetype - */ -static _Bool -fedfs_lookup_replication_get_resolvetype(const char *resolvetype, FedFsResolveType *resolve) -{ - if (strcmp(resolvetype, "0") == 0 || - strcasecmp(resolvetype, "none") == 0 || - strcasecmp(resolvetype, "fedfs_resolve_none") == 0) { - *resolve = FEDFS_RESOLVE_NONE; - return true; - } - if (strcmp(resolvetype, "1") == 0 || - strcasecmp(resolvetype, "cache") == 0 || - strcasecmp(resolvetype, "fedfs_resolve_cache") == 0) { - *resolve = FEDFS_RESOLVE_CACHE; - return true; - } - if (strcmp(resolvetype, "2") == 0 || - strcasecmp(resolvetype, "nsdb") == 0 || - strcasecmp(resolvetype, "fedfs_resolve_nsdb") == 0) { - *resolve = FEDFS_RESOLVE_NSDB; - return true; - } - return false; -} - -/** - * Display FSN UUID information in a FEDFS_LOOKUP_REPLICATION result - * - * @param pre_text NUL-terminated C string containing prefix to display - * @param uuid UUID to display - */ -static void -fedfs_lookup_replication_print_uuid(const char *pre_text, const FedFsUuid uuid) -{ - char buf[FEDFS_UUID_STRLEN]; - uuid_t uu; - - memcpy(uu, uuid, sizeof(uu)); - uuid_unparse(uu, buf); - printf("%s: %s\n", pre_text, buf); -} - -/** - * Display FSN NSDB information in a FEDFS_LOOKUP_REPLICATION result - * - * @param pre_text NUL-terminated C string containing prefix to display - * @param nsdbname NSDB information to display - */ -static void -fedfs_lookup_replication_print_nsdbname(const char *pre_text, - const FedFsNsdbName nsdbname) -{ - if (nsdbname.hostname.utf8string_val == NULL) { - printf("%s: NSDB name was empty\n", pre_text); - return; - } - printf("%s: %.*s:%u\n", pre_text, - nsdbname.hostname.utf8string_len, - nsdbname.hostname.utf8string_val, - nsdbname.port); -} - -/** - * Display FSN information in a FEDFS_LOOKUP_REPLICATION result - * - * @param fsn FSN information to display - */ -static void -fedfs_lookup_replication_print_fsn(const FedFsFsn fsn) -{ - fedfs_lookup_replication_print_uuid("Fsn UUID", fsn.fsnUuid); - fedfs_lookup_replication_print_nsdbname("Fsn NSDB name", fsn.nsdbName); -} - -/** - * Display one NFS FSL in a FEDFS_LOOKUP_REPLICATION result + * Display one FSL in a FEDFS_LOOKUP_JUNCTION result * * @param fsl FSL record to display */ static void -fedfs_lookup_replication_print_nfs_fsl(FedFsNfsFsl fsl) +fedfs_lookup_replication_print_fsl(struct admin_fsl *fsl) { - FedFsStatus status; - char **path_array; unsigned int i; - fedfs_lookup_replication_print_uuid("Fsl UUID", fsl.fslUuid); - if (fsl.hostname.utf8string_val == NULL) - printf("FSL hostname: empty\n"); - else - printf("FSL hostname: %.*s:%u\n", - fsl.hostname.utf8string_len, - fsl.hostname.utf8string_val, - fsl.port); - status = nsdb_fedfspathname_to_path_array(fsl.path, &path_array); - if (status != FEDFS_OK) - printf("Returned NFS export pathname was invalid: %s\n", - nsdb_display_fedfsstatus(status)); - else { - if (path_array[0] == NULL) - printf(" FSL NFS pathname: /\n"); - else { - printf(" FSL NFS pathname: "); - for (i = 0; path_array[i] != NULL; i++) - printf("/%s", path_array[i]); - printf("\n"); - } + printf(" FSL UUID: %s\n", fsl->al_uuid); - nsdb_free_string_array(path_array); - } -} + printf(" FSL hostname: %s:%u\n", + fsl->al_hostname, fsl->al_port); -/** - * Display one FSL in a FEDFS_LOOKUP_REPLICATION result - * - * @param fsl FSL record to display - */ -static void -fedfs_lookup_replication_print_fsl(FedFsFsl fsl) -{ - switch (fsl.type) { - case FEDFS_NFS_FSL: - fedfs_lookup_replication_print_nfs_fsl(fsl.FedFsFsl_u. nfsFsl); - break; - default: - printf("Unsupported FSL type\n"); + if (fsl->al_pathname[0] == NULL) + printf(" FSL NFS pathname: /\n"); + else { + printf(" FSL NFS pathname: "); + for (i = 0; fsl->al_pathname[i] != NULL; i++) + printf("/%s", fsl->al_pathname[i]); + printf("\n"); } } /** - * Display results of a successful FEDFS_LOOKUP_REPLICATION request + * Display FSLs returned by a FEDFS_LOOKUP_JUNCTION request * - * @param result results to display + * @param fsl list of FSLs returned from the server */ static void -fedfs_lookup_replication_print_resok(FedFsLookupResOk result) +fedfs_lookup_replication_print_fsls(struct admin_fsl *fsl) { - unsigned int i; - - fedfs_lookup_replication_print_fsn(result.fsn); - - if (result.fsl.fsl_len == 0) { - printf("Empty FSL list\n"); + if (fsl == NULL) return; - } + printf("Returned FSLs:\n"); - for (i = 0; i <= result.fsl.fsl_len; i++) - fedfs_lookup_replication_print_fsl(result.fsl.fsl_val[i]); + while (fsl != NULL) { + fedfs_lookup_replication_print_fsl(fsl); + fsl = fsl->al_next; + } } /** - * Display results of FEDFS_LOOKUP_REPLICATION when an LDAP/NSDB failure is reported + * Look up a replication on a remote fileserver * - * @param result results to display + * @param host an initialized and opened admin_t + * @param path_array an array of NUL-terminated C strings containing pathname components + * @param request requested resolution type + * @return program exit status */ -static void -fedfs_lookup_replication_print_ldapresultcode(FedFsLookupRes result) +static int +fedfs_lookup_replication_try(admin_t host, char * const *path_array, + int request) { - int ldap_err = result.FedFsLookupRes_u.ldapResultCode; + struct admin_fsl *fsls; + struct admin_fsn *fsn; + int status, err; + + switch (request) { + case 0: + fsls = NULL; + err = admin_lookup_replication_none(host, path_array, &fsn); + break; + case 1: + err = admin_lookup_replication_cached(host, path_array, + &fsn, &fsls); + break; + case 2: + err = admin_lookup_replication_nsdb(host, path_array, + &fsn, &fsls); + break; + } - fprintf(stderr, "LDAP result code (%d): %s\n", - ldap_err, ldap_err2string(ldap_err)); -} + status = EXIT_FAILURE; + switch (err) { + case 0: + break; + case EACCES: + xlog(L_ERROR, "%s: access denied", admin_hostname(host)); + xlog(D_GENERAL, "%s", + admin_perror(host, admin_hostname(host))); + goto out; + case EIO: + xlog(L_ERROR, "%s", + admin_perror(host, admin_hostname(host))); + goto out; + default: + xlog(L_ERROR, "ADMIN client: %s", strerror(err)); + goto out; + } -/** - * Display results of FEDFS_LOOKUP_JUNCTION request - * - * @param result results to display - */ -static void -fedfs_lookup_replication_print_result(FedFsLookupRes result) -{ - nsdb_print_fedfsstatus(result.status); - switch (result.status) { + switch (admin_status(host)) { case FEDFS_OK: - fedfs_lookup_replication_print_resok(result.FedFsLookupRes_u.resok); + printf("FSN UUID: %s\n", fsn->af_uuid); + printf("NSDB: %s:%u\n", + fsn->af_nsdb.an_hostname, + fsn->af_nsdb.an_port); + admin_free_fsn(fsn); + if (request > 0) { + fedfs_lookup_replication_print_fsls(fsls); + admin_free_fsls(fsls); + } + status = EXIT_SUCCESS; break; case FEDFS_ERR_NSDB_LDAP_VAL: - fedfs_lookup_replication_print_ldapresultcode(result); + fprintf(stderr, "LDAP result code (%d): %s\n", + admin_ldaperr(host), + ldap_err2string(admin_ldaperr(host))); + case FEDFS_ERR_NSDB_PARAMS: + printf("No connection parameters found\n"); break; default: - break; + nsdb_print_fedfsstatus(admin_status(host)); } + +out: + return status; } /** - * Request a remote fileserver to resolve a replication + * Look up a replication on a remote fileserver * * @param hostname NUL-terminated UTF-8 string containing ADMIN server's hostname * @param nettype NUL-terminated C string containing nettype to use for connection - * @param path NUL-terminated C string containing remote pathname of replication to resolve - * @param resolvetype NUL-terminated C string containing name of requested resolvetype - * @return a FedFsStatus code + * @param security NUL-terminated C string containing RPC security mode + * @param path_array an array of NUL-terminated C strings containing pathname components + * @param request requested resolution type + * @return program exit status */ -static int -fedfs_lookup_replication_call(const char *hostname, const char *nettype, - const char *path, const char *resolvetype) +static FedFsStatus +fedfs_lookup_replication_host(const char *hostname, const char *nettype, + const char *security, char * const *path_array, int request) { - FedFsLookupRes result; - enum clnt_stat status; - FedFsLookupArgs arg; - char **path_array; - CLIENT *client; - - memset(&arg, 0, sizeof(arg)); - - if (!fedfs_lookup_replication_get_resolvetype(resolvetype, &arg.resolve)) - return FEDFS_ERR_INVAL; - arg.path.type = FEDFS_PATH_SYS; - result.status = nsdb_posix_to_path_array(path, &path_array); - if (result.status != FEDFS_OK) { - fprintf(stderr, "Failed to encode pathname: %s", - nsdb_display_fedfsstatus(result.status)); - return result.status; - } - result.status = nsdb_path_array_to_fedfspathname(path_array, - &arg.path.FedFsPath_u.adminPath); - if (result.status != FEDFS_OK) { - fprintf(stderr, "Failed to encode pathname: %s", - nsdb_display_fedfsstatus(result.status)); - nsdb_free_string_array(path_array); - return result.status; - } - - client = clnt_create(hostname, FEDFS_PROG, FEDFS_V1, nettype); - if (client == NULL) { - clnt_pcreateerror("Failed to create FEDFS client"); - result.status = FEDFS_ERR_SVRFAULT; - goto out; - } - - memset((char *)&result, 0, sizeof(result)); - status = clnt_call(client, FEDFS_LOOKUP_REPLICATION, - (xdrproc_t)xdr_FedFsLookupArgs, (caddr_t)&arg, - (xdrproc_t)xdr_FedFsLookupRes, (caddr_t)&result, - fedfs_lookup_replication_timeout); - if (status != RPC_SUCCESS) { - clnt_perror(client, "FEDFS_LOOKUP_REPLICATION call failed"); - result.status = FEDFS_ERR_SVRFAULT; - } else { - fedfs_lookup_replication_print_result(result); - clnt_freeres(client, - (xdrproc_t)xdr_FedFsLookupRes, - (caddr_t)&result); + admin_t host; + int status; + + status = EXIT_FAILURE; + switch (admin_create(hostname, nettype, security, &host)) { + case 0: + status = fedfs_lookup_replication_try(host, path_array, request); + admin_release(host); + break; + case EINVAL: + xlog(L_ERROR, "Failed to allocate an admin_t object"); + break; + case EACCES: + xlog(L_ERROR, "Failed to authenticate server"); + break; + case EKEYEXPIRED: + xlog(L_ERROR, "User credentials not found"); + break; + default: + xlog(L_ERROR, "%s", + admin_open_perror(admin_hostname(host))); } - (void)clnt_destroy(client); -out: - nsdb_free_fedfspathname(&arg.path.FedFsPath_u.adminPath); - nsdb_free_string_array(path_array); - return result.status; + return status; } /** @@ -358,10 +257,10 @@ out: int main(int argc, char **argv) { - char *progname, *hostname, *nettype, *path, *resolvetype; - unsigned int seconds; - FedFsStatus status; - int arg; + char *progname, *hostname, *nettype, *path, *security, *resolvetype; + int arg, status, request; + FedFsStatus retval; + char **path_array; (void)setlocale(LC_ALL, ""); (void)umask(S_IRWXO); @@ -379,6 +278,7 @@ main(int argc, char **argv) hostname = "localhost"; nettype = "netpath"; + security = "unix"; resolvetype = "none"; path = NULL; while ((arg = getopt_long(argc, argv, fedfs_lookup_replication_opts, @@ -396,34 +296,55 @@ main(int argc, char **argv) case 'p': path = optarg; break; + case 's': + security = optarg; + break; case 't': resolvetype = optarg; break; default: fprintf(stderr, "Invalid command line argument: %c\n", (char)arg); case '?': - fedfs_lookup_replication_usage(progname); + return fedfs_lookup_replication_usage(progname); } } if (argc == optind + 1) path = argv[optind]; else if (argc > optind + 1) { fprintf(stderr, "Unrecognized positional parameters\n"); - fedfs_lookup_replication_usage(progname); + return fedfs_lookup_replication_usage(progname); } else { fprintf(stderr, "No replication pathname was specified\n"); - fedfs_lookup_replication_usage(progname); + return fedfs_lookup_replication_usage(progname); } - for (seconds = FEDFS_DELAY_MIN_SECS;; seconds = fedfs_delay(seconds)) { - status = fedfs_lookup_replication_call(hostname, nettype, - path, resolvetype); - if (status != FEDFS_ERR_DELAY) - break; + if (strcmp(resolvetype, "0") == 0 || + strcasecmp(resolvetype, "none") == 0 || + strcasecmp(resolvetype, "fedfs_resolve_none") == 0) + request = 0; + else if (strcmp(resolvetype, "1") == 0 || + strcasecmp(resolvetype, "cache") == 0 || + strcasecmp(resolvetype, "fedfs_resolve_cache") == 0) + request = 1; + else if (strcmp(resolvetype, "2") == 0 || + strcasecmp(resolvetype, "nsdb") == 0 || + strcasecmp(resolvetype, "fedfs_resolve_nsdb") == 0) + request = 2; + else { + fprintf(stderr, "Unrecognized resolvetype\n"); + return EXIT_FAILURE; + } - xlog(D_GENERAL, "Delaying %u seconds...", seconds); - if (sleep(seconds) != 0) - break; + retval = nsdb_posix_to_path_array(path, &path_array); + if (retval != FEDFS_OK) { + fprintf(stderr, "Failed to encode pathname: %s", + nsdb_display_fedfsstatus(retval)); + return EXIT_FAILURE; } - return (int)status; + + status = fedfs_lookup_replication_host(hostname, nettype, + security, path_array, request); + + nsdb_free_string_array(path_array); + return status; }