From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cs.msu.ru; s=dkim; h=Subject:In-Reply-To:Content-Type:MIME-Version:References:Message-ID :Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=jB+4M1MGh1QQYpyREtt6RD0g2n2+FW84xmTV8fR4rpk=; b=uPPpinVIEmpFqjGtG9duvtPADu 8nbht4gSo02oYNrtyx7f7aJDEIeHZMcdPoxmIwgZY7lgy/9ufqkRak072OROzETA2JzNq0IjGa+xP hDRiJ7oIVimX5xc3df3KlQD6dXYjmyqc5Ff8lfqjKmQ6ZgaLgE0Tnv+pq9D8U0YBQegeM4jShS4M0 Hnxiy0f+oi5n8VjTl8G62SfRecwJ8JoPm9ziF8zMV5Y/8BeXrNP7kedbujn0dsvUDOkbAVwpZmKr/ jBbv8jEUq1IkPR3K+PQCqKOBxYGyI9yB5scXkoxLv9xLCN4OacTmy8nkQryzKgI4uzSKE14sIxg4z 5xUu1O1A==; Date: Thu, 17 Sep 2020 16:11:27 +0300 From: Arseny Maslennikov To: Alex Gladkov , devel@lists.altlinux.org Message-ID: <20200917131127.GF286846@cello> References: <9bca7626b593f896de4283cba2d6290ec99eb4f2.1576183643.git.legion@altlinux.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="4VrXvz3cwkc87Wze" Content-Disposition: inline In-Reply-To: <9bca7626b593f896de4283cba2d6290ec99eb4f2.1576183643.git.legion@altlinux.org> OpenPGP: url=http://grep.cs.msu.ru/~ar/pgp-key.asc X-SA-Exim-Connect-IP: 10.7.5.179 X-SA-Exim-Mail-From: ar@cs.msu.ru X-SA-Exim-Version: 4.2.1 X-SA-Exim-Scanned: Yes (on mail.cs.msu.ru) Cc: ldv@altlinux.org Subject: Re: [devel] [PATCH hasher-priv v1 1/3] caller.c X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Sep 2020 13:11:30 -0000 Archived-At: List-Archive: List-Post: --4VrXvz3cwkc87Wze Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Dec 13, 2019 at 12:42:03PM +0100, Alex Gladkov wrote: > diff --git a/hasher-priv/caller.c b/hasher-priv/caller.c > index e83084a..031ddef 100644 > --- a/hasher-priv/caller.c > +++ b/hasher-priv/caller.c > @@ -19,62 +19,67 @@ > > #include "priv.h" > #include "xmalloc.h" > +#include "logging.h" > > -const char *caller_user, *caller_home; > -uid_t caller_uid; > -gid_t caller_gid; > +char *caller_user = NULL; > +char *caller_home = NULL; > +uid_t caller_uid; > +gid_t caller_gid; > > /* > * Initialize caller_user, caller_uid, caller_gid and caller_home. > */ > -void > -init_caller_data(void) > +int > +init_caller_data(uid_t uid, gid_t gid) > { > - const char *logname; > struct passwd *pw = 0; > > - caller_uid = getuid(); > - if (caller_uid < MIN_CHANGE_UID) > - error(EXIT_FAILURE, 0, "caller has invalid uid: %u", > - caller_uid); > - > - caller_gid = getgid(); > - if (caller_gid < MIN_CHANGE_GID) > - error(EXIT_FAILURE, 0, "caller has invalid gid: %u", > - caller_gid); > - > - if ((logname = getenv("LOGNAME"))) > - if (!*logname || strchr(logname, ':')) > - logname = 0; > - > - if (logname) > - { > - pw = getpwnam(logname); > - if (caller_uid != pw->pw_uid || caller_gid != pw->pw_gid) > - pw = 0; > + caller_uid = uid; > + if (caller_uid < MIN_CHANGE_UID) { > + err("caller has invalid uid: %u", caller_uid); > + return -1; > + } > + > + caller_gid = gid; > + if (caller_gid < MIN_CHANGE_GID) { > + err("caller has invalid gid: %u", caller_gid); > + return -1; > } > > - if (!pw) > - pw = getpwuid(caller_uid); > + pw = getpwuid(caller_uid); > > - if (!pw || !pw->pw_name) > - error(EXIT_FAILURE, 0, "caller lookup failure"); > + if (!pw || !pw->pw_name) { > + err("caller lookup failure"); > + return -1; > + } > > caller_user = xstrdup(pw->pw_name); > > - if (caller_uid != pw->pw_uid) > - error(EXIT_FAILURE, 0, "caller %s: uid mismatch", > - caller_user); > + if (caller_uid != pw->pw_uid) { > + err("caller %s: uid mismatch", caller_user); > + return -1; > + } > > - if (caller_gid != pw->pw_gid) > - error(EXIT_FAILURE, 0, "caller %s: gid mismatch", > - caller_user); > + if (caller_gid != pw->pw_gid) { > + err("caller %s: gid mismatch", caller_user); > + return -1; > + } > > errno = 0; > if (pw->pw_dir && *pw->pw_dir) > caller_home = canonicalize_file_name(pw->pw_dir); > > - if (!caller_home || !*caller_home) > - error(EXIT_FAILURE, errno, "caller %s: invalid home", > - caller_user); > + if (!caller_home || !*caller_home) { > + err("caller %s: invalid home: %m", caller_user); > + return -1; > + } > + > + return 0; > +} > + > +void > +free_caller_data(void) > +{ > + free(caller_user); > + free(caller_home); > } --4VrXvz3cwkc87Wze Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE56JD3UKTLEu/ddrm9dQjyAYL01AFAl9jYH8ACgkQ9dQjyAYL 01BeFg//X0GV9GBtGj8DlOdyi3IcVWt6fK/YTpSprR/EYtL7KUN3M4oLeXXnws/e 9XCW+2xs8h0/gAXr9AN6ReSewKzA20WOxPtzRMGK4SqIImeCOJGj/BzNsT9IXif7 xFENhZRxBlj+jEW1fo82d6bOpN6Ahlzdsul7lbPp3oytySgbmfOI4ZC6rTL50S+j OB2JygXKoHW8oPWUZQYXuwvzXBKfCt/Cb3mbyy2U7LnXqYJewhy3oQrRfESDJbN9 xKss6/aNAZCI2uMD9rYB/y8ZmzJGhfL+w8Aj5UKvj6gFk9vv0yP5D8dh3rpBDgrJ yQiorJOKohU3ZtevESvV2POjvafjbFvnXwf7Dme/mOErYDHmxaWlfj93pyDXlr10 rsuXtFtLuvXEvkNEpB9pszo0Wxw2z/Dk4bU2tHxDXDF0yfze8bzsTYPokNhU5Gl5 x9OKsiFVbUgIwKDW8a7M21z5DysDYZspTEoYPgUC5L79ENKkHlh1bxDu7zCqqAa5 HEzqMJ4ioCHfpCg04zudNgmGXKZUpKlWfFsRYk874wPe4U7kbUlgOdE19VA8CnLG uSGc8S21YsGCYSRGXiVO8Qy0C0RcNZNPDrX2lP8QHV/hqXp3VVgMcxiYIUcNDSDa /z7am9EtPZFkBx1SxhoXxf854T7MWivkxtj+k/kP0QxHiIi+TXY= =Bg1W -----END PGP SIGNATURE----- --4VrXvz3cwkc87Wze--