From patchwork Fri Apr 8 16:05:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Zaman X-Patchwork-Id: 8784461 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 6838B9FBEA for ; Fri, 8 Apr 2016 16:13:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9DE23202EC for ; Fri, 8 Apr 2016 16:13:36 +0000 (UTC) Received: from emvm-gh1-uea09.nsa.gov (smtp.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 9EE7B202DD for ; Fri, 8 Apr 2016 16:13:35 +0000 (UTC) X-TM-IMSS-Message-ID: <6598f9de000a10d7@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 6598f9de000a10d7 ; Fri, 8 Apr 2016 12:09:59 -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 u38GB0cc022345; Fri, 8 Apr 2016 12:11:00 -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 u38G6ZWj083030 for ; Fri, 8 Apr 2016 12:06:35 -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 u38G6Zm2021132 for ; Fri, 8 Apr 2016 12:06:35 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1DCCwBH1gdXX0TcVdFcgwyBe7g2gmyBJIR9AYEPAoF/AQEBAQEBBxcMEx9yDAGDdAEBAQMSFRkBATcBD1E0AQUBCBQ7iAUBoRuBMT4xik+FKAEEjT4BAQEBAQEEAgEXBgqEDo1bC0CCQ41Tc4lDjg5kiEWFYkWNIy+BDoJZDRmBV18BgR+IGQEBAQ X-IPAS-Result: A1DCCwBH1gdXX0TcVdFcgwyBe7g2gmyBJIR9AYEPAoF/AQEBAQEBBxcMEx9yDAGDdAEBAQMSFRkBATcBD1E0AQUBCBQ7iAUBoRuBMT4xik+FKAEEjT4BAQEBAQEEAgEXBgqEDo1bC0CCQ41Tc4lDjg5kiEWFYkWNIy+BDoJZDRmBV18BgR+IGQEBAQ X-IronPort-AV: E=Sophos;i="5.24,454,1454994000"; d="scan'208";a="5363087" Received: from emvm-gh1-uea09.nsa.gov ([10.208.42.194]) by goalie.tycho.ncsc.mil with ESMTP; 08 Apr 2016 12:06:34 -0400 X-TM-IMSS-Message-ID: <6594dec0000a0ea6@nsa.gov> Received: from mail-pa0-f68.google.com (mail-pa0-f68.google.com [209.85.220.68]) by nsa.gov ([10.208.42.194]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 6594dec0000a0ea6 ; Fri, 8 Apr 2016 12:05:30 -0400 Received: by mail-pa0-f68.google.com with SMTP id zy2so9376308pac.2 for ; Fri, 08 Apr 2016 09:06:32 -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=zoq7JPdRN5RF3G97XpHsAoL2DjCLgvKK8Qdbg0tC7EQ=; b=gbts8y43eBUfnz7OHcwEkMZpvbP0/Iz0yPvVNDSXhAhXTlVO8giRD04H59RsV6cP5f jaa/bmO/CI740luIOqhsIQdhijRgsLRYRcyGOkonpWE10jAGhu2qsB2tk79AbVSYg3ui 4saGQt8MmUdXw55ex1dcRHxTSkiUTR29PZi3EGJDKBOgpvKAgG3yEW5cvvygI5q/FOFk MfyzEz0fEG324KMdOQMtNYFiwyq9mXpb0MeGx7MqK5pXwzxETKG/ALtmdvBSH/gQ9Q9F yBHG/25Juzas0sRlwt0+vn3OqhlUioc7Hm/GQ2Dp9pExrzXYT7EWuZFCycU2tKmz3sZA mMcw== 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=zoq7JPdRN5RF3G97XpHsAoL2DjCLgvKK8Qdbg0tC7EQ=; b=YOfIv2Al1d2koWv3DaAR+5GaBhp/HZInSrXyRcoonAkuHt7c1nhwiy6q8FG1cqGKn3 VL0004/RmJj21OnaVG12tzmlOijjde8VfiE7qMacevLtWxEDpfWADmzr98ErgZnc74zc OpFVC6M9MvOxHJtVQkLiLt3LJAZNPARoYkJgUJNQoULLUbyQpZ0r3xbmOJEbiel84atV joHab/5fm2v3WW7mkd1XIk4MwpE1cRZndKpPD6mN4iU9Wbg4OaQ/NVxO841Ny77x37D6 vxRs5jOPoOKyx2LBUQYoDGQB0VQcU86/otWO1T+98374z8N0VsMY7lQjsLwtEtCGKm9+ bo7A== X-Gm-Message-State: AD7BkJIo9+lYek/qroxNU1qwBt+K2m4QUuJ3wZi+yZbiM+VJBOwJHkhzdG9r/HF/lJFsSg== X-Received: by 10.66.190.40 with SMTP id gn8mr13707576pac.64.1460131591172; Fri, 08 Apr 2016 09:06:31 -0700 (PDT) Received: from localhost ([2404:e800:e600:38b:5121:e6bd:6ddf:d757]) by smtp.gmail.com with ESMTPSA id f8sm19698243pfj.49.2016.04.08.09.06.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Apr 2016 09:06:30 -0700 (PDT) From: Jason Zaman To: selinux@tycho.nsa.gov Subject: [PATCH 5/7] genhomedircon: Add uid and gid to struct user_entry Date: Sat, 9 Apr 2016 00:05:33 +0800 Message-Id: <1460131535-15688-6-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 --- libsemanage/src/genhomedircon.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/libsemanage/src/genhomedircon.c b/libsemanage/src/genhomedircon.c index 495f084..ae4a261 100644 --- a/libsemanage/src/genhomedircon.c +++ b/libsemanage/src/genhomedircon.c @@ -82,10 +82,13 @@ #define FALLBACK_PREFIX "user" #define FALLBACK_LEVEL "s0" #define FALLBACK_NAME ".*" +#define FALLBACK_UIDGID "[0-9]+" #define DEFAULT_LOGIN "__default__" typedef struct user_entry { char *name; + char *uid; + char *gid; char *sename; char *prefix; char *home; @@ -627,11 +630,13 @@ static int name_user_cmp(char *key, semanage_user_t ** val) } static int push_user_entry(genhomedircon_user_entry_t ** list, const char *n, - const char *sen, const char *pre, const char *h, - const char *l) + const char *u, const char *g, const char *sen, + const char *pre, const char *h, const char *l) { genhomedircon_user_entry_t *temp = NULL; char *name = NULL; + char *uid = NULL; + char *gid = NULL; char *sename = NULL; char *prefix = NULL; char *home = NULL; @@ -643,6 +648,12 @@ static int push_user_entry(genhomedircon_user_entry_t ** list, const char *n, name = strdup(n); if (!name) goto cleanup; + uid = strdup(u); + if (!uid) + goto cleanup; + gid = strdup(g); + if (!gid) + goto cleanup; sename = strdup(sen); if (!sename) goto cleanup; @@ -657,6 +668,8 @@ static int push_user_entry(genhomedircon_user_entry_t ** list, const char *n, goto cleanup; temp->name = name; + temp->uid = uid; + temp->gid = gid; temp->sename = sename; temp->prefix = prefix; temp->home = home; @@ -668,6 +681,8 @@ static int push_user_entry(genhomedircon_user_entry_t ** list, const char *n, cleanup: free(name); + free(uid); + free(gid); free(sename); free(prefix); free(home); @@ -686,6 +701,8 @@ static void pop_user_entry(genhomedircon_user_entry_t ** list) temp = *list; *list = temp->next; free(temp->name); + free(temp->uid); + free(temp->gid); free(temp->sename); free(temp->prefix); free(temp->home); @@ -737,7 +754,8 @@ static int setup_fallback_user(genhomedircon_settings_t * s) level = FALLBACK_LEVEL; } - if (push_user_entry(&(s->fallback), FALLBACK_NAME, 0, 0, + if (push_user_entry(&(s->fallback), FALLBACK_NAME, + FALLBACK_UIDGID, FALLBACK_UIDGID, seuname, prefix, "", level) != 0) errors = STATUS_ERR; semanage_user_key_free(key); @@ -767,6 +785,8 @@ static genhomedircon_user_entry_t *get_users(genhomedircon_settings_t * s, const char *seuname = NULL; const char *prefix = NULL; const char *level = NULL; + char uid[10]; + char gid[10]; struct passwd pwstorage, *pwent = NULL; unsigned int i; long rbuflen; @@ -851,7 +871,13 @@ static genhomedircon_user_entry_t *get_users(genhomedircon_settings_t * s, } if (ignore(pwent->pw_dir)) continue; - if (push_user_entry(&head, name, seuname, + + if (snprintf(uid, sizeof(uid), "%d", pwent->pw_uid) < 0 + || snprintf(gid, sizeof(gid), "%d", pwent->pw_gid) < 0) { + *errors = STATUS_ERR; + goto cleanup; + } + if (push_user_entry(&head, name, uid, gid, seuname, prefix, pwent->pw_dir, level) != STATUS_SUCCESS) { *errors = STATUS_ERR; break;