* 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: edit.c,v 1.12 1998/12/06 22:58:14 archie Exp $
*/
#ifndef lint
-static char sccsid[] = "@(#)edit.c 8.3 (Berkeley) 4/2/94";
+static const char sccsid[] = "@(#)edit.c 8.3 (Berkeley) 4/2/94";
#endif /* not lint */
#include <sys/param.h>
"#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)
+ "#Changing user database information for %s.\n", pw->pw_name);
if (!uid) {
#endif /* YP */
(void)fprintf(fp, "Login: %s\n", pw->pw_name);
if (p)
list[E_LOCATE].save = strdup(p);
if (!list[E_LOCATE].restricted || !uid)
- (void)fprintf(fp, "Location: %s\n", p ? p : "");
+ (void)fprintf(fp, "Office Location: %s\n", p ? p : "");
p = strsep(&bp, ",");
if (p)
if (!list[E_HPHONE].restricted || !uid)
(void)fprintf(fp, "Home Phone: %s\n", p ? p : "");
+ if (bp!=NULL)
+ list[E_OTHER].save = strdup(bp);
+ if (!list[E_OTHER].restricted || !uid)
+ (void)fprintf(fp, "Other information: %s\n", bp ? bp : "");
+
(void)fchown(fd, getuid(), getgid());
(void)fclose(fp);
}
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));
/* Build the gecos field. */
len = strlen(list[E_NAME].save) + strlen(list[E_BPHONE].save) +
- strlen(list[E_HPHONE].save) + strlen(list[E_LOCATE].save) + 4;
+ strlen(list[E_HPHONE].save) + strlen(list[E_LOCATE].save) +
+ strlen(list[E_OTHER].save) + 4;
if (!(p = malloc(len)))
err(1, NULL);
- (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);
+ (void)sprintf(pw->pw_gecos = p, "%s,%s,%s,%s,%s", list[E_NAME].save,
+ list[E_LOCATE].save, list[E_BPHONE].save, list[E_HPHONE].save,
+ list[E_OTHER].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_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));
}