home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / USERINFO.ZIP / USERINFO.C next >
Text File  |  1990-10-17  |  4KB  |  114 lines

  1. /*      function  uinfo           Get user information
  2.  
  3.         purpose   To retrieve the domain name, userid, computername,
  4.                   and user comment for the current network user.
  5.  
  6.         note      This program is set up as both a standalone program
  7.                   and a function.  The default when compiling is to
  8.                   generate a function, to compile for standalone use
  9.                   define the macro variable MPROG.
  10.  
  11.         arguments
  12.  
  13.         name                  type    i/o   description
  14.         domain                char**  O     A pointer to the newly
  15.                                             allocated buffer containing
  16.                                             the name of the domain.
  17.         machine               char**  O     A pointer to the newly
  18.                                             allocated buffer containing
  19.                                             the name of the local computer.
  20.         userid                char**  O     A pointer to the newly
  21.                                             allocated buffer containing
  22.                                             the current userid.
  23.         username              char**  O     A pointer to the newly
  24.                                             allocated buffer containing
  25.                                             the user description field
  26.                                             (usually their name).
  27. */
  28. #define INCL_BASE
  29. #include <os2.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <memory.h>
  34. #include <neterr.h>
  35. #include <netcons.h>
  36. #include <wksta.h>
  37. #include <access.h>
  38. #include <util.h>
  39.  
  40.  
  41. #if defined(MPROG)
  42. int main ()
  43.   {
  44.     char        *domain;
  45.     char        *machine;
  46.     char        *userid;
  47.     char        *username;
  48. #else
  49. #define   domain (*domain_)
  50. #define   machine (*machine_)
  51. #define   userid (*userid_)
  52. #define   username (*username_)
  53. int uinfo (char **domain_,
  54.            char **machine_,
  55.            char **userid_,
  56.            char **username_)
  57.   {
  58. #endif
  59.     int         rc=0;
  60.     SHORT       level;
  61.     USHORT      buflen;
  62.     USHORT      totalavail;
  63.     CHAR        *servername;
  64.     CHAR far    *buf;
  65.     struct wksta_info_10 far *info_a;
  66.     struct user_info_2 far *info_b;
  67.  
  68.     servername = "\0";
  69.     level = 10;
  70.     buflen = 0;
  71.  
  72.     rc = NetWkstaGetInfo (servername, level, buf, buflen, &totalavail);
  73.     buflen = totalavail;
  74.     buf = (CHAR far *) malloc (buflen);
  75.     rc = NetWkstaGetInfo (servername, level, buf, buflen, &totalavail);
  76.     info_a = (struct wksta_info_10 far *) buf;
  77.     domain = strdup (info_a->wki10_logon_domain);
  78.     machine= strdup (info_a->wki10_computername);
  79.     userid = strdup (info_a->wki10_username);
  80. #if defined(MPROG)
  81.     printf ("   Domain: \"%s\"\n", domain);
  82.     printf ("  Machine: \"%s\"\n", machine);
  83.     printf ("   Userid: \"%s\"\n", userid);
  84. #endif
  85.     buflen = 0;
  86.     level = 2;
  87.     rc = NetUserGetInfo (servername,
  88.                          userid,
  89.                          level,
  90.                          buf,
  91.                          buflen,
  92.                          &totalavail);
  93.     buflen = totalavail;
  94.     buf = realloc (buf, buflen);
  95.     rc = NetUserGetInfo (servername,
  96.                          userid,
  97.                          level,
  98.                          buf,
  99.                          buflen,
  100.                          &totalavail);
  101.     info_b = (struct user_info_2 far *) buf;
  102.     username = strdup (info_b->usri2_usr_comment);
  103.  
  104. #if defined(MPROG)
  105.     printf ("User name: \"%s\"\n", username);
  106. #endif
  107.  
  108. #if defined(MPROG)
  109.     exit (rc);
  110. #else
  111.     return (rc);
  112. #endif
  113.   }
  114.