home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
1990
/
08
/
stevens.lst
< prev
next >
Wrap
File List
|
1990-06-20
|
3KB
|
160 lines
_C PROGRAMMING COLUMN_
by Al Stevens
[LISTING ONE]
/* ---------- Display NetWare USERID ---------- */
#include <stdio.h>
#include <nit.h>
char *GetUserid(void);
void main()
{
printf("\nUserid: %s", GetUserid());
}
/*
* Get the current logged on userid
*/
char *GetUserid(void)
{
static char userid[48];
WORD connection_number = GetConnectionNumber();
WORD objecttype;
long objectid;
BYTE logintime[7];
GetConnectionInformation(connection_number, userid,
&objecttype, &objectid, logintime);
return userid;
}
[LISTING TWO]
/* -------- getuser1.c ----------- */
#include <stdio.h>
#include <dos.h>
#include <string.h>
/* ----- request packet for get connection information ----- */
static struct {
int rlen; /* packet length-2 */
char func; /* NW function */
char station; /* station number */
} rqpacket = { 2, 22 };
/* ------ reply buffer for get connection information ----- */
static struct {
int rlen; /* packet length-2 */
long id; /* object id */
int type; /* type of object */
char userid[48]; /* name of object */
char time[8]; /* log on time */
} rsbuffer = { 62 };
char *GetUserid(void);
void main()
{
printf("\nUserid: %s", GetUserid());
}
char *GetUserid(void)
{
union REGS regs;
struct SREGS segs;
segread(&segs);
segs.es = segs.ds;
/* ------- get connection (station) number ------ */
regs.h.ah = 0xdc;
intdosx(®s, ®s, &segs);
rqpacket.station = regs.h.al;
/* ------- get connection information --------- */
regs.x.si = (unsigned) &rqpacket;
regs.x.di = (unsigned) &rsbuffer;
regs.h.ah = 0xe3;
intdosx(®s, ®s, &segs);
return rsbuffer.userid;
}
[LISTING THREE]
/* -------------- showusrs.c ---------------- */
#include <stdio.h>
#include <nit.h>
#include <niterror.h>
static long objid;
char *getusers(void);
void main()
{
char *userid;
objid = -1;
while ((userid = getusers()) != NULL)
printf("\n%s", userid);
}
/* ---------- scan bindery for users ------------- */
char *getusers(void)
{
static char name[48];
char hasproperties, flag, security;
WORD type;
if (ScanBinderyObject("*", OT_USER, &objid, name, &type,
&hasproperties, &flag, &security) == SUCCESSFUL)
return name;
return NULL;
}
[LISTING FOUR]
/* --------------- nwloaded.c ------------ */
#include <stdio.h>
#include <dos.h>
int NetworkLoaded(void);
void main()
{
printf("\nThe network %s operating",
NetworkLoaded() ? "is" : "is not");
}
#define encr(lm) (0-(~(0-lm)))
/* ------- test network operating ----------- */
int NetworkLoaded(void)
{
int lockmode, encrypted;
union REGS regs;
regs.x.ax = 0xc600;
intdos(®s, ®s);
lockmode = regs.h.al;
encrypted = encr(lockmode);
regs.h.ah = 0xc6;
regs.h.al = encrypted;
intdos(®s, ®s);
lockmode = regs.h.al;
return encrypted != encr(lockmode);
}