summaryrefslogtreecommitdiff
path: root/libmisc
diff options
context:
space:
mode:
authorBalint Reczey <balint.reczey@canonical.com>2019-03-03 23:31:24 +0100
committerBalint Reczey <balint.reczey@canonical.com>2019-03-03 23:31:24 +0100
commitb0729855e8fb744192a0395ea24673557818172c (patch)
treef2c3f13b5ba33b0b1f3627c24cd4005e0972ff86 /libmisc
parent589f97ade4610b98cc532c8142343d4c33694e72 (diff)
downloadshadow-b0729855e8fb744192a0395ea24673557818172c.tar.gz
New upstream version 4.6upstream/4.6
Diffstat (limited to 'libmisc')
-rw-r--r--libmisc/Makefile.am3
-rw-r--r--libmisc/failure.h2
-rw-r--r--libmisc/find_new_gid.c2
-rw-r--r--libmisc/find_new_uid.c2
-rw-r--r--libmisc/getdate.y2
-rw-r--r--libmisc/idmapping.c2
-rw-r--r--libmisc/pam_pass_non_interactive.c (renamed from libmisc/pam_pass_non_interractive.c)2
-rw-r--r--libmisc/prefix_flag.c340
-rw-r--r--libmisc/setupenv.c2
-rw-r--r--libmisc/strtoday.c2
-rw-r--r--libmisc/utmp.c2
11 files changed, 351 insertions, 10 deletions
diff --git a/libmisc/Makefile.am b/libmisc/Makefile.am
index 4a620495..eb44a569 100644
--- a/libmisc/Makefile.am
+++ b/libmisc/Makefile.am
@@ -44,7 +44,8 @@ libmisc_a_SOURCES = \
myname.c \
obscure.c \
pam_pass.c \
- pam_pass_non_interractive.c \
+ pam_pass_non_interactive.c \
+ prefix_flag.c \
pwd2spwd.c \
pwdcheck.c \
pwd_init.c \
diff --git a/libmisc/failure.h b/libmisc/failure.h
index 13187a40..38a4d72f 100644
--- a/libmisc/failure.h
+++ b/libmisc/failure.h
@@ -69,7 +69,7 @@ extern int failcheck (uid_t uid, struct faillog *fl, bool failed);
extern void failprint (const struct faillog *);
/*
- * failtmp - update the cummulative failure log
+ * failtmp - update the cumulative failure log
*
* failtmp updates the (struct utmp) formatted failure log which
* maintains a record of all login failures.
diff --git a/libmisc/find_new_gid.c b/libmisc/find_new_gid.c
index 2fe6a2a9..d8764087 100644
--- a/libmisc/find_new_gid.c
+++ b/libmisc/find_new_gid.c
@@ -136,7 +136,7 @@ static int check_gid (const gid_t gid,
}
/* Check if the GID exists according to NSS */
errno = 0;
- if (getgrgid (gid) != NULL) {
+ if (prefix_getgrgid (gid) != NULL) {
return EEXIST;
} else {
/* getgrgid() was NULL
diff --git a/libmisc/find_new_uid.c b/libmisc/find_new_uid.c
index b3143134..d01f79b1 100644
--- a/libmisc/find_new_uid.c
+++ b/libmisc/find_new_uid.c
@@ -136,7 +136,7 @@ static int check_uid(const uid_t uid,
}
/* Check if the UID exists according to NSS */
errno = 0;
- if (getpwuid(uid) != NULL) {
+ if (prefix_getpwuid(uid) != NULL) {
return EEXIST;
} else {
/* getpwuid() was NULL
diff --git a/libmisc/getdate.y b/libmisc/getdate.y
index ee00ca58..5a8bde2e 100644
--- a/libmisc/getdate.y
+++ b/libmisc/getdate.y
@@ -66,7 +66,7 @@
#endif
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
- as well as gratuitiously global symbol names, so we can have multiple
+ as well as gratuitously global symbol names, so we can have multiple
yacc generated parsers in the same program. Note that these are only
the variables produced by yacc. If other parser generators (bison,
byacc, etc) produce additional global names that conflict at link time,
diff --git a/libmisc/idmapping.c b/libmisc/idmapping.c
index db254fcb..20f2d9c7 100644
--- a/libmisc/idmapping.c
+++ b/libmisc/idmapping.c
@@ -148,7 +148,7 @@ void write_mapping(int proc_dir_fd, int ranges, struct map_range *mappings,
pos += written;
}
- /* Write the mapping to the maping file */
+ /* Write the mapping to the mapping file */
fd = openat(proc_dir_fd, map_file, O_WRONLY);
if (fd < 0) {
fprintf(stderr, _("%s: open of %s failed: %s\n"),
diff --git a/libmisc/pam_pass_non_interractive.c b/libmisc/pam_pass_non_interactive.c
index e50648b6..ded5c69e 100644
--- a/libmisc/pam_pass_non_interractive.c
+++ b/libmisc/pam_pass_non_interactive.c
@@ -134,7 +134,7 @@ failed_conversation:
*
* Return 0 on success, 1 on failure.
*/
-int do_pam_passwd_non_interractive (const char *pam_service,
+int do_pam_passwd_non_interactive (const char *pam_service,
const char *username,
const char* password)
{
diff --git a/libmisc/prefix_flag.c b/libmisc/prefix_flag.c
new file mode 100644
index 00000000..6581235e
--- /dev/null
+++ b/libmisc/prefix_flag.c
@@ -0,0 +1,340 @@
+/*
+ * Copyright (c) 2011 , Julian Pidancet
+ * Copyright (c) 2011 , Nicolas François
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the copyright holders or contributors may not be used to
+ * endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <config.h>
+
+#ident "$Id$"
+
+#include <stdio.h>
+#include <assert.h>
+#include "defines.h"
+#include "prototypes.h"
+/*@-exitarg@*/
+#include "exitcodes.h"
+#include "groupio.h"
+#include "pwio.h"
+#ifdef SHADOWGRP
+#include "sgroupio.h"
+#endif
+#include "shadowio.h"
+#ifdef ENABLE_SUBIDS
+#include "subordinateio.h"
+#endif /* ENABLE_SUBIDS */
+#include "getdef.h"
+
+static char *passwd_db_file = NULL;
+static char *spw_db_file = NULL;
+static char *group_db_file = NULL;
+static char *sgroup_db_file = NULL;
+static char *suid_db_file = NULL;
+static char *sgid_db_file = NULL;
+static char *def_conf_file = NULL;
+static FILE* fp_pwent = NULL;
+static FILE* fp_grent = NULL;
+
+/*
+ * process_prefix_flag - prefix all paths if given the --prefix option
+ *
+ * This shall be called before accessing the passwd, group, shadow,
+ * gshadow, useradd's default, login.defs files (non exhaustive list)
+ * or authenticating the caller.
+ *
+ * The audit, syslog, or locale files shall be open before
+ */
+extern const char* process_prefix_flag (const char* short_opt, int argc, char **argv)
+{
+ /*
+ * Parse the command line options.
+ */
+ int i;
+ const char *prefix = NULL;
+
+ for (i = 0; i < argc; i++) {
+ if ( (strcmp (argv[i], "--prefix") == 0)
+ || (strcmp (argv[i], short_opt) == 0)) {
+ if (NULL != prefix) {
+ fprintf (stderr,
+ _("%s: multiple --prefix options\n"),
+ Prog);
+ exit (E_BAD_ARG);
+ }
+
+ if (i + 1 == argc) {
+ fprintf (stderr,
+ _("%s: option '%s' requires an argument\n"),
+ Prog, argv[i]);
+ exit (E_BAD_ARG);
+ }
+ prefix = argv[i + 1];
+ }
+ }
+
+
+
+ if (prefix != NULL) {
+ if ( prefix[0] == '\0' || !strcmp(prefix, "/"))
+ return ""; /* if prefix is "/" then we ignore the flag option */
+ /* should we prevent symbolic link from being used as a prefix? */
+
+ size_t len;
+ len = strlen(prefix) + strlen(PASSWD_FILE) + 2;
+ passwd_db_file = xmalloc(len);
+ snprintf(passwd_db_file, len, "%s/%s", prefix, PASSWD_FILE);
+ pw_setdbname(passwd_db_file);
+
+ len = strlen(prefix) + strlen(GROUP_FILE) + 2;
+ group_db_file = xmalloc(len);
+ snprintf(group_db_file, len, "%s/%s", prefix, GROUP_FILE);
+ gr_setdbname(group_db_file);
+
+#ifdef SHADOWGRP
+ len = strlen(prefix) + strlen(SGROUP_FILE) + 2;
+ sgroup_db_file = xmalloc(len);
+ snprintf(sgroup_db_file, len, "%s/%s", prefix, SGROUP_FILE);
+ sgr_setdbname(sgroup_db_file);
+#endif
+#ifdef USE_NIS
+ __setspNIS(0); /* disable NIS for now, at least until it is properly supporting a "prefix" */
+#endif
+
+ len = strlen(prefix) + strlen(SHADOW_FILE) + 2;
+ spw_db_file = xmalloc(len);
+ snprintf(spw_db_file, len, "%s/%s", prefix, SHADOW_FILE);
+ spw_setdbname(spw_db_file);
+
+
+ len = strlen(prefix) + strlen("/etc/subuid") + 2;
+ suid_db_file = xmalloc(len);
+ snprintf(suid_db_file, len, "%s/%s", prefix, "/etc/subuid");
+ sub_uid_setdbname(suid_db_file);
+
+ len = strlen(prefix) + strlen("/etc/subgid") + 2;
+ sgid_db_file = xmalloc(len);
+ snprintf(sgid_db_file, len, "%s/%s", prefix, "/etc/subgid");
+ sub_gid_setdbname(sgid_db_file);
+
+ len = strlen(prefix) + strlen("/etc/login.defs") + 2;
+ def_conf_file = xmalloc(len);
+ snprintf(def_conf_file, len, "%s/%s", prefix, "/etc/login.defs");
+ setdef_config_file(def_conf_file);
+ }
+
+ if (prefix == NULL)
+ return "";
+ return prefix;
+}
+
+
+extern struct group *prefix_getgrnam(const char *name)
+{
+ if (group_db_file) {
+ FILE* fg;
+ struct group * grp = NULL;
+
+ fg = fopen(group_db_file, "rt");
+ if(!fg)
+ return NULL;
+ while(grp = fgetgrent(fg)) {
+ if(!strcmp(name, grp->gr_name))
+ break;
+ }
+ fclose(fg);
+ return grp;
+ }
+
+ return getgrnam(name);
+}
+
+extern struct group *prefix_getgrgid(gid_t gid)
+{
+ if (group_db_file) {
+ FILE* fg;
+ struct group * grp = NULL;
+
+ fg = fopen(group_db_file, "rt");
+ if(!fg)
+ return NULL;
+ while(grp = fgetgrent(fg)) {
+ if(gid == grp->gr_gid)
+ break;
+ }
+ fclose(fg);
+ return grp;
+ }
+
+ return getgrgid(gid);
+}
+
+extern struct passwd *prefix_getpwuid(uid_t uid)
+{
+ if (passwd_db_file) {
+ FILE* fg;
+ struct passwd *pwd = NULL;
+
+ fg = fopen(passwd_db_file, "rt");
+ if(!fg)
+ return NULL;
+ while(pwd = fgetpwent(fg)) {
+ if(uid == pwd->pw_uid)
+ break;
+ }
+ fclose(fg);
+ return pwd;
+ }
+ else {
+ return getpwuid(uid);
+ }
+}
+extern struct passwd *prefix_getpwnam(const char* name)
+{
+ if (passwd_db_file) {
+ FILE* fg;
+ struct passwd *pwd = NULL;
+
+ fg = fopen(passwd_db_file, "rt");
+ if(!fg)
+ return NULL;
+ while(pwd = fgetpwent(fg)) {
+ if(!strcmp(name, pwd->pw_name))
+ break;
+ }
+ fclose(fg);
+ return pwd;
+ }
+ else {
+ return getpwnam(name);
+ }
+}
+extern struct spwd *prefix_getspnam(const char* name)
+{
+ if (spw_db_file) {
+ FILE* fg;
+ struct spwd *sp = NULL;
+
+ fg = fopen(spw_db_file, "rt");
+ if(!fg)
+ return NULL;
+ while(sp = fgetspent(fg)) {
+ if(!strcmp(name, sp->sp_namp))
+ break;
+ }
+ fclose(fg);
+ return sp;
+ }
+ else {
+ return getspnam(name);
+ }
+}
+
+extern void prefix_setpwent()
+{
+ if(!passwd_db_file) {
+ setpwent();
+ return;
+ }
+ if (fp_pwent)
+ fclose (fp_pwent);
+
+ fp_pwent = fopen(passwd_db_file, "rt");
+ if(!fp_pwent)
+ return;
+}
+extern struct passwd* prefix_getpwent()
+{
+ if(!passwd_db_file) {
+ return getpwent();
+ }
+ return fgetpwent(fp_pwent);
+}
+extern void prefix_endpwent()
+{
+ if(!passwd_db_file) {
+ endpwent();
+ return;
+ }
+ if (fp_pwent)
+ fclose(fp_pwent);
+ fp_pwent = NULL;
+}
+
+extern void prefix_setgrent()
+{
+ if(!group_db_file) {
+ setgrent();
+ return;
+ }
+ if (fp_grent)
+ fclose (fp_grent);
+
+ fp_grent = fopen(group_db_file, "rt");
+ if(!fp_grent)
+ return;
+}
+extern struct group* prefix_getgrent()
+{
+ if(!group_db_file) {
+ return getgrent();
+ }
+ return fgetgrent(fp_grent);
+}
+extern void prefix_endgrent()
+{
+ if(!group_db_file) {
+ endgrent();
+ return;
+ }
+ if (fp_grent)
+ fclose(fp_grent);
+ fp_grent = NULL;
+}
+
+extern struct group *prefix_getgr_nam_gid(const char *grname)
+{
+ long long int gid;
+ char *endptr;
+
+ if (NULL == grname) {
+ return NULL;
+ }
+
+ if (group_db_file) {
+ errno = 0;
+ gid = strtoll (grname, &endptr, 10);
+ if ( ('\0' != *grname)
+ && ('\0' == *endptr)
+ && (ERANGE != errno)
+ && (gid == (gid_t)gid)) {
+ return prefix_getgrgid ((gid_t) gid);
+ }
+ return prefix_getgrnam (grname);
+ }
+ else
+ return getgr_nam_gid(grname);
+}
diff --git a/libmisc/setupenv.c b/libmisc/setupenv.c
index 8020f3d5..24c6e678 100644
--- a/libmisc/setupenv.c
+++ b/libmisc/setupenv.c
@@ -171,7 +171,7 @@ static void read_env_file (const char *filename)
cp++;
goto d_quote;
}
- eise if (*cp == '\0') {
+ else if (*cp == '\0') {
/* end of string */
goto finished;
} else {
diff --git a/libmisc/strtoday.c b/libmisc/strtoday.c
index 57648984..860f06d4 100644
--- a/libmisc/strtoday.c
+++ b/libmisc/strtoday.c
@@ -126,7 +126,7 @@ static char *date_formats[] = {
#else
/*
* days and juldays are used to compute the number of days in the
- * current month, and the cummulative number of days in the preceding
+ * current month, and the cumulative number of days in the preceding
* months. they are declared so that january is 1, not 0.
*/
static short days[13] = { 0,
diff --git a/libmisc/utmp.c b/libmisc/utmp.c
index c22f31c5..f5614a22 100644
--- a/libmisc/utmp.c
+++ b/libmisc/utmp.c
@@ -88,7 +88,7 @@ static bool is_my_tty (const char *tty)
* session
*
* The utmp file is scanned for an entry with the same process ID.
- * The line enterred by the *getty / telnetd, etc. should also match
+ * The line entered by the *getty / telnetd, etc. should also match
* the current terminal.
*
* When an entry is returned by get_current_utmp, and if the utmp