* 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.
+ *
+ * $Id$
*/
#ifndef lint
#include <pw_util.h>
#include "chpass.h"
+#ifdef YP
+#include "pw_yp.h"
+#endif /* YP */
extern char *tempname;
pw_error(tempname, 1, 1);
(void)fprintf(fp,
+#ifdef YP
+ "#Changing %s information for %s.\n", _use_yp ? "NIS" : "user database", pw->pw_name);
+ if (!uid && (!_use_yp || suser_override)) {
+#else
"#Changing user database information for %s.\n", pw->pw_name);
if (!uid) {
+#endif /* YP */
(void)fprintf(fp, "Login: %s\n", pw->pw_name);
(void)fprintf(fp, "Password: %s\n", pw->pw_passwd);
(void)fprintf(fp, "Uid [#]: %d\n", pw->pw_uid);
*pw->pw_shell ? pw->pw_shell : _PATH_BSHELL);
}
/* Only admin can change "restricted" shells. */
+#ifdef 0
else if (ok_shell(pw->pw_shell))
/*
* Make shell a restricted field. Ugly with a
* necklace, but there's not much else to do.
*/
+#else
+ else if ((!list[E_SHELL].restricted && ok_shell(pw->pw_shell)) || !uid)
+ /*
+ * If change not restrict (table.c) and standard shell
+ * OR if root, then allow editing of shell.
+ */
+#endif
(void)fprintf(fp, "Shell: %s\n",
*pw->pw_shell ? pw->pw_shell : _PATH_BSHELL);
else
list[E_NAME].save = strdup(p);
if (!list[E_NAME].restricted || !uid)
(void)fprintf(fp, "Full Name: %s\n", p ? p : "");
-
+
p = strsep(&bp, ",");
if (p)
list[E_LOCATE].save = strdup(p);
if (!list[E_LOCATE].restricted || !uid)
(void)fprintf(fp, "Location: %s\n", p ? p : "");
-
+
p = strsep(&bp, ",");
if (p)
list[E_BPHONE].save = strdup(p);
if (!list[E_BPHONE].restricted || !uid)
(void)fprintf(fp, "Office Phone: %s\n", p ? p : "");
-
+
p = strsep(&bp, ",");
if (p)
list[E_HPHONE].save = strdup(p);
char *p;
struct stat sb;
FILE *fp;
- int len;
- char buf[LINE_MAX];
+ int len, line;
+ static char buf[LINE_MAX];
if (!(fp = fopen(tempname, "r")))
pw_error(tempname, 1, 1);
warnx("corrupted temporary file");
goto bad;
}
+ line = 0;
while (fgets(buf, sizeof(buf), fp)) {
+ line++;
if (!buf[0] || buf[0] == '#')
continue;
if (!(p = strchr(buf, '\n'))) {
- warnx("line too long");
+ warnx("line %d too long", line);
goto bad;
}
*p = '\0';
for (ep = list;; ++ep) {
if (!ep->prompt) {
- warnx("unrecognized field");
+ warnx("unrecognized field on line %d", line);
goto bad;
}
if (!strncasecmp(buf, ep->prompt, ep->len)) {
goto bad;
}
if (!(p = strchr(buf, ':'))) {
- warnx("line corrupted");
+ warnx("line %d corrupted", line);
goto bad;
}
while (isspace(*++p));
(void)sprintf(pw->pw_gecos = p, "%s,%s,%s,%s", list[E_NAME].save,
list[E_LOCATE].save, list[E_BPHONE].save, list[E_HPHONE].save);
+ while ((len = strlen(pw->pw_gecos)) && pw->pw_gecos[len - 1] == ',')
+ pw->pw_gecos[len - 1] = '\0';
+
if (snprintf(buf, sizeof(buf),
"%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s",
pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid, pw->pw_class,
pw->pw_change, pw->pw_expire, pw->pw_gecos, pw->pw_dir,
pw->pw_shell) >= sizeof(buf)) {
warnx("entries too long");
+ free(p);
return (0);
}
+ free(p);
return (pw_scan(buf, pw));
}