From patchwork Tue Aug 7 16:33:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1287021 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id CF1C53FC23 for ; Tue, 7 Aug 2012 16:33:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752421Ab2HGQdy (ORCPT ); Tue, 7 Aug 2012 12:33:54 -0400 Received: from mail-gg0-f174.google.com ([209.85.161.174]:43229 "EHLO mail-gg0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751523Ab2HGQdx (ORCPT ); Tue, 7 Aug 2012 12:33:53 -0400 Received: by ggnl2 with SMTP id l2so3872137ggn.19 for ; Tue, 07 Aug 2012 09:33:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:x-gm-message-state; bh=dXBIyyuATJhS+zJWsIN3gPboSiTR1rg9gJyxvsgodMc=; b=Vdfs4OCkgSVpjouYWsqWE9VGYxzM3D1XKmp8pwhCU0bEt/aZEwxuIrr41BmE909Ql6 m1n4eVelIS0W7bHXr2n59fVUiYtNoRtg/DnS3sLQVDMPoKdP2Bh1GLak++4eILjnvbTp FOVfcUDoWF2gYzR/PaL7Jv9ZhOVY2n4x+xg7gBYbZCokFZrMK3fEN8cznU5NIsTWwOWk BQIyXvCdvhAAxGQiI2dOzha0Myb16jymIkx7hA9M24rBqsj6vKB0hWfr64nnGNI+WWRC BnfQ+IX+u1nfZ/stfWQkt6+ZcObyRA058Fw9JWJLknx6PJE20Vod32A+5BJdMU8gcAun 6WYA== Received: by 10.236.84.108 with SMTP id r72mr14132580yhe.90.1344357232886; Tue, 07 Aug 2012 09:33:52 -0700 (PDT) Received: from salusa.poochiereds.net (cpe-069-134-145-027.nc.res.rr.com. [69.134.145.27]) by mx.google.com with ESMTPS id n5sm8059189ang.18.2012.08.07.09.33.51 (version=SSLv3 cipher=OTHER); Tue, 07 Aug 2012 09:33:52 -0700 (PDT) From: Jeff Layton To: linux-cifs@vger.kernel.org Subject: [PATCH] mount.cifs: handle username= differently depending on sec= option Date: Tue, 7 Aug 2012 12:33:47 -0400 Message-Id: <1344357227-9683-1-git-send-email-jlayton@samba.org> X-Mailer: git-send-email 1.7.11.2 X-Gm-Message-State: ALoCoQlgF/870jBdtRu1Bd9bnDyBj3JTRunF8mFJOHfvgpEm8eyiQ5eYb7CwMMdTtAK1iU5NhuRF Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org This patch is intended as a temporary workaround for krb5 users that need to specify usernames with '/' in them. I intend to remove this hack from mount.cifs once the legacy username handling code is removed. The idea here is to save off the raw username string while we're parsing options. If the mount options specify "sec=krb5" or "sec=krb5i" then we'll not do the legacy username parsing and will instead just pass in the username string as-is. Obviously, this is a nasty hack and we don't really want to carry this in perpetuity, so this can go away once the "legacy" username parsing has gone away. Signed-off-by: Jeff Layton --- mount.cifs.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/mount.cifs.c b/mount.cifs.c index ef5b43f..f843bb4 100644 --- a/mount.cifs.c +++ b/mount.cifs.c @@ -588,7 +588,8 @@ parsing_err: } static int open_cred_file(char *file_name, - struct parsed_mount_info *parsed_info) + struct parsed_mount_info *parsed_info, + char **saved_username) { char *line_buf = NULL; char *temp_val = NULL; @@ -637,9 +638,11 @@ static int open_cred_file(char *file_name, /* parse next token */ switch (parse_cred_line(line_buf + i, &temp_val)) { case CRED_USER: - i = parse_username(temp_val, parsed_info); - if (i) + *saved_username = strdup(temp_val); + if (!*saved_username) { + i = EX_SYSERR; goto return_i; + } break; case CRED_PASS: i = set_password(parsed_info, temp_val); @@ -827,6 +830,8 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info) char *ep; struct passwd *pw; struct group *gr; + char *saved_username = NULL; + bool krb5_auth = false; /* * max 32-bit uint in decimal is 4294967295 which is 10 chars wide * +1 for NULL, and +1 for good measure @@ -894,11 +899,10 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info) fprintf(stderr, "username too long\n"); return EX_USAGE; } - rc = parse_username(value, parsed_info); - if (rc) { - fprintf(stderr, - "problem parsing username\n"); - return rc; + saved_username = strdup(value); + if (!saved_username) { + fprintf(stderr, "Unable to allocate memory!\n"); + return EX_SYSERR; } goto nocopy; } @@ -920,9 +924,12 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info) case OPT_SEC: if (value) { - if (!strncmp(value, "none", 4) || - !strncmp(value, "krb5", 4)) + if (!strncmp(value, "none", 4)) { + parsed_info->got_password = 1; + } else if (!strncmp(value, "krb5", 4)) { parsed_info->got_password = 1; + krb5_auth = true; + } } break; @@ -978,7 +985,7 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info) "invalid credential file name specified\n"); return EX_USAGE; } - rc = open_cred_file(value, parsed_info); + rc = open_cred_file(value, parsed_info, &saved_username); if (rc) { fprintf(stderr, "error %d (%s) opening credential file %s\n", @@ -1197,6 +1204,22 @@ nocopy: data = next_keyword; } + if (saved_username) { + if (krb5_auth) { + strlcpy(parsed_info->username, saved_username, + sizeof(parsed_info->username)); + parsed_info->got_user = 1; + } else { + rc = parse_username(saved_username, parsed_info); + free(saved_username); + if (rc) { + fprintf(stderr, "Unable to parse username!\n"); + return rc; + } + } + } + + /* special-case the uid and gid */ if (got_uid) { word_len = snprintf(txtbuf, sizeof(txtbuf), "%u", uid);