From patchwork Sat Nov 3 12:50:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1692281 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 3F9A7DFB7B for ; Sat, 3 Nov 2012 12:50:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932146Ab2KCMuu (ORCPT ); Sat, 3 Nov 2012 08:50:50 -0400 Received: from mail-yh0-f46.google.com ([209.85.213.46]:44234 "EHLO mail-yh0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932075Ab2KCMuu (ORCPT ); Sat, 3 Nov 2012 08:50:50 -0400 Received: by mail-yh0-f46.google.com with SMTP id m54so749191yhm.19 for ; Sat, 03 Nov 2012 05:50:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=5GcicbvRto7BMquq/lGqLrHrpnMQww04pnzlMCEdWiA=; b=BvJ+IVh4kDZhWkaCD61QCIZQs4VeBmLJOGrW7qnkrE2fu/XsQfEbZz7mCO6GBdU2wc q74AzD1j/lpRwQkfIyAYt6vpDqmsCK4sRC1P991R7ynIXZyuZPABbhgLRKP8vGQl9Cn3 IwcoM99ptzlH0strcXA5xKGfuMBliA25HdoOYBZpWvHecyVkMPdUHbbUKSSkw7acSofh n7xT+tgJ3sBQOv2Xy1GTuQQiV7f6gZ0sqMG5uyxrhgJMho1tT6mCMk/EV3gPoC3GChT9 mkRBxzVY6pVwA+8QUT/cYIL1+2+JJVMGzcPtecKefNBBJg+Bu+W8BDxtlNQUDpKb6d26 vKrA== Received: by 10.236.59.98 with SMTP id r62mr4305042yhc.130.1351947049550; Sat, 03 Nov 2012 05:50:49 -0700 (PDT) Received: from salusa.poochiereds.net (cpe-107-015-110-129.nc.res.rr.com. [107.15.110.129]) by mx.google.com with ESMTPS id n13sm11145727ano.20.2012.11.03.05.50.48 (version=SSLv3 cipher=OTHER); Sat, 03 Nov 2012 05:50:48 -0700 (PDT) From: Jeff Layton To: linux-cifs@vger.kernel.org Cc: shirishpargaonkar@gmail.com Subject: [PATCH 06/17] setcifsacl: fix up getopt() usage Date: Sat, 3 Nov 2012 08:50:23 -0400 Message-Id: <1351947034-18876-7-git-send-email-jlayton@samba.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1351947034-18876-1-git-send-email-jlayton@samba.org> References: <1351947034-18876-1-git-send-email-jlayton@samba.org> X-Gm-Message-State: ALoCoQnwUfV1QSSfhpO6SasVIeGgPP6EXPalRcPydNukttYuIHQErTkjWSOZuLl4QJF+PH1FQX2N Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org '?' has a special meaning in getopt(). It means that the option character was not recognized. You can override that behavior by making ':' the first character of the optstring, but that wasn't done here. I'm not sure what the effect of having '?' in the actual optstring is in this case, but it's probably best not to put it in there. Remove '?' from the optstring and replace it 'h'. Also add '-h' as a valid option to the manpage. '-v' doesn't require an argument, so fix the optstring to reflect that. Finally declare a new variable to hold optarg. Currently we only call getopt() once, which is a little odd. Eventually we may want to make it call it more than once, in which case we'll need some way to store the optarg on each pass. Signed-off-by: Jeff Layton --- setcifsacl.1 | 4 ++++ setcifsacl.c | 25 +++++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/setcifsacl.1 b/setcifsacl.1 index 550d23d..3dd755c 100644 --- a/setcifsacl.1 +++ b/setcifsacl.1 @@ -30,6 +30,10 @@ This tool is part of the cifs-utils suite\&. setcifsacl is a userspace helper program for the Linux CIFS client file system. It is intended to alter an ACL of a security descriptor for a file system object. It is best utilized when an option of cifsacl is specified when mounting a cifs share in conjunction with winbind facility of Samba suite. Whether a security descriptor to be set is applied or not is determined by the CIFS/SMB server. .SH "OPTIONS" .PP +-h +.RS 4 +Print usage message and exit. +.RE \-v .RS 4 Print version number and exit\&. diff --git a/setcifsacl.c b/setcifsacl.c index 71b065c..4c09345 100644 --- a/setcifsacl.c +++ b/setcifsacl.c @@ -779,7 +779,7 @@ main(const int argc, char *const argv[]) int i, rc, c, numcaces, numfaces; enum setcifsacl_actions maction = ActUnknown; ssize_t attrlen, bufsize = BUFSIZE; - char *filename, *attrval, **arrptr = NULL; + char *ace_list, *filename, *attrval, **arrptr = NULL; struct cifs_ctrl_acl *daclptr = NULL; struct cifs_ace **cacesptr = NULL, **facesptr = NULL; struct cifs_ntsd *ntsdptr = NULL; @@ -788,43 +788,49 @@ main(const int argc, char *const argv[]) openlog(prog, 0, LOG_DAEMON); - c = getopt(argc, argv, "v:D:M:a:S:?"); + c = getopt(argc, argv, "hvD:M:a:S:"); switch (c) { - case 'v': - printf("Version: %s\n", VERSION); - goto out; case 'D': maction = ActDelete; + ace_list = optarg; break; case 'M': maction = ActModify; + ace_list = optarg; break; case 'a': maction = ActAdd; + ace_list = optarg; break; case 'S': maction = ActSet; + ace_list = optarg; break; - case '?': + case 'h': setcifsacl_usage(); return 0; + case 'v': + printf("Version: %s\n", VERSION); + return 0; default: - break; + setcifsacl_usage(); + return -1; } + /* We expect 1 argument in addition to the option */ if (argc != 4) { setcifsacl_usage(); return -1; } filename = argv[3]; - numcaces = get_numcaces(optarg); + numcaces = get_numcaces(ace_list); if (!numcaces) { printf("%s: No valid ACEs specified\n", __func__); return -1; } - arrptr = parse_cmdline_aces(optarg, numcaces); + arrptr = parse_cmdline_aces(ace_list, numcaces); if (!arrptr) goto setcifsacl_numcaces_ret; @@ -878,7 +884,6 @@ cifsacl: printf("%s: setxattr error: %s\n", __func__, strerror(errno)); goto setcifsacl_facenum_ret; -out: return 0; setcifsacl_action_ret: