Logo Search packages:      
Sourcecode: pwlib version File versions

PString PProcess::GetUserName (  )  const [inherited]

Get the effective user name of the owner of the process, eg "root" etc. This is a platform dependent string only provided by platforms that are multi-user. Note that some value may be returned as a "simulated" user. For example, in MS-DOS an environment variable

Returns:
user name of processes owner.

Definition at line 362 of file doswin.cxx.

Referenced by PVideoInputDevice_FakeVideo::GrabTextVideoFrame().

{
  /* ----- Microsoft LAN Manager, Windows for Workgroups, IBM LAN Server ----- */
#pragma pack(1)
  static struct {
    char _far *computername;
    char _far *username;
    char _far *langroup;
    unsigned char ver_major;
    unsigned char ver_minor;
    char _far *logon_domain;
    char _far *oth_domains;
    char filler[32];
  } NEAR wksta;
#pragma pack()

  union REGS r;
  r.x.ax = 0x5F44;
  r.x.bx = 10;
  r.x.cx = sizeof(wksta);
  r.x.di = (WORD)&wksta;

  struct SREGS sregs;
  segread(&sregs);
  sregs.es = sregs.ds;
  int86x(0x21, &r, &r, &sregs);
  if (r.x.ax == 0 || r.x.ax == 0x5F44) {
    char name[32];
    strcpy(name, wksta.username);
    strlwr(name);
    return name;
  }


  /* ----- Novell NetWare ----- Get Connection Information E3(16) */

#pragma pack(1)
  static struct {
    unsigned short len;
    unsigned char func;
    unsigned char number;
  } NEAR gcireq;
  
  static struct {
    unsigned short len;
    unsigned long objectID;
    unsigned short objecttype;
    char objectname[48];
    unsigned char logintime[7];
    unsigned char reserved[39];
  } NEAR gcirep;
#pragma pack()

  /* Load Get Connection Number function code.   */
  r.x.ax = 0xDC00;
  int86x(0x21, &r, &r, &sregs);
  if (r.h.al > 0 && r.h.al <= 100) {
    /* If the connection number is in range 1-100,
     * invoke Get Connection Information to get the user name. */

    gcireq.len = sizeof(gcireq) - sizeof(gcireq.len);
    gcireq.func = 0x16;
    gcireq.number = r.h.al;
    gcirep.len = sizeof(gcirep) - sizeof(gcirep.len);

    r.h.ah = 0xE3;
    r.x.si = (unsigned short) &gcireq;
    r.x.di = (unsigned short) &gcirep;
    int86x(0x21, &r, &r, &sregs);
    if (r.h.al == 0) {
      strlwr(gcirep.objectname);
      return gcirep.objectname;
    }
  }


  /* Give up and use environment variables */
  const char * username = getenv("LOGNAME");
  if (username == NULL) {
    username = getenv("USER");
    if (username == NULL)
      username = "";
  }
  
  PAssert(*username != '\0', "Cannot determine user name, set LOGNAME.");
  return username;
}


Generated by  Doxygen 1.6.0   Back to index