From patchwork Fri Apr 8 16:05:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Zaman X-Patchwork-Id: 8784401 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 826D4C0553 for ; Fri, 8 Apr 2016 16:13:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C67F12011D for ; Fri, 8 Apr 2016 16:13:14 +0000 (UTC) Received: from emvm-gh1-uea09.nsa.gov (emvm-gh1-uea09.nsa.gov [8.44.101.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D75FC202E9 for ; Fri, 8 Apr 2016 16:13:13 +0000 (UTC) X-TM-IMSS-Message-ID: <6598cc87000a10b6@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([10.208.42.194]) with ESMTP (TREND IMSS SMTP Service 7.1) id 6598cc87000a10b6 ; Fri, 8 Apr 2016 12:09:48 -0400 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u38GAnhN022224; Fri, 8 Apr 2016 12:10:49 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u38G6LMK083021 for ; Fri, 8 Apr 2016 12:06:21 -0400 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u38G6LBF021119 for ; Fri, 8 Apr 2016 12:06:21 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1A0CgBH1gdXd8LAVdFcgwyBe7YdghmCbIEkhg0CgX8BAQEBAQETAQoLFCFwDAGDdAEBAQMSFRkBATcBD1E0AQUBHDuIBQGhG4ExPjGKT4UoAQSNPgEBAQEBBQIBFwYKhA6LX4F8C0CCQ4d1hV5ziUOODmSIRYViRY0jL4EOglmBfV8BgR+IGQEBAQ X-IPAS-Result: A1A0CgBH1gdXd8LAVdFcgwyBe7YdghmCbIEkhg0CgX8BAQEBAQETAQoLFCFwDAGDdAEBAQMSFRkBATcBD1E0AQUBHDuIBQGhG4ExPjGKT4UoAQSNPgEBAQEBBQIBFwYKhA6LX4F8C0CCQ4d1hV5ziUOODmSIRYViRY0jL4EOglmBfV8BgR+IGQEBAQ X-IronPort-AV: E=Sophos;i="5.24,454,1454994000"; d="scan'208";a="5363084" Received: from emvm-gh1-uea09.nsa.gov ([10.208.42.194]) by goalie.tycho.ncsc.mil with ESMTP; 08 Apr 2016 12:06:20 -0400 X-TM-IMSS-Message-ID: <6594a836000a0e82@nsa.gov> Received: from mail-pf0-f194.google.com (mail-pf0-f194.google.com [209.85.192.194]) by nsa.gov ([10.208.42.194]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 6594a836000a0e82 ; Fri, 8 Apr 2016 12:05:16 -0400 Received: by mail-pf0-f194.google.com with SMTP id q129so9764528pfb.3 for ; Fri, 08 Apr 2016 09:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=perfinion-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OHyNltpcq85Xi4Vv5Ikn3xCRZJK8u0WEK3meAMcFRUI=; b=osPhc9C3Wqh9H8gO7+s2IwnHut/2sOPWBN1n2lrnM+UiHuBxm6fy43QTUnFc23p4Vn cAqOS1VG3e2mCwfz/wdBBXOHc8C4ldnqsdMrfR///WU3FzE8YI72MMSPutnkz/I3sxs9 T/gAJSCXZQnuo8C/aak3TZqcgGbAxiK+uq6pjoVND3yCFfmeLgC5U1NeP5gqndm0+hv9 q5ixLchkcdTWbYrDCpn7k05aXFQLcRLTWCWUUEtwSbfo28WJfuqRDtrhLgWRQBTlCFCl PTdA2+UeCFYsPP2D3/cawhos4UUhM47oKFAwQbX6eIRtqBjrGj6RMi6/7wbM0mxtyXAj caaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OHyNltpcq85Xi4Vv5Ikn3xCRZJK8u0WEK3meAMcFRUI=; b=Y1LJ6/MEsSC53bfk1ss5/xv2be6m9em0bIuaGYqemwHh8dLc8pRHvSHTwXvlOKgc5B jBLXnT5iMgvbBHDznpUmMvHkBqcUaXsH2RYDep+GKVn42ktvZ5p8j5Eo3d4GUrdo5xgo UxYSrl+FPGlreGjWkdjKdciGvKzIxRwsn2VxXbUikL5g6aWur9R17eiY+EkoIsucDYSt EjQIsRI5pi0nnqCZYV5XadmyYTmJZDdkVSqyKJ6jFfqRXNuPiQ1nhpjijnhMIyuieip+ MtZz1bdk7fL8OIRNrhVwvLKPBZrN00c3fgncdzI5Jg5vxQxXJHCydJOURwClSU76gbhQ gslQ== X-Gm-Message-State: AD7BkJKBYrrHfTi78NK8AA8yF9YpxmPQx2cryI16LUmG2YZtPu37NTWaqmQ6btLCCys+SA== X-Received: by 10.98.75.214 with SMTP id d83mr13778506pfj.22.1460131577349; Fri, 08 Apr 2016 09:06:17 -0700 (PDT) Received: from localhost ([2404:e800:e600:38b:5121:e6bd:6ddf:d757]) by smtp.gmail.com with ESMTPSA id tc8sm19744635pac.29.2016.04.08.09.06.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2016 09:06:16 -0700 (PDT) From: Jason Zaman To: selinux@tycho.nsa.gov Subject: [PATCH 2/7] genhomedircon: move fallback user to genhomedircon_user_entry_t Date: Sat, 9 Apr 2016 00:05:30 +0800 Message-Id: <1460131535-15688-3-git-send-email-jason@perfinion.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1460131535-15688-1-git-send-email-jason@perfinion.com> References: <20160201093633.GB21978@meriadoc.perfinion.com> <1460131535-15688-1-git-send-email-jason@perfinion.com> X-TM-AS-MML: disable X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The fallback user is used in all the write functions, making it use a struct allows us to have everything consistent between normal and fallback users. --- libsemanage/src/genhomedircon.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/libsemanage/src/genhomedircon.c b/libsemanage/src/genhomedircon.c index a95ab16..3289954 100644 --- a/libsemanage/src/genhomedircon.c +++ b/libsemanage/src/genhomedircon.c @@ -83,17 +83,6 @@ #define FALLBACK_USER_LEVEL "s0" #define DEFAULT_LOGIN "__default__" -typedef struct { - const char *fcfilepath; - int usepasswd; - const char *homedir_template_path; - char *fallback_user; - char *fallback_user_prefix; - char *fallback_user_level; - semanage_handle_t *h_semanage; - sepol_policydb_t *policydb; -} genhomedircon_settings_t; - typedef struct user_entry { char *name; char *sename; @@ -104,6 +93,15 @@ typedef struct user_entry { } genhomedircon_user_entry_t; typedef struct { + const char *fcfilepath; + int usepasswd; + const char *homedir_template_path; + genhomedircon_user_entry_t *fallback; + semanage_handle_t *h_semanage; + sepol_policydb_t *policydb; +} genhomedircon_settings_t; + +typedef struct { const char *search_for; const char *replace_with; } replacement_pair_t; @@ -1045,10 +1043,16 @@ int semanage_genhomedircon(semanage_handle_t * sh, s.fcfilepath = semanage_final_path(SEMANAGE_FINAL_TMP, SEMANAGE_FC_HOMEDIRS); - s.fallback_user = strdup(FALLBACK_USER); - s.fallback_user_prefix = strdup(FALLBACK_USER_PREFIX); - s.fallback_user_level = strdup(FALLBACK_USER_LEVEL); - if (s.fallback_user == NULL || s.fallback_user_prefix == NULL || s.fallback_user_level == NULL) { + s.fallback = calloc(1, sizeof(genhomedircon_user_entry_t)); + if (s.fallback == NULL) { + retval = STATUS_ERR; + goto done; + } + + s.fallback->sename = strdup(FALLBACK_USER); + s.fallback->prefix = strdup(FALLBACK_USER_PREFIX); + s.fallback->level = strdup(FALLBACK_USER_LEVEL); + if (s.fallback->sename == NULL || s.fallback->prefix == NULL || s.fallback->level == NULL) { retval = STATUS_ERR; goto done; } @@ -1072,9 +1076,7 @@ done: if (out != NULL) fclose(out); - free(s.fallback_user); - free(s.fallback_user_prefix); - free(s.fallback_user_level); + pop_user_entry(&(s.fallback)); ignore_free(); return retval;