X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:references:message-id:date:from:reply-to :subject:to:in-reply-to:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=syF4zF5ZJhZ0cGMx 3s7XySege/32sPA+OfeCk4idkF9DuTw8q3GCeOzYigBqNqpVc51qjZLdTGe1n1LF FRe8o5zpy79P8f2T31CGJD02p4H7VxYFJ60VPt5YjF/6suPfpwTs4jtmYIQdOmzy gEt50sYMaQe45Y+aJLvwqf/w76s= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:references:message-id:date:from:reply-to :subject:to:in-reply-to:mime-version:content-type :content-transfer-encoding; s=default; bh=1XVpUUpCaMmWx3Cs3MjjNA muE0c=; b=UsysgpPZwSb6HdrG8pGeIM2zJVbesoLBJhziyo84JK9badagBmM8Je WHaVkgawyPw8e1ihTR0aq1OCKfOnBsa81J/z+f2O4h68riDUBvS+lTQd8x4NQ+cr X+A1ZTniulBUqePzIXBOLd+hus3Kp013QxFE6o0mWkEhs9DoG+zPU= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.7 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,FREEMAIL_REPLYTO_END_DIGIT,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,SPF_PASS autolearn=no version=3.3.2 X-HELO: nm34-vm5.bullet.mail.bf1.yahoo.com References: <1397248059 DOT 12764 DOT YahooMailNeo AT web140001 DOT mail DOT bf1 DOT yahoo DOT com> Message-ID: <1397248902.21653.YahooMailNeo@web140004.mail.bf1.yahoo.com> Date: Fri, 11 Apr 2014 13:41:42 -0700 (PDT) From: q q Reply-To: q q Subject: Two problems getting user and group info from /etc/{passwd,group} To: "cygwin AT cygwin DOT com" In-Reply-To: <1397248059.12764.YahooMailNeo@web140001.mail.bf1.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id s3BKfwGh008707 Dear Cygwin developers, Can you please take a look? - We came across a couple problems (times two, because they're identical for /etc/group as well): 1.  When '/etc/passwd' gets reloaded, it can't add the last (default) line for uid=-1 because pretty_ls[] has already been parsed (':'s replaced with '\0'), and can't be parsed again. 2.  When there's fork(), a fresh copy of the pretty_ls seems to be loaded, which does not have '\0's in place of ':'s, while the parsed addressed are kept on heap and are still valid. NOTE.  The default entry (uid=-1) is needed in case when code runs from a service account(NT SERVICE\...), which can't map to any POSIX UID/GID, so they fail back to -1. The exposition is below, for each bug (WARNING: BUG1 will cause /etc/passwd to be "touch"ed): $ gcc -DBUG1 pwd.c $ ./a.exe pw_name   = (0x6118ad2c)???????? pw_passwd = (0x6118ad35)* pw_uid    = 4294967295 pw_gid    = 4294967295 pw_gecos  = (0x6118ad3d) pw_dir    = (0x6118ad3e) pw_shell  = (0x6118ad3f) pwd = NULL $ gcc -DBUG2 pwd.c $ ./a.exe pw_name   = (0x6118ad2c)???????? pw_passwd = (0x6118ad35)* pw_uid    = 4294967295 pw_gid    = 4294967295 pw_gecos  = (0x6118ad3d) pw_dir    = (0x6118ad3e) pw_shell  = (0x6118ad3f) pw_name   = (0x6118ad2c)????????:*:-1:-1::: pw_passwd = (0x6118ad35)*:-1:-1::: pw_uid    = 4294967295 pw_gid    = 4294967295 pw_gecos  = (0x6118ad3d):: pw_dir    = (0x6118ad3e): pw_shell  = (0x6118ad3f) Best regards, Q. --------------------------------------- #include #include #include #include #include #include #include #include #include //#define BUG1 //#define BUG2 static void s_GetPwUid(uid_t uid) {     const struct passwd* pwd = getpwuid(uid);     if (pwd) {         printf("pw_name   = (%p)%s\n"                 "pw_passwd = (%p)%s\n"                 "pw_uid    = %u\n"                 "pw_gid    = %u\n"                 "pw_gecos  = (%p)%s\n"                 "pw_dir    = (%p)%s\n"                 "pw_shell  = (%p)%s\n\n",                 pwd->pw_name,   pwd->pw_name   ? pwd->pw_name   : "NULL",                 pwd->pw_passwd, pwd->pw_passwd ? pwd->pw_passwd : "NULL",                 (unsigned int) pwd->pw_uid,                 (unsigned int) pwd->pw_gid,                 pwd->pw_gecos,  pwd->pw_gecos  ? pwd->pw_gecos  : "NULL",                 pwd->pw_dir,    pwd->pw_dir    ? pwd->pw_dir    : "NULL",                 pwd->pw_shell, pwd->pw_shell   ? pwd->pw_shell  : "NULL");     } else {       printf("pwd = NULL\n\n");     } } int main(void) {     s_GetPwUid(-1); #ifdef BUG1     {     time_t t;     struct timeval tv[2];     sleep(2);     t = time(0);     memset(tv, 0, sizeof(tv));     tv[0].tv_sec = t;     tv[1].tv_sec = t;     utimes("/etc/passwd", tv);     s_GetPwUid(-1);     } #endif #ifdef BUG2     if (fork())        return 0;     s_GetPwUid(-1); #endif     return 0; } -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple