home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Black Box 4
/
BlackBox.cdr
/
lan
/
lanutsrc.arj
/
FINDUSER.C
< prev
next >
Wrap
Text File
|
1991-03-13
|
6KB
|
209 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dos.h>
#include <direct.h>
#include <conio.h>
#include "lantasti.h"
#define DOS 0x21
#define NETBIOS 0x5C
#define DELIM "+, "
/* structure to allow easy access to both segment and offset portions of
far pointers */
#define LIST_SIZE 50
#define NAME_SIZE 20
typedef struct LIST {
int num_servers;
char server[LIST_SIZE][NAME_SIZE];
} LIST;
char found;
/* definitions to save typing time */
#define C_SERVER list->server[i % list->num_servers]
/***********************************************************************
Delete leading and trailing blanks.
***********************************************************************/
void dltb(string)
char *string;
{
int i;
i = strspn(string, " ");
if (i) strcpy(string,string + i);
i = strlen(string) - 1;
while (i && (string[i] == ' ')) {
string[i--] = '\0';
}
}
/* getstring ********************************************************************
Get a string from the console -- takes a pointer to a string buffer, the
longest permissible length and two switches. The empty switch determines
whether or not the user is allowed to enter an empty string. If TRUE, he
can, if FALSE, he must enter something. The shown switch determines
whether or not input is echoed to the screen, TRUE if echoed, FALSE if
invisible
*****************************************************************************/
void getstring(prompt,buffer,length,empty,shown)
char *prompt,*buffer;
int length,empty,shown;
{
fprintf(stdout,"%s",prompt);
fgets(buffer,length,stdin);
if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0;
while (!(strlen(buffer) || empty)) {
fprintf(stdout,"%s",prompt);
fgets(buffer,length,stdin);
if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0;
}
}
/* error ********************************************************************
Traps for system errors and prints a happy message.
*****************************************************************************/
void error(code,message)
int code;
char *message;
{
char *ptr;
if (code) {
ptr = get_error_text(code);
puts(ptr);
}
else puts(message);
}
/* get_active_servers ********************************************************************
Gets a list of the active servers.
*****************************************************************************/
void get_active_servers(list)
LIST *list;
{
char buffer[17];
int index,result;
index = 0;
/* pull in the name of a server */
while ((result = get_active_server(buffer,index++))) {
sprintf(list->server[list->num_servers++],"\\\\%s",buffer);
/* only allow a reasonable number of servers */
if (list->num_servers >= LIST_SIZE) {
puts("Warning: Too many servers. Only the first 50 can be used.");
break;
}
}
}
void display_help() {
puts("FINDUSER utility for LANtastic -- Copyright 1989 by SoftMagic, Inc.");
puts("All rights reserved. LANtastic is a trademark of Artisoft, Inc.\n");
puts("Usage: FINDUSER <user name(s)> [/OPTIONS]");
puts(" A question mark in the list causes the program to prompt the user");
puts(" for input. FINDUSER with no arguments will display help.");
puts("Available options are:");
puts("/HELP - display this documentation");
exit(0);
}
/* scan_command_line ********************************************************************
Scans the command line for /options like HELP. Doesn't do anything else.
*****************************************************************************/
scan_command_line(argc,argv)
int argc;
char *argv[];
{
int i;
/* for each argument */
if (argc < 2) {
display_help();
exit(0);
}
for (i = 1;i < argc; i++) {
/* convert to upper case and see if it exists */
strupr(argv[i]);
if (argv[i] !=NULL) {
/* if it's /HELP, run our happy message */
if (!strcmp(argv[i],"/HELP")) {
display_help();
break;
}
}
}
}
/* do_userlist ********************************************************************
Breaks apart the names and checks them against the list of logged in folks.
Prints its answer.
*****************************************************************************/
int do_finduser(list,username)
LIST *list;
char *username;
{
int result,i,j;
char *ptr;
ACTIVE_USER user;
if (username[0] == '?')
getstring("User name(s): ",username,80,FALSE,TRUE);
/* no matter what else happens, break off a name and check it */
ptr = strtok(username,DELIM);
while (ptr != NULL) {
for (i = 0; i < list->num_servers; i++) {
j = 0;
dltb(list->server[i]);
while (!(result = (get_user_info(list->server[i],j++,&user)))) {
dltb(user.name);
if (!strcmpi(ptr,user.name)) {
found = TRUE;
dltb(user.machine);
printf(" %s on machine %s is logged into server %s.\n",ptr,user.machine,list->server[i]);
break;
}
}
}
if (!found) printf("User %s is not logged in.\n",ptr);
found = FALSE;
ptr = strtok(NULL,DELIM);
}
}
/* main ********************************************************************
*****************************************************************************/
int main(argc,argv)
int argc;
char *argv[];
{
LIST list; /*server, user and password lists*/
int i;
char username[80];
/* scan for /HELP option */
found = FALSE;
scan_command_line(argc,argv);
/* fetch list of servers -- we assume you want to know for all */
list.num_servers = 0;
get_active_servers(&list);
/* if there aren't any servers, bomb out. */
if (list.num_servers <= 0) {
error(FALSE,"You are not logged in to any servers.");
return(0);
}
/* otherwise, for each name, see if they're logged in and where. */
for (i = 1; i < argc; i++)
do_finduser(&list,argv[i]);
/* outta there */
return(0);
}