In a message dated 12/24/2002 11:45:10 AM Eastern Standard Time, [EMAIL PROTECTED] writes:

I'm looking at nsmain.c for the fun of it on Christmas Eve.  I don't
understand the difference in the code between the gid and the uid. It
seems like the gid has to be less than zero before it is converted to an
int using atoi. Then it is compared to zero. In the uid case, the uid is
always compared to zero.

Merry Christmas!

  if (garg != NULL) {
  gid = Ns_GetGid(garg);
  if (gid <0) {
    gid = atoi(garg);
    if (gid == 0) {
      Ns_Fatal("nsmain: invalid group '%s'", garg);
    }
  }
}
if (uarg != NULL) {
  uid = Ns_GetUid(uarg);
  gid = Ns_GetUserGid(uarg);
  if (uid <0) {
    uid = atoi(uarg);
  }
  if (uid == 0) {
    Ns_Fatal("nsmain: invalid user '%s'", uarg);
  }
}




Hmm - I think this is confusing because this 3.5 code looks wrong.  Compare with 4.0 - the gid code comes after the uid code which make sense.  Basically, if a uid is specified with the -u arg, the gid is set to that user's gid by default, possibly to be overridden with an actual -g arg.  The code also handles strings (like user "jimbo") or simple integers which explains the less than zero and equal to zero comparisons (the Ns functions return -1 on invalid user/group, atoi returns 0). 

Happy Holidays, -Jim

Reply via email to