- while (!found) {
- int i = 0;
- memset(line, 0, sizeof(line));
- while (i<(sizeof(line)-1)) {
- if (read(fd, &line[i], 1) != 1) {
- memset(line, 0, sizeof(line));
- close(fd);
- return 0;
- }
- if (line[i] == '\r') continue;
- if (line[i] == '\n') break;
- i++;
+ if (*user == '#') {
+ /* Reject attempt to match a comment. */
+ close(fd);
+ return 0;
+ }
+
+ /* Try to find a line that starts with the user name and a ':'. */
+ p = user;
+ while (1) {
+ if (read(fd, &ch, 1) != 1) {
+ close(fd);
+ return 0;
+ }
+ if (ch == '\n')
+ p = user;
+ else if (p) {
+ if (*p == ch)
+ p++;
+ else if (!*p && ch == ':')
+ break;
+ else
+ p = NULL;