From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FROM_SUSPICIOUS_NTLD, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x13e.google.com (mail-lf1-x13e.google.com [IPv6:2a00:1450:4864:20::13e]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 7333002f for ; Sun, 22 Sep 2019 13:12:51 +0000 (UTC) Received: by mail-lf1-x13e.google.com with SMTP id y27sf1833886lfg.21 for ; Sun, 22 Sep 2019 06:12:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1569157971; cv=pass; d=google.com; s=arc-20160816; b=CDNEu/RJFXJ1S9dkT6gVZK99qwUvT0/MOiEHqu/wLgVFGdHhFB3sU80h2ZmWX4A4od pvAseop4th92hiYKds3OVOasM55Xi2vLy/FuyZMyURXTIrKUaZrlcgDrU85PFKxOkayC CDMvKWcrj7GUKAX7rJe2z6naU2gHzqt5HLgoriKC9mUX5SGae+7wl2X2qwInpYC+nOdA CK0hG1eQgBG+GNVJeedpPAMfO2Sb47ZBX/zyKO9GwzllxSeyIbS8ulIRXC5EqA/Mwvel 3PcWplg1H0hHaZMjjhUi6Sdg79Ps1XqmZgCnlP2pD8ADP6UjedahLD4gZV6vX6GQhDGg WTtg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=N2gjQU8SW6o+9mdJrLNqci+f7ISq5TTeWPspzdJLdqM=; b=JpNEUlMTn91DBSFWoLfUfY3v/TNw3ciF9prGdLlp9HYJ7YDk+/Oe6sI4jt3eHzEbFW IgvsEviq8Bl2LKsEe2RbeLZZv7RS5/yBu5uLjbe0n+a4ZbZzXkg4INejfZPrUxMgNAZt 7JWfKtsuNUK0BMfKARDYRaZxEX9I2H74vAeiW4JIjJ0//zxz1NlCzurJSMWXqio1Tg/E BeAevf/S/X+/Qbj/FRZ26iHUYfXrrYyyKr/8myYYoWJRuNNH6LdIMztxJe6kbgKhRX4K gsIWCmB/zCNot0YAomsA2KLN2yjS1jAI6PTCDtd1Mpkm3pYBtDXLjOCOdQxfwjRBM5B1 mj3w== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@fifth.space header.s=dkim header.b=ot25CPum; spf=pass (google.com: domain of quinq@fifth.space designates 45.32.148.28 as permitted sender) smtp.mailfrom=quinq@fifth.space DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=N2gjQU8SW6o+9mdJrLNqci+f7ISq5TTeWPspzdJLdqM=; b=JsqRxmG0Xsg4LCXGa/TWHuSnlWLz0lATGukedCndjUx+IZWg26+cq7jVf+o9YvDRV5 kdBwd0n1gYX5eY9xKTXPWQtzG6AEag6Gw/Vrzy+cCK2xpz7cO2tRyFq0NB6/jBCMDlZL /Ceys4tt9JkyXak4zj9PTQ9NwKqTf08eRb413h52lzAhCHmOexk66nPbTLYt6tNt2d9q gR3V+ey+57L55OQ5tW/Px1pw18stzbfo4GKyuDE9s2OqrguqgmZ1pJtOMuXzAUOgT6BF 8HT6b4S+dwviUvfRX7qWSfGNdD9qj49pwfaRbasIMzLfAYUnhgDDPBZPT47SIWsz26xE ekCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=N2gjQU8SW6o+9mdJrLNqci+f7ISq5TTeWPspzdJLdqM=; b=bMu1kqtN8jt73kAqSZD78fhKPWaJKT0Unix0qDrvt3GlyFJau98ms8ShlSt65I6Nh+ IxzpOO/qwlhEI3iPANCYcUsCnQJH4IWE5F9LpaP4GLHsbPsGaVX7CH/vIJlyAVe4JdJp pfRog5OVXaidu4EhbwXiHj6uNR1XrkUYFTaaQvZQw/DMeaBaAvr/xxut+/bCEE42G9wd NoRlMDFIOKWspslkKlCFLJ6n5HofZMB0K0dNeOC9lxsEJMvOOg15yV3Mefi3/JmTfJBU BEyNlAChuJBcbResFfrFHmcfP7CH2NICnpBi1I/eavu0bVtLGCk076PUQO/CkS5gp94x I9JA== Sender: voidlinux@googlegroups.com X-Gm-Message-State: APjAAAXFjz3WuYEj/33hQhz2bJHO2DmVo/NJBNoUlD0ePoGeMJYZkTyk KO/EG0QBcb8xYZDExQcpkZ8= X-Google-Smtp-Source: APXvYqw/tV9BWjjHWZFjQDJBaJs3bhEF90qMQ+G1YII1Bd81kDlzAp4S0j5wpSqSUsw+O8/HrSq19A== X-Received: by 2002:a2e:9615:: with SMTP id v21mr14364187ljh.46.1569157971543; Sun, 22 Sep 2019 06:12:51 -0700 (PDT) X-BeenThere: voidlinux@googlegroups.com Received: by 2002:a2e:2286:: with SMTP id i128ls1562486lji.7.gmail; Sun, 22 Sep 2019 06:12:50 -0700 (PDT) X-Received: by 2002:a2e:8941:: with SMTP id b1mr9579617ljk.40.1569157970947; Sun, 22 Sep 2019 06:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569157970; cv=none; d=google.com; s=arc-20160816; b=xlGl80v3pUEuSaWHy1UecmBZ1ZSpn3HiId4SNZzOWqlFrMEYN1tF0juJkThBvb6+Ld jZws+G8CH+MylXu0+VzWxNsVIyogBW801bZgutPs2Ed6X9jrTWdCxIAckUgRGeDlpdqB W9fI1g4BtQ2LGOypGoNZw3X1yIwKprU/3h0JXU0SR4HA86PduMRr9elluy58okOqQS27 eSUPXyk4/AnyLHKcSWlQ61stHnH5mN1Fz19d8v/5zkkm2a0XwuWVS1luBZs1NHQPPhjU 9UJN/wi7VFBKteXcCVKYAJE20IkOFyxxJuabl0mJVE66CIi+uo3HZjwATWTRsg4E+O8+ zusg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:domainkey-signature :dkim-signature; bh=6a6BXLK2VyGbOVhyojE550buFyYfQ80wINGy8E7tNT4=; b=UYunUNxEZ0n2zDltinSYxO6rchqW9XzDB/wqk01cuqu3TmUXp/3ufSifzjGyRKGy8j MwxX3fLfPeT1ahjwBjS7WmgCldM36zqvpdBu6TiQYDAR+dd7TOEWoLXazV0o8t+EhCPU 6OhU2YuqtF9y1GhlSghS44bdxTZ85sTRfMTGnB/OGo+KAt5WGWdxlVFGZ0hwY83ZtBh1 Cl1I1joB3UvXVqh+VVlKxfjZ8hWP75ROArEZZ/jMQjYf3MUqLiwpAb3DnV78UfLf6ptg YKAxvdgwip44aoRznCMgzrvuFYmmmGs8k5dRJNmgkLt2Up5JnbC8MFetw1Lxan0ZuYRQ edwg== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@fifth.space header.s=dkim header.b=ot25CPum; spf=pass (google.com: domain of quinq@fifth.space designates 45.32.148.28 as permitted sender) smtp.mailfrom=quinq@fifth.space Received: from fifth.space (fifth.space. [45.32.148.28]) by gmr-mx.google.com with ESMTPS id y6si479643lji.0.2019.09.22.06.12.50 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 22 Sep 2019 06:12:50 -0700 (PDT) Received-SPF: pass (google.com: domain of quinq@fifth.space designates 45.32.148.28 as permitted sender) client-ip=45.32.148.28; Received: from fifth.space (localhost [127.0.0.1]) by fifth.space (OpenSMTPD) with ESMTP id 5d4776a9 for ; Sun, 22 Sep 2019 15:12:49 +0200 (CEST) Received: from localhost (fifth.space [local]) by fifth.space (OpenSMTPD) with ESMTPA id 34121f1f; Sun, 22 Sep 2019 15:12:49 +0200 (CEST) From: Quentin Rameau To: Void Linux Cc: Quentin Rameau Subject: [PATCH 1/2] lib/pwdutils: add xgetpwuid Date: Sun, 22 Sep 2019 15:12:36 +0200 Message-Id: <20190922131237.93849-2-quinq@fifth.space> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190922131237.93849-1-quinq@fifth.space> References: <20190922131237.93849-1-quinq@fifth.space> MIME-Version: 1.0 X-Original-Sender: quinq@fifth.space X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@fifth.space header.s=dkim header.b=ot25CPum; spf=pass (google.com: domain of quinq@fifth.space designates 45.32.148.28 as permitted sender) smtp.mailfrom=quinq@fifth.space Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list voidlinux@googlegroups.com; contact voidlinux+owners@googlegroups.com List-ID: X-Google-Group-Id: 289663804196 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , --- include/pwdutils.h | 1 + lib/pwdutils.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/pwdutils.h b/include/pwdutils.h index a69dd6b45..bea46e57e 100644 --- a/include/pwdutils.h +++ b/include/pwdutils.h @@ -5,6 +5,7 @@ #include extern struct passwd *xgetpwnam(const char *username, char **pwdbuf); +extern struct passwd *xgetpwuid(uid_t uid, char **pwdbuf); extern char *xgetlogin(void); #endif /* UTIL_LINUX_PWDUTILS_H */ diff --git a/lib/pwdutils.c b/lib/pwdutils.c index 25b4daed0..d54458d65 100644 --- a/lib/pwdutils.c +++ b/lib/pwdutils.c @@ -36,6 +36,34 @@ failed: return NULL; } +struct passwd *xgetpwuid(uid_t uid, char **pwdbuf) +{ + struct passwd *pwd = NULL, *res = NULL; + int rc; + + if (!pwdbuf) + return NULL; + + *pwdbuf = xmalloc(UL_GETPW_BUFSIZ); + pwd = xcalloc(1, sizeof(struct passwd)); + + errno = 0; + rc = getpwuid_r(uid, pwd, *pwdbuf, UL_GETPW_BUFSIZ, &res); + if (rc != 0) { + errno = rc; + goto failed; + } + if (!res) { + errno = EINVAL; + goto failed; + } + return pwd; +failed: + free(pwd); + free(*pwdbuf); + return NULL; +} + char *xgetlogin(void) { struct passwd *pw = NULL; -- 2.21.0 -- You received this message because you are subscribed to the Google Groups "voidlinux" group. To unsubscribe from this group and stop receiving emails from it, send an email to voidlinux+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/voidlinux/20190922131237.93849-2-quinq%40fifth.space.