home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1990 / 08 / stevens.lst < prev    next >
File List  |  1990-06-20  |  3KB  |  160 lines

  1. _C PROGRAMMING COLUMN_
  2. by Al Stevens
  3.  
  4. [LISTING ONE]
  5.  
  6. /* ---------- Display NetWare USERID ---------- */
  7. #include <stdio.h>
  8. #include <nit.h>
  9.  
  10. char *GetUserid(void);
  11.  
  12. void main()
  13. {
  14.     printf("\nUserid: %s", GetUserid());
  15. }
  16.  
  17. /*
  18.  * Get the current logged on userid
  19.  */
  20.  
  21. char *GetUserid(void)
  22. {
  23.     static char userid[48];
  24.     WORD connection_number = GetConnectionNumber();
  25.     WORD objecttype;
  26.     long objectid;
  27.     BYTE logintime[7];
  28.  
  29.     GetConnectionInformation(connection_number, userid,
  30.                     &objecttype, &objectid, logintime);
  31.     return userid;
  32. }
  33.  
  34.  
  35. [LISTING TWO]
  36.  
  37. /* -------- getuser1.c ----------- */
  38.  
  39. #include <stdio.h>
  40. #include <dos.h>
  41. #include <string.h>
  42.  
  43. /* ----- request packet for get connection information ----- */
  44. static struct {
  45.     int  rlen;            /* packet length-2  */
  46.     char func;            /* NW function      */
  47.     char station;         /* station number   */
  48. } rqpacket = { 2, 22 };
  49.  
  50. /* ------ reply buffer for get connection information ----- */
  51. static struct {
  52.     int rlen;            /* packet length-2  */
  53.     long id;             /* object id        */
  54.     int type;            /* type of object   */
  55.     char userid[48];     /* name of object   */
  56.     char time[8];        /* log on time      */
  57. } rsbuffer = { 62 };
  58.  
  59. char *GetUserid(void);
  60.  
  61. void main()
  62. {
  63.     printf("\nUserid: %s", GetUserid());
  64. }
  65.  
  66. char *GetUserid(void)
  67. {
  68.     union REGS regs;
  69.     struct SREGS segs;
  70.  
  71.     segread(&segs);
  72.     segs.es = segs.ds;
  73.     /* ------- get connection (station) number ------ */
  74.     regs.h.ah = 0xdc;
  75.     intdosx(®s, ®s, &segs);
  76.     rqpacket.station = regs.h.al;
  77.     /* ------- get connection information --------- */
  78.     regs.x.si = (unsigned) &rqpacket;
  79.     regs.x.di = (unsigned) &rsbuffer;
  80.     regs.h.ah = 0xe3;
  81.     intdosx(®s, ®s, &segs);
  82.     return rsbuffer.userid;
  83. }
  84.  
  85.  
  86. [LISTING THREE]
  87.  
  88. /* -------------- showusrs.c ---------------- */
  89.  
  90. #include <stdio.h>
  91. #include <nit.h>
  92. #include <niterror.h>
  93.  
  94. static long objid;
  95.  
  96. char *getusers(void);
  97.  
  98. void main()
  99. {
  100.     char *userid;
  101.     objid = -1;
  102.     while ((userid = getusers()) != NULL)
  103.         printf("\n%s", userid);
  104. }
  105.  
  106. /* ---------- scan bindery for users ------------- */
  107. char *getusers(void)
  108. {
  109.     static char name[48];
  110.     char hasproperties, flag, security;
  111.     WORD type;
  112.  
  113.     if (ScanBinderyObject("*", OT_USER, &objid, name, &type,
  114.                &hasproperties, &flag, &security) == SUCCESSFUL)
  115.         return name;
  116.     return NULL;
  117. }
  118.  
  119.  
  120.  
  121. [LISTING FOUR]
  122.  
  123. /* --------------- nwloaded.c ------------ */
  124.  
  125. #include <stdio.h>
  126. #include <dos.h>
  127.  
  128. int NetworkLoaded(void);
  129.  
  130. void main()
  131. {
  132.     printf("\nThe network %s operating",
  133.             NetworkLoaded() ? "is" : "is not");
  134. }
  135.  
  136. #define encr(lm) (0-(~(0-lm)))
  137.  
  138. /* ------- test network operating ----------- */
  139. int NetworkLoaded(void)
  140. {
  141.     int lockmode, encrypted;
  142.     union REGS regs;
  143.  
  144.     regs.x.ax = 0xc600;
  145.     intdos(®s, ®s);
  146.     lockmode = regs.h.al;
  147.  
  148.     encrypted = encr(lockmode);
  149.  
  150.     regs.h.ah = 0xc6;
  151.     regs.h.al = encrypted;
  152.     intdos(®s, ®s);
  153.     lockmode = regs.h.al;
  154.  
  155.     return encrypted != encr(lockmode);
  156. }
  157.  
  158.  
  159.  
  160.