From patchwork Thu Nov 14 17:55:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kenneth Dsouza X-Patchwork-Id: 11244093 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB52717E6 for ; Thu, 14 Nov 2019 17:56:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CB9FD20718 for ; Thu, 14 Nov 2019 17:56:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="R0MRDtUC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726474AbfKNR4D (ORCPT ); Thu, 14 Nov 2019 12:56:03 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:30905 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726473AbfKNR4C (ORCPT ); Thu, 14 Nov 2019 12:56:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573754161; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gJ2lp0m+sLZX24RNjuIddwIM1kRXXv9PEcfkabM6vJI=; b=R0MRDtUCnDJQsMj2AjcI6k5WnWcmgONu1WonAFKkLB8zLKuipBDdvc+GuwklPycudtMWe/ vS2YgTSBzBBudTqROYpsxbGmR0tl8Surg2gOWquq/j72I5A5HCUMXdvsR6sCDI+2EvO8Wu eEV+VKbe/LB9Rq9g04OLjzxovc+9C9Y= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-108-Nfv0U0KqN7qG73e73prdhQ-1; Thu, 14 Nov 2019 12:55:56 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DF826107B01D; Thu, 14 Nov 2019 17:55:55 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.76.0.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65EA860BF1; Thu, 14 Nov 2019 17:55:54 +0000 (UTC) From: Kenneth D'souza To: linux-cifs@vger.kernel.org Cc: piastryyy@gmail.com, smfrench@gmail.com, lsahlber@redhat.com Subject: [PATCH] Add program name to error output instead of static mount.cifs Date: Thu, 14 Nov 2019 23:25:51 +0530 Message-Id: <20191114175551.18805-1-kdsouza@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: Nfv0U0KqN7qG73e73prdhQ-1 X-Mimecast-Spam-Score: 0 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org As we are supporting mount.smb3 to be invoked, the error output should contain the called program and not mount.cifs Signed-off-by: Kenneth D'souza --- mount.cifs.c | 56 ++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/mount.cifs.c b/mount.cifs.c index 0ed9d0a..40918c1 100644 --- a/mount.cifs.c +++ b/mount.cifs.c @@ -194,7 +194,7 @@ struct parsed_mount_info { static const char *thisprogram; static const char *cifs_fstype; -static int parse_unc(const char *unc_name, struct parsed_mount_info *parsed_info); +static int parse_unc(const char *unc_name, struct parsed_mount_info *parsed_info, const char *progname); static int check_setuid(void) { @@ -206,7 +206,7 @@ static int check_setuid(void) #if CIFS_DISABLE_SETUID_CAPABILITY if (getuid() && !geteuid()) { - printf("This mount.cifs program has been built with the " + printf("This program has been built with the " "ability to run as a setuid root program disabled.\n"); return EX_USAGE; } @@ -301,7 +301,7 @@ static int mount_usage(FILE * stream) "\n\tbsize="); fprintf(stream, "\n\nOptions are described in more detail in the manual page"); - fprintf(stream, "\n\tman 8 mount.cifs\n"); + fprintf(stream, "\n\tman 8 %s\n", thisprogram); fprintf(stream, "\nTo display the version number of the mount helper:"); fprintf(stream, "\n\t%s -V\n", thisprogram); @@ -636,7 +636,7 @@ return_i: static int get_password_from_file(int file_descript, char *filename, - struct parsed_mount_info *parsed_info) + struct parsed_mount_info *parsed_info, const char *program) { int rc = 0; char buf[sizeof(parsed_info->password) + 1]; @@ -649,8 +649,8 @@ get_password_from_file(int file_descript, char *filename, rc = access(filename, R_OK); if (rc) { fprintf(stderr, - "mount.cifs failed: access check of %s failed: %s\n", - filename, strerror(errno)); + "%s failed: access check of %s failed: %s\n", + program, filename, strerror(errno)); toggle_dac_capability(0, 0); return EX_SYSERR; } @@ -658,8 +658,8 @@ get_password_from_file(int file_descript, char *filename, file_descript = open(filename, O_RDONLY); if (file_descript < 0) { fprintf(stderr, - "mount.cifs failed. %s attempting to open password file %s\n", - strerror(errno), filename); + "%s failed. %s attempting to open password file %s\n", + program, strerror(errno), filename); toggle_dac_capability(0, 0); return EX_SYSERR; } @@ -675,8 +675,8 @@ get_password_from_file(int file_descript, char *filename, rc = read(file_descript, buf, sizeof(buf) - 1); if (rc < 0) { fprintf(stderr, - "mount.cifs failed. Error %s reading password file\n", - strerror(errno)); + "%s failed. Error %s reading password file\n", + program, strerror(errno)); rc = EX_SYSERR; goto get_pw_exit; } @@ -923,7 +923,7 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info) "invalid path to network resource\n"); return EX_USAGE; } - rc = parse_unc(value, parsed_info); + rc = parse_unc(value, parsed_info, thisprogram); if (rc) return rc; break; @@ -1280,7 +1280,7 @@ nocopy: return 0; } -static int parse_unc(const char *unc_name, struct parsed_mount_info *parsed_info) +static int parse_unc(const char *unc_name, struct parsed_mount_info *parsed_info, const char *progname) { int length = strnlen(unc_name, MAX_UNC_LEN); const char *host, *share, *prepath; @@ -1305,26 +1305,26 @@ static int parse_unc(const char *unc_name, struct parsed_mount_info *parsed_info } if (strncmp(unc_name, "//", 2) && strncmp(unc_name, "\\\\", 2)) { - fprintf(stderr, "mount.cifs: bad UNC (%s)\n", unc_name); + fprintf(stderr, "%s: bad UNC (%s)\n", progname, unc_name); return EX_USAGE; } host = unc_name + 2; hostlen = strcspn(host, "/\\"); if (!hostlen) { - fprintf(stderr, "mount.cifs: bad UNC (%s)\n", unc_name); + fprintf(stderr, "%s: bad UNC (%s)\n", progname, unc_name); return EX_USAGE; } share = host + hostlen + 1; if (hostlen + 1 > sizeof(parsed_info->host)) { - fprintf(stderr, "mount.cifs: host portion of UNC too long\n"); + fprintf(stderr, "%s: host portion of UNC too long\n", progname); return EX_USAGE; } sharelen = strcspn(share, "/\\"); if (sharelen + 1 > sizeof(parsed_info->share)) { - fprintf(stderr, "mount.cifs: share portion of UNC too long\n"); + fprintf(stderr, "%s: share portion of UNC too long\n", progname); return EX_USAGE; } @@ -1335,7 +1335,7 @@ static int parse_unc(const char *unc_name, struct parsed_mount_info *parsed_info prepathlen = strlen(prepath); if (prepathlen + 1 > sizeof(parsed_info->prefix)) { - fprintf(stderr, "mount.cifs: UNC prefixpath too long\n"); + fprintf(stderr, "%s: UNC prefixpath too long\n", progname); return EX_USAGE; } @@ -1347,7 +1347,7 @@ static int parse_unc(const char *unc_name, struct parsed_mount_info *parsed_info return 0; } -static int get_pw_from_env(struct parsed_mount_info *parsed_info) +static int get_pw_from_env(struct parsed_mount_info *parsed_info, const char *program) { int rc = 0; @@ -1355,10 +1355,10 @@ static int get_pw_from_env(struct parsed_mount_info *parsed_info) rc = set_password(parsed_info, getenv("PASSWD")); else if (getenv("PASSWD_FD")) rc = get_password_from_file(atoi(getenv("PASSWD_FD")), NULL, - parsed_info); + parsed_info, program); else if (getenv("PASSWD_FILE")) rc = get_password_from_file(0, getenv("PASSWD_FILE"), - parsed_info); + parsed_info, program); return rc; } @@ -1408,9 +1408,9 @@ static int uppercase_string(char *string) return 1; } -static void print_cifs_mount_version(void) +static void print_cifs_mount_version(const char *progname) { - printf("mount.cifs version: %s\n", VERSION); + printf("%s version: %s\n", progname, VERSION); } /* @@ -1782,7 +1782,7 @@ assemble_mountinfo(struct parsed_mount_info *parsed_info, parsed_info->flags |= CIFS_SETUID_FLAGS; } - rc = get_pw_from_env(parsed_info); + rc = get_pw_from_env(parsed_info, thisprogram); if (rc) goto assemble_exit; @@ -1802,7 +1802,7 @@ assemble_mountinfo(struct parsed_mount_info *parsed_info, parsed_info->flags &= ~(MS_USERS | MS_USER); - rc = parse_unc(orig_dev, parsed_info); + rc = parse_unc(orig_dev, parsed_info, thisprogram); if (rc) goto assemble_exit; @@ -1987,10 +1987,10 @@ int main(int argc, char **argv) thisprogram = "mount.cifs"; if(strcmp(thisprogram, "mount.cifs") == 0) - cifs_fstype = "cifs"; + cifs_fstype = "cifs"; - if(strcmp(thisprogram, "mount.smb3") == 0) - cifs_fstype = "smb3"; + if(strcmp(thisprogram, "mount.smb3") == 0) + cifs_fstype = "smb3"; /* allocate parsed_info as shared anonymous memory range */ parsed_info = mmap((void *)0, sizeof(*parsed_info), PROT_READ | PROT_WRITE, @@ -2027,7 +2027,7 @@ int main(int argc, char **argv) ++parsed_info->verboseflag; break; case 'V': - print_cifs_mount_version(); + print_cifs_mount_version(thisprogram); exit(0); case 'w': parsed_info->flags &= ~MS_RDONLY;