From patchwork Sat Apr 23 06:04:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Zaman X-Patchwork-Id: 8916971 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B438C9FC74 for ; Sat, 23 Apr 2016 06:10:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 01530202EC for ; Sat, 23 Apr 2016 06:10:24 +0000 (UTC) Received: from emvm-gh1-uea08.nsa.gov (smtp.nsa.gov [8.44.101.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F1E2620254 for ; Sat, 23 Apr 2016 06:10:22 +0000 (UTC) X-TM-IMSS-Message-ID: <64d18bfc00007549@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1) id 64d18bfc00007549 ; Sat, 23 Apr 2016 02:07:29 -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 u3N688kv007859; Sat, 23 Apr 2016 02:08:08 -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 u3N65S1N117829 for ; Sat, 23 Apr 2016 02:05:28 -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 u3N65Sgg007355 for ; Sat, 23 Apr 2016 02:05:28 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CsBACSDxtX/yUp0Apegw2Be7VdghmCaoEohg4CgW4BAQEBAQFmJ4RCAQEBAxIVGQEBNwEPUTQBBQEcGSKICAGgd4ExPjGKT4UoAQSMSQEBAQEBBQIBFwYKhA2LYIUKh3mFX3OJSY4WY4hGhWVFjSwwgQ5igXiCAF8BiHoBAQE X-IPAS-Result: A0CsBACSDxtX/yUp0Apegw2Be7VdghmCaoEohg4CgW4BAQEBAQFmJ4RCAQEBAxIVGQEBNwEPUTQBBQEcGSKICAGgd4ExPjGKT4UoAQSMSQEBAQEBBQIBFwYKhA2LYIUKh3mFX3OJSY4WY4hGhWVFjSwwgQ5igXiCAF8BiHoBAQE X-IronPort-AV: E=Sophos;i="5.24,520,1454994000"; d="scan'208";a="5403912" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 23 Apr 2016 02:05:27 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3A294LrxCI4C5h2Y5OKi9LUyQJP3N1i/DPJgcQr6Af?= =?us-ascii?q?oPdwSP74r8bcNUDSrc9gkEXOFd2CrakU26yJ6uuxCSQp2tWojjMrSNR0TRgLiM?= =?us-ascii?q?EbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpQAbFhi3Dwdp?= =?us-ascii?q?POO9QteU1JTnkb/rsMyDKyxzxxODIppKZC2sqgvQssREyaBDEY0WjiXzn31TZu?= =?us-ascii?q?5NznlpL1/A1zz158O34YIxu38I46FppIZ8VvDhcqA5S6FIJCg3OGAyosvwvF/M?= =?us-ascii?q?ShXcyGEbVzA0mwFPBUD35RTzWN+lsCLhsexVwCSAM8zwTLcyHz+l6vE4G1fTlC?= =?us-ascii?q?4bOmthoynsgctqgfcDrQ=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A1EQAQA2DxtXiELcVdFegw2Be7VdghmCa?= =?us-ascii?q?oEeCheBdoQBAoFuAQEBAQEBAgIPAQEBCAsLCR+CXn1bPQEBAQMSFRkBATcBD1E?= =?us-ascii?q?0AQUBHBkiiAgBoHeBMT4xik+FKAEEjEkBAQEBAQUCARcGCoQNi2CBfAtAgkOHe?= =?us-ascii?q?YVfc4lJjhZjiEaFZUWNLDCBDoJaHoFiXwGIegEBAQ?= X-IPAS-Result: =?us-ascii?q?A1EQAQA2DxtXiELcVdFegw2Be7VdghmCaoEeCheBdoQBAoF?= =?us-ascii?q?uAQEBAQEBAgIPAQEBCAsLCR+CXn1bPQEBAQMSFRkBATcBD1E0AQUBHBkiiAgBo?= =?us-ascii?q?HeBMT4xik+FKAEEjEkBAQEBAQUCARcGCoQNi2CBfAtAgkOHeYVfc4lJjhZjiEa?= =?us-ascii?q?FZUWNLDCBDoJaHoFiXwGIegEBAQ?= X-IronPort-AV: E=Sophos;i="5.24,520,1454976000"; d="scan'208";a="15548862" Received: from emvm-gh1-uea09.nsa.gov ([10.208.42.194]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-SHA; 23 Apr 2016 06:05:26 +0000 X-TM-IMSS-Message-ID: Received: from mail-pa0-f66.google.com (mail-pa0-f66.google.com [209.85.220.66]) by nsa.gov ([10.208.42.194]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id b0ad6def00006428 ; Sat, 23 Apr 2016 02:04:57 -0400 Received: by mail-pa0-f66.google.com with SMTP id zy2so12078432pac.2 for ; Fri, 22 Apr 2016 23:05:24 -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=ERnLhGkFCtT510sGIXS9JMI7GCp2dWQUh+FBb5Uf9ec=; b=QmtD9qDG4AQYlilpMgcoubhoguicsCKf9nyI0jHdPwLemu6o/DVjDiXVF3Z4ir27yh SHqvvVfmLxo0DB8QyMwrQ6bJNgrrCie28QHMkuQIkdzeltJxUeEOnRiOHON4ltwUvx2X k+et/Z40DQ6+DwTftXXepygS6s6i1HeSbkHfjR3EetxmrLnbKHJ3tmkhedY85H5wY1Ja kC47PA/8Vqr76/tW3bPKnTq4po0O7+rKuRJ2kiJTsjG4+2uidWR0tSAFt5mnllzhbUIN Ueqt40vN7doVRVU4CewVgOu9ybgGsLEc0z6hsWjTW8cbfLTADUeT8wR1rlUBG+SW16vd Hz6Q== 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=ERnLhGkFCtT510sGIXS9JMI7GCp2dWQUh+FBb5Uf9ec=; b=fETTXo0VfxeiaCM6S7Suot3W1067sjJeDdYNMkWaVoQRMzd9lLPzv/1SiG5s4J6naL W7d+STUtofjJJncwTKR4mXVuEYATvXTh9WgV3hnIHtKsUrt2qf9GTKEmirSOzqVp8Cv0 tH3+ce9SH4Uj/8YgTastyokOfRhrusslHvdCkhEt5YX6lxJrO55PiV8VljqjnmpyU+2R CbIJW2WddB3qiH6hg0WvkwzPIT9/8tYlfh5ptz/dhgpYh2jSECnBQ7fVMFd/L10K6wJe /0JGGRzp2SqVy7YdCe7J8F18551az7N0PrGER8Q++TVprqqUwKgWJflB/yPTDGVAFWBE Qrpw== X-Gm-Message-State: AOPr4FVvcE7iuU84BZKh6x8fu4M3SSFbP8EPTxztkCMB/pi9IG4QdFC+j3znpTWsFNI3MA== X-Received: by 10.66.177.75 with SMTP id co11mr34218548pac.85.1461391523788; Fri, 22 Apr 2016 23:05:23 -0700 (PDT) Received: from localhost ([2404:e800:e600:38b:b52d:863:7600:b418]) by smtp.gmail.com with ESMTPSA id h2sm12257514pfd.91.2016.04.22.23.05.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Apr 2016 23:05:23 -0700 (PDT) From: Jason Zaman To: selinux@tycho.nsa.gov Subject: [PATCH v2 2/8] genhomedircon: move fallback user to genhomedircon_user_entry_t Date: Sat, 23 Apr 2016 14:04:53 +0800 Message-Id: <1461391499-20593-3-git-send-email-jason@perfinion.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1461391499-20593-1-git-send-email-jason@perfinion.com> References: <1460131535-15688-1-git-send-email-jason@perfinion.com> <1461391499-20593-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. Signed-off-by: Jason Zaman --- 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 09c2a10..1e35b7e 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; @@ -1046,10 +1044,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; } @@ -1073,9 +1077,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;