int main(int argc, char *argv[]) {
	NWDSCCODE dserr;
	NWDSContextHandle ctx;
	NWCONN_HANDLE conn;

	const char* context = "[Root]";
        const char * server=NULL;
        const char *  scanFilter="*";

        int allTrees=1;

	int opt;
	u_int32_t ctxflag = 0;
	u_int32_t confidence = 0;


         long err;

#ifndef N_PLAT_MSW4
	setlocale(LC_ALL, "");
	bindtextdomain(NCPFS_PACKAGE, LOCALEDIR);
	textdomain(NCPFS_PACKAGE);
#endif

	progname = argv[0];

	NWCallsInit(NULL, NULL);
#ifndef N_PLAT_MSW4
	NWDSInitRequester();
#endif

	dserr = NWDSCreateContextHandle(&ctx);
	if (dserr) {
		fprintf(stderr, "NWDSCreateContextHandle failed with %s\n", strnwerror(dserr));
		return 123;
	}
	while ((opt = getopt(argc, argv, "h?c:v:S:C:F:f:a")) != EOF)
	{
		switch (opt)
		{
		case 'C':
			confidence = strtoul(optarg, NULL, 0);
			break;
		case 'c':
			context = optarg;
			break;
         	case 'a':
		        allTrees=0;
			break;

		case 'v':
			ctxflag = strtoul(optarg, NULL, 0);
			break;
		case 'h':
		case '?':
			help();
			goto finished;
		case 'S':
			server = optarg;
			break;
                case 'F':
                case 'f':
                 scanFilter =optarg; break;
        	default:
		  usage();
		  goto finished;
		}
	}


	ctxflag |= DCV_XLATE_STRINGS;

	dserr = NWDSSetContext(ctx, DCK_FLAGS, &ctxflag);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_FLAGS) failed: %s\n",
			strnwerror(dserr));
		return 123;
	}
	dserr = NWDSSetContext(ctx, DCK_NAME_CONTEXT, context);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_NAME_CONTEXT) failed: %s\n",
			strnwerror(dserr));
                err = 122;
		goto closing_ctx;
	}
	dserr = NWDSSetContext(ctx, DCK_CONFIDENCE, &confidence);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_CONFIDENCE) failed: %s\n",
			strnwerror(dserr));
                err=121;
		goto closing_ctx;
	}
#ifndef N_PLAT_MSW4
	{
		static const u_int32_t add[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
		dserr = NWDSSetTransport(ctx, 16, add);
		if (dserr) {
			fprintf(stderr, "NWDSSetTransport failed: %s\n",
				strnwerror(dserr));
			err= 124;
                        goto closing_ctx;
		}
	}
#endif

#ifdef N_PLAT_MSW4
	dserr = NWDSOpenConnToNDSServer(ctx, server, &conn);
#else
         {
               conn=ncp_initialize(&argc,argv,0,&err); /* no login required*/
               if (!conn) {
		 fprintf(stderr, "ncp_initialize failed with %s\n",strnwerror(err));
		err= 111;
                goto closing_ctx;
                }
        }
	dserr = NWDSAddConnection(ctx, conn);

#endif

	if (dserr) {
		fprintf(stderr, "failed: Cannot bind connection to context: %s\n",
			strnwerror(dserr));
                err=dserr;
                goto closing_all;

        }

// testing code goes here
        {
#define NB 64

        nuint32 i,cnt,totTrees;
        char* table[NB];
        char * nextBlock;
        for (i=0;i<NB;i++) {
	  table[i]=(char *)malloc (MAX_TREE_NAME_CHARS);
          if (!table[i]) {
                fprintf(stderr, "failed: out of memory\n");

          }
        }

        if (allTrees) {
                /* request a count only*/
                err=NWDSReturnBlockOfAvailableTrees (ctx,conn,scanFilter,NULL,NULL,0,NULL,NULL,&totTrees);
                if (err) {
	                fprintf(stderr, "NWDSReturnBlockOfAvailableTres failed: %s\n",strnwerror(err));
                        goto closing_all;
                }

                nextBlock=NULL;
                do {
                        if (totTrees >NB)
                                totTrees=NB;
                        err=NWDSReturnBlockOfAvailableTrees (ctx,conn,scanFilter,nextBlock,NULL,totTrees,table,&cnt,&totTrees);
                        if (err) {
	                        fprintf(stderr, "NWDSReturnBlockOfAvailableTrees failed: %s\n",strnwerror(err));
                                goto closing_all;
                        }

                        for (i=0; i<cnt;i++) {
                                printf( "%s\n",table[i]);
                         }
                        nextBlock=table[cnt-1];
                } while (cnt);
       }else {
                err=NWDSScanConnsForTrees (ctx,NB,&totTrees,table);
                if (err) {
	                fprintf(stderr, "NWDSScanConnsForTreesfailed: %s\n",strnwerror(err));
                        goto closing_all;
                }
                for (i=0; i<totTrees;i++) {
                                printf( "%s\n",table[i]);
                }


       }
/* end of test block*/
}

err=0;

closing_all:
	NWCCCloseConn(conn);
closing_ctx:
	dserr = NWDSFreeContext(ctx);
	if (dserr) {
		fprintf(stderr, "NWDSFreeContext failed with %s\n", strnwerror(dserr));
		return 121;
	}
finished:
	return err;
}
예제 #2
0
int main(int argc, char *argv[]) {
	NWDSCCODE dserr;
	NWDSContextHandle ctx;
	NWCONN_HANDLE conn;
	const char* objectname = "[Root]";
	const char* context = "OrgUnit.Org.Country";
	const char* server = "CDROM";
	const char* pwd = "TEST";
	int opt;
	int raw = 0;
	int ret = 2;
	u_int32_t ctxflag = 0;
	u_int32_t confidence = 0;

#ifndef N_PLAT_MSW4
	setlocale(LC_ALL, "");
	bindtextdomain(NCPFS_PACKAGE, LOCALEDIR);
	textdomain(NCPFS_PACKAGE);
#endif

	progname = argv[0];

	NWCallsInit(NULL, NULL);
#ifndef N_PLAT_MSW4
	NWDSInitRequester();
#endif

	dserr = NWDSCreateContextHandle(&ctx);
	if (dserr) {
		fprintf(stderr, "NWDSCretateContextHandle failed with %s\n", strnwerror(dserr));
		return 123;
	}
	while ((opt = getopt(argc, argv, "h?o:c:v:S:C:P:r")) != EOF)
	{
		switch (opt)
		{
		case 'C':
			confidence = strtoul(optarg, NULL, 0);
			break;
		case 'o':
			objectname = optarg;
			break;
		case 'c':
			context = optarg;
			break;
		case 'P':
			pwd = optarg;
			break;
		case 'v':
			ctxflag = strtoul(optarg, NULL, 0);
			break;
		case 'h':
		case '?':
			help();
			goto finished;
		case 'S':
			server = optarg;
			break;
		case 'r':
			raw = 1;
			break;
		default:
			usage();
			goto finished;
		}
	}

	if (!raw) {
		char* p;
		char c;

		for (p = pwd; (c = *p) != 0; p++) {
			if (islower(c))
				*p = toupper(c);
		}
	}

	ctxflag |= DCV_XLATE_STRINGS;
	
	dserr = NWDSSetContext(ctx, DCK_FLAGS, &ctxflag);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_FLAGS) failed: %s\n",
			strnwerror(dserr));
		return 123;
	}
	dserr = NWDSSetContext(ctx, DCK_NAME_CONTEXT, context);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_NAME_CONTEXT) failed: %s\n",
			strnwerror(dserr));
		return 122;
	}
	dserr = NWDSSetContext(ctx, DCK_CONFIDENCE, &confidence);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_CONFIDENCE) failed: %s\n",
			strnwerror(dserr));
		return 122;
	}
#ifndef N_PLAT_MSW4
	{
		static const u_int32_t add[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
		dserr = NWDSSetTransport(ctx, 16, add);
		if (dserr) {
			fprintf(stderr, "NWDSSetTransport failed: %s\n",
				strnwerror(dserr));
			return 124;
		}
	}
#endif
#ifdef N_PLAT_MSW4
	dserr = NWDSOpenConnToNDSServer(ctx, server, &conn);
#else
	if (server[0] == '/') {
		dserr = ncp_open_mount(server, &conn);
		if (dserr) {
			fprintf(stderr, "ncp_open_mount failed with %s\n",
				strnwerror(dserr));
			return 111;
		}
	} else {
		struct ncp_conn_spec connsp;
		long err;
		
		memset(&connsp, 0, sizeof(connsp));
		strcpy(connsp.server, server);
		conn = ncp_open(&connsp, &err);
		if (!conn) {
			fprintf(stderr, "ncp_open failed with %s\n",
				strnwerror(err));
			return 111;
		}
	}
	dserr = NWDSAddConnection(ctx, conn);
#endif
	if (dserr) {
		fprintf(stderr, "Cannot bind connection to context: %s\n",
			strnwerror(dserr));
	}
	dserr = NWDSVerifyObjectPassword(ctx, NDS_PASSWORD, objectname, pwd);
	if (dserr) {
		fprintf(stderr, "Verify password failed: %s\n",
			strnwerror(dserr));
		ret = 1;
	} else {
		ret = 0;
	}
	NWCCCloseConn(conn);
	dserr = NWDSFreeContext(ctx);
	if (dserr) {
		fprintf(stderr, "NWDSFreeContext failed with %s\n", strnwerror(dserr));
		return 121;
	}
finished:
	return ret;
}
예제 #3
0
int main(int argc, char *argv[]) {
	NWDSCCODE dserr;
	NWDSContextHandle ctx;
	NWCONN_HANDLE conn;
	const char* context = "[Root]";
	const char* server = "CDROM.VC.CVUT.CZ";
	int opt;
	u_int32_t ctxflag = 0;
	u_int32_t confidence = 0;

#ifdef N_PLAT_LINUX
	setlocale(LC_ALL, "");
	bindtextdomain(NCPFS_PACKAGE, LOCALEDIR);
	textdomain(NCPFS_PACKAGE);
#endif

	progname = argv[0];

	NWCallsInit(NULL, NULL);

	dserr = NWDSCreateContextHandle(&ctx);
	if (dserr) {
		fprintf(stderr, "NWDSCretateContextHandle failed with %s\n", strnwerror(dserr));
		return 123;
	}
	while ((opt = getopt(argc, argv, "h?o:c:v:S:C:t:")) != EOF)
	{
		switch (opt)
		{
		case 'C':
			confidence = strtoul(optarg, NULL, 0);
			break;
		case 'c':
			context = optarg;
			break;
		case 'v':
			ctxflag = strtoul(optarg, NULL, 0);
			break;
		case 'h':
		case '?':
			help();
			goto finished;
		case 'S':
			server = optarg;
			break;
		default:
			usage();
			goto finished;
		}
	}

	ctxflag |= DCV_XLATE_STRINGS;
	
	dserr = NWDSSetContext(ctx, DCK_FLAGS, &ctxflag);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_FLAGS) failed: %s\n",
			strnwerror(dserr));
		return 123;
	}
	dserr = NWDSSetContext(ctx, DCK_NAME_CONTEXT, context);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_NAME_CONTEXT) failed: %s\n",
			strnwerror(dserr));
		return 122;
	}
	dserr = NWDSSetContext(ctx, DCK_CONFIDENCE, &confidence);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_CONFIDENCE) failed: %s\n",
			strnwerror(dserr));
		return 122;
	}
#ifdef N_PLAT_LINUX
	{
		static const u_int32_t add[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
		dserr = NWDSSetTransport(ctx, 16, add);
		if (dserr) {
			fprintf(stderr, "NWDSSetTransport failed: %s\n",
				strnwerror(dserr));
			return 124;
		}
	}
	if (server[0] == '/') {
		dserr = ncp_open_mount(server, &conn);
		if (dserr) {
			fprintf(stderr, "ncp_open_mount failed with %s\n",
				strnwerror(dserr));
			return 111;
		}
	} else {
		struct ncp_conn_spec connsp;
		long err;
		
		memset(&connsp, 0, sizeof(connsp));
		strcpy(connsp.server, server);
		conn = ncp_open(&connsp, &err);
		if (!conn) {
			fprintf(stderr, "ncp_open failed with %s\n",
				strnwerror(err));
			return 111;
		}
	}
	dserr = NWDSAddConnection(ctx, conn);
#else	
	dserr = NWDSOpenConnToNDSServer(ctx, server, &conn);
#endif
	if (dserr) {
		fprintf(stderr, "Cannot bind connection to context: %s\n",
			strnwerror(dserr));
	}
	DemoGetTime(conn);
	printf("Waiting 500 ms\n"); 
#ifdef N_PLAT_LINUX
	usleep(500000);
#else
	Sleep(500);
#endif
	DemoGetTime(conn);
	DemoGetVersion(conn);
	DemoGetGarbage(conn);
	NWCCCloseConn(conn);
	dserr = NWDSFreeContext(ctx);
	if (dserr) {
		fprintf(stderr, "NWDSFreeContext failed with %s\n", strnwerror(dserr));
		return 121;
	}
finished:
	return 0;
}
int main(int argc, char *argv[]) {
	NWDSCCODE dserr;
	NWDSContextHandle ctx;
	NWCONN_HANDLE conn;
	const char* objectname = "[Root]";
	const char* context = "OrgUnit.Org.Country";
	const char* server = "CDROM";
	int opt;
	u_int32_t ctxflag = 0;
	u_int32_t confidence = 0;
	u_int32_t req = 0;
	int req_present = 0;
	nuint32 ih = NO_MORE_ITERATIONS;
	Buf_T* buf;
	size_t size = DEFAULT_MESSAGE_LEN;

#ifndef N_PLAT_MSW4
	setlocale(LC_ALL, "");
	bindtextdomain(NCPFS_PACKAGE, LOCALEDIR);
	textdomain(NCPFS_PACKAGE);
#endif

	progname = argv[0];

	NWCallsInit(NULL, NULL);
#ifndef N_PLAT_MSW4
	NWDSInitRequester();
#endif

	dserr = NWDSCreateContextHandle(&ctx);
	if (dserr) {
		fprintf(stderr, "NWDSCretateContextHandle failed with %s\n", strnwerror(dserr));
		return 123;
	}
	while ((opt = getopt(argc, argv, "h?o:c:v:S:C:q:s:")) != EOF)
	{
		switch (opt)
		{
		case 'C':
			confidence = strtoul(optarg, NULL, 0);
			break;
		case 'o':
			objectname = optarg;
			break;
		case 'c':
			context = optarg;
			break;
		case 'v':
			ctxflag = strtoul(optarg, NULL, 0);
			break;
		case 'q':
			req = strtoul(optarg, NULL, 0);
			req_present = 1;
			break;
		case 's':
			size = strtoul(optarg, NULL, 0);
			break;
		case 'h':
		case '?':
			help();
			goto finished;
		case 'S':
			server = optarg;
			break;
		default:
			usage();
			goto finished;
		}
	}

	ctxflag |= DCV_XLATE_STRINGS;
	
	dserr = NWDSSetContext(ctx, DCK_FLAGS, &ctxflag);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_FLAGS) failed: %s\n",
			strnwerror(dserr));
		return 123;
	}
	dserr = NWDSSetContext(ctx, DCK_NAME_CONTEXT, context);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_NAME_CONTEXT) failed: %s\n",
			strnwerror(dserr));
		return 122;
	}
	dserr = NWDSSetContext(ctx, DCK_CONFIDENCE, &confidence);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_CONFIDENCE) failed: %s\n",
			strnwerror(dserr));
		return 122;
	}
#ifndef N_PLAT_MSW4
	{
		static const u_int32_t add[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
		dserr = NWDSSetTransport(ctx, 16, add);
		if (dserr) {
			fprintf(stderr, "NWDSSetTransport failed: %s\n",
				strnwerror(dserr));
			return 124;
		}
	}
#endif
#ifdef N_PLAT_MSW4
	dserr = NWDSOpenConnToNDSServer(ctx, server, &conn);
#else
	if (server[0] == '/') {
		dserr = ncp_open_mount(server, &conn);
		if (dserr) {
			fprintf(stderr, "ncp_open_mount failed with %s\n",
				strnwerror(dserr));
			return 111;
		}
	} else {
		struct ncp_conn_spec connsp;
		long err;
		
		memset(&connsp, 0, sizeof(connsp));
		strcpy(connsp.server, server);
		conn = ncp_open(&connsp, &err);
		if (!conn) {
			fprintf(stderr, "ncp_open failed with %s\n",
				strnwerror(err));
			return 111;
		}
	}
	dserr = NWDSAddConnection(ctx, conn);
#endif
	if (dserr) {
		fprintf(stderr, "Cannot bind connection to context: %s\n",
			strnwerror(dserr));
	}
	dserr = NWDSAllocBuf(size, &buf);
	if (dserr) {
		fprintf(stderr, "Cannot create reply buffer: %s\n",
			strnwerror(dserr));
	}
	do {
		if (req_present)
			dserr = NWDSListPartitionsExtInfo(ctx, &ih, objectname, req, buf);
		else
			dserr = NWDSListPartitions(ctx, &ih, objectname, buf);
		if (dserr) {
			fprintf(stderr, "ListPartitions failed with %s\n", 
				strnwerror(dserr));
		} else {
			unsigned char* pp;
			NWObjectCount cnt;
			char sn[MAX_DN_CHARS + 1];
			size_t pcnt;

			printf("Iteration handle: %08X\n", ih);
		
			dserr = NWDSGetServerName(ctx, buf, sn, &cnt);
			if (dserr) {
				fprintf(stderr, "GetServerName failed with %s\n",
					strnwerror(dserr));
			} else {
				pcnt = 0;
				printf("Server %s holds %u partitions\n",
					sn, cnt);
				while (!dserr && cnt--) {
					printf("Partition #%u\n", pcnt++);
					if (req_present) {
						char* start;
						char* end;
						
						dserr = NWDSGetPartitionExtInfoPtr(
								ctx, buf, &start, &end);
						if (dserr) {
							fprintf(stderr, "  NWDSGetPartitionExtInfoPtr failed with %s\n",
								strnwerror(dserr));
						} else {
							nuint32 pt;
							union {
							nuint32     x32;
							TimeStamp_T ts;
							NWObjectID  id;
							char        name[MAX_DN_CHARS + 1];
							} info;
							nuint32 bit;
							size_t len;
							
							printf("  Partition info length:  %10u\n", end - start);
							if (req & DSP_OUTPUT_FIELDS) {
								dserr = NWDSGetPartitionExtInfo(ctx, start, end, DSP_OUTPUT_FIELDS, &len, &pt);
								if (dserr) {
									fprintf(stderr, "  NWDSGetPartitionExtInfo(DSP_OUTPUT_FIELDS) failed with %s\n",
										strnwerror(dserr));
									pt = req;
								} else {
									printf("  Output fields:            %08X (%u bytes)\n", pt, len);
								}
							} else {
								pt = req;
							}
							for (bit = DSP_PARTITION_ID; bit; bit <<= 1) {
								if (pt & bit) {
									dserr = NWDSGetPartitionExtInfo(ctx, start, end, bit, &len, &info);
									if (dserr)
										fprintf(stderr, "  NWDSGetPartitionExtInfo(0x%08X) failed with %s\n",
											bit, strnwerror(dserr));
									else {
										switch (bit) {
											case DSP_PARTITION_ID:
												printf("  Partition ID:             %08X (%u bytes)\n", info.id, len);
												break;
											case DSP_REPLICA_STATE:
												printf("  Replica state:          %10u (%u bytes)\n", info.x32, len);
												break;
											case DSP_MODIFICATION_TIMESTAMP:
												printf("  Modification timestamp: %10u.%u.%u (%u bytes)\n",
													info.ts.wholeSeconds, info.ts.replicaNum,
													info.ts.eventID, len);
												break;
											case DSP_PURGE_TIME:
												printf("  Purge time:             %10u (%u bytes)\n", 
													info.x32, len);
												break;
											case DSP_LOCAL_PARTITION_ID:
												printf("  Local partition ID:     %10u (%u bytes)\n",
													info.x32, len);
												break;
											case DSP_PARTITION_DN:
												printf("  Partition DN:           %s (%u bytes)\n",
													info.name, len);
												break;
											case DSP_REPLICA_TYPE:
												printf("  Replica type:           %10u (%u bytes)\n",
													info.x32, len);
												break;
											case DSP_PARTITION_BUSY:
												printf("  Partition busy:         %10u (%u bytes)\n",
													info.x32, len);
												break;
											default:
												printf("  Unknown %08X:       %10u (%u bytes)\n",
													bit, info.x32, len);
												break;
										}
									}
								}
							}
						}
					} else {
						nuint32 pt;
						
						dserr = NWDSGetPartitionInfo(ctx, buf, sn, &pt);
						if (dserr) {
							fprintf(stderr, "  NWDSGetPartitionInfo failed with %s\n",
								strnwerror(dserr));
						} else {
							printf("  Partition DN: %s\n", sn);
							printf("  Replica type: %u\n", pt);
						}
					}
#if 0
					Object_Info_T tt;
					char name[8192];
					size_t attrs;
					
					dserr = NWDSGetObjectName(ctx, buf, name, &attrs, &tt);
					if (dserr) {
						fprintf(stderr, "GetObjectName failed with %s\n",
							strnwerror(dserr));
						break;
					}
					printf("Name: %s\n", name);
					printf("  Attrs: %u\n", attrs);
					printf("  Flags: %08X\n", tt.objectFlags);
					printf("  Subordinate Count: %u\n", tt.subordinateCount);
					printf("  Modification Time: %lu\n", tt.modificationTime);
					printf("  Base Class: %s\n", tt.baseClass);
#endif
				}
			}
#ifndef N_PLAT_MSW4
			pp = buf->curPos;	
			for (; pp < buf->dataend; pp++) {
				printf("%02X ", *pp);
			}
			printf("\n");
#endif
		}
	} while ((dserr == 0) && (ih != NO_MORE_ITERATIONS));
	NWCCCloseConn(conn);
	dserr = NWDSFreeContext(ctx);
	if (dserr) {
		fprintf(stderr, "NWDSFreeContext failed with %s\n", strnwerror(dserr));
		return 121;
	}
finished:
	return 0;
}
예제 #5
0
int main (int argc, char* argv[])
{
        NWDSCCODE               res;
        nstr8                   UserName   [NW_MAX_USER_NAME_LEN];
        nstr8                   Password   [256];
        nstr8                   Object     [MAX_DN_CHARS+1];
        nstr8                   FileName   [256];
	nstr8			Logfile	   [256];
        nstr8                   ServerName [50];
	NWCONN_HANDLE           ConnHandle;
        FILE*                   BackupFile;
        int                     NonOptArgs;
        BYTE                    OldNameSpace;

        // start off by auto destroying the screen
	AutoDestroyScreen = 0xF;
	
	// increment the thread counter
	ThreadCount++;
	
	// get the main thread group id
	MainThreadGroupId = GetThreadGroupID ();

	// set the signal handler, and disable CTRL-C
	signal (SIGTERM, SigHandler);
	SetCtrlCharCheckMode (FALSE);

	// make sure we've got something to do - i know, this would be more appropriately done in the switch below
	if (argc == 1)
	{
		Usage ();
		return 1;
	}

	clrscr ();
	gotoxy (28, 0);
	printf ("NetWare Rights Utility\n");
	gotoxy (28, 1);
	printf ("(c) 2003  J. Gallimore\n");
	printf ("\n\n");
        
	// create a global context handle
	if ((res = NWDSCreateContextHandle (&NDSContext)) != 0)
        {
                printf ("NWDSCreateContextHandle returned: %d\n", res);
                return 1;
        }

        DoLogin = 0;

        // attempt to retrieve the username and password from the command line
	NonOptArgs = GetOptArgs (argc, argv, UserName, Password, Logfile);

        // login if we need to
	// ask for the username / password, if not specified on the command line
	// if user input is required, don't automatically close the screen
	
	if (!NWIsDSAuthenticated ())
        {
                printf ("Login to NDS\nUsername:"******"") == 0)
       	        {
               	        AutoDestroyScreen = 0x0;
			AwaitingInput = TRUE;
                        gets (UserName);
			AwaitingInput = FALSE;
               	}
                else
       	                printf ("%s\n", UserName);

		// included if the nlm is unloaded whilst inputting details
		if (NlmExiting)
		{
			Cleanup ();
			return 1;
		}

                printf ("Password:"******"") == 0)
       	        {
               	        AutoDestroyScreen = 0x0;
			AwaitingInput = TRUE;
                        GetPass (Password, 256);
			AwaitingInput = FALSE;
               	}
                else
       	                printf ("*\n");

		// included if the nlm is unloaded whilst inputting details
		if (NlmExiting)
		{
			Cleanup ();
			return 1;
		}
                
                if ((res = NWDSLogin (NDSContext, 0, UserName, Password, 0)) != 0)
                {
       	                printf ("NWDSLogin returned: %d\n", res);
               	        Cleanup ();
                       	return 1;
		}
                DoLogin = 1; // if we logged in, we must logout
        }

	// included if the nlm is unloaded whilst inputting details
	if (NlmExiting)
	{
		Cleanup ();
		return 1;
	}

        // open and authenticate a connection to the local box	
	GetFileServerName (0, ServerName);

        if ((res = NWCCOpenConnByName (0, ServerName, NWCC_NAME_FORMAT_NDS, NWCC_OPEN_LICENSED, NWCC_RESERVED, &ConnHandle)) != 0)
        {
                printf ("NWDSOpenConnToNDSServer returned: %d\n", res);
                Cleanup ();
                return 1;
        }
        
        if ((res = NWDSAuthenticateConn (NDSContext, ConnHandle)) != 0)
        {
                printf ("NWDSAuthenticateConn returned: %d\n", res);
                Cleanup ();
                return 1;
        }

        // change to the [Root] context
	if ((res = NWDSSetContext (NDSContext, DCK_NAME_CONTEXT, "[Root]")) != 0)
        {
                printf ("NWDSSetContext returned: %d\n", res);
                Cleanup ();
                return 1;
        }

        // process the command line arguments
	switch (NonOptArgs)
        {
                case 0:
                        Usage ();
                break;

                case 1:
                        Usage ();
                break;

                case 2:
                        if (strncmp (argv [1], "/R=", 3) == 0 || strncmp (argv [1], "/r=", 3) == 0)
                        {
                                if (TrimQuotes (FileName, argv [1] + 3, 256) == 0)
                                {
                                        // perform a restore
					Restore (ConnHandle, FileName, Logfile);
                                }
                        }
                        else
                        {
                                // display trustee rights, don't auto close screen
				AutoDestroyScreen = 0x0;
                                GetTrustees (ConnHandle, 0, argv [1], NW_NS_LONG, 1, NULL);
                        }
                break;

                case 3:
                        if (strncmp (argv [2], "/B=", 3) == 0 || strncmp (argv [2], "/b=", 3) == 0)
                        {
                                // backup the trustee rights to a file
				if (TrimQuotes (FileName, argv[2] + 3, 256) == 0)
                                {
                                        OldNameSpace = SetCurrentNameSpace (NW_NS_LONG);
                                        if ((BackupFile = fopen (FileName, "w")) != NULL)
                                        {
                                                fprintf (BackupFile, "cx [Root]\n");
                                                GetTrustees (ConnHandle, 0, argv [1], NW_NS_LONG, 1, BackupFile);
                                                fclose (BackupFile);
                                        }
                                }
                        }
                break;

                case 4:
                        // set trustee rights or IRF as appropriate
		
			if (strncmp ("/F", argv [3], 2) == 0 || strncmp ("/f", argv [3], 2) == 0)
                        {
                                // inherited rights filter
                                InheritedRights (ConnHandle, 0, argv [1], NW_NS_LONG, argv [2]);
                        }

                        if (strncmp (argv[3], "/NAME=", 6) == 0 || strncmp (argv[3], "/name=", 6) == 0)
                        {
                                // get pointer to name, strip off leading and trailing "
                                if (TrimQuotes (Object, argv [3] + 6, MAX_DN_CHARS+1) == 0)
                                        TrusteeRights (ConnHandle, 0, argv [1], NW_NS_LONG, Object, argv [2]);
                        
                        }

                break;

                default:
                        Usage ();
                break;
        }

        // close local connection and cleanup
	if ((res = NWCCCloseConn (ConnHandle)) != 0)
                printf ("NWCCCloseConn returned: %d\n", res);
        
        Cleanup ();
        return 0;               
}
예제 #6
0
int main(int argc, char *argv[]) {
	NWDSCCODE dserr;
	NWDSContextHandle ctx;
	NWCONN_HANDLE conn;
	const char* objectname = "[Root]";
	const char* context = "OrgUnit.Org.Country";
	const char* server = "CDROM";
	int opt;
	u_int32_t ctxflag = 0;
	u_int32_t confidence = 0;
	Buf_T* buf;
	size_t size = DEFAULT_MESSAGE_LEN;

#ifndef N_PLAT_MSW4
	setlocale(LC_ALL, "");
	bindtextdomain(NCPFS_PACKAGE, LOCALEDIR);
	textdomain(NCPFS_PACKAGE);
#endif

	progname = argv[0];

	NWCallsInit(NULL, NULL);
#ifndef N_PLAT_MSW4
	NWDSInitRequester();
#endif

	dserr = NWDSCreateContextHandle(&ctx);
	if (dserr) {
		fprintf(stderr, "NWDSCretateContextHandle failed with %s\n", strnwerror(dserr));
		return 123;
	}
	dserr = NWDSAllocBuf(size, &buf);
	if (dserr) {
		fprintf(stderr, "Cannot create request buffer: %s\n",
			strnwerror(dserr));
	}
	dserr = NWDSInitBuf(ctx, DSV_MODIFY_CLASS_DEF, buf);
	if (dserr) {
		fprintf(stderr, "Cannot init buffer: %s\n",
			strnwerror(dserr));
	}
	while ((opt = getopt(argc, argv, "h?o:c:v:S:C:s:A:")) != EOF)
	{
		switch (opt)
		{
		case 'C':
			confidence = strtoul(optarg, NULL, 0);
			break;
		case 'o':
			objectname = optarg;
			break;
		case 'c':
			context = optarg;
			break;
		case 'v':
			ctxflag = strtoul(optarg, NULL, 0);
			break;
		case 's':
			size = strtoul(optarg, NULL, 0);
			break;
		case 'A':
			dserr = NWDSPutClassItem(ctx, buf, optarg);
			if (dserr) {
				fprintf(stderr, "Cannot NWDSPutClassItem `%s': %s\n",
					optarg, strnwerror(dserr));
			}
			break;
		case 'h':
		case '?':
			help();
			goto finished;
		case 'S':
			server = optarg;
			break;
		default:
			usage();
			goto finished;
		}
	}

	ctxflag |= DCV_XLATE_STRINGS;
	
	dserr = NWDSSetContext(ctx, DCK_FLAGS, &ctxflag);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_FLAGS) failed: %s\n",
			strnwerror(dserr));
		return 123;
	}
	dserr = NWDSSetContext(ctx, DCK_NAME_CONTEXT, context);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_NAME_CONTEXT) failed: %s\n",
			strnwerror(dserr));
		return 122;
	}
	dserr = NWDSSetContext(ctx, DCK_CONFIDENCE, &confidence);
	if (dserr) {
		fprintf(stderr, "NWDSSetContext(DCK_CONFIDENCE) failed: %s\n",
			strnwerror(dserr));
		return 122;
	}
#ifndef N_PLAT_MSW4
	{
		static const u_int32_t add[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
		dserr = NWDSSetTransport(ctx, 16, add);
		if (dserr) {
			fprintf(stderr, "NWDSSetTransport failed: %s\n",
				strnwerror(dserr));
			return 124;
		}
	}
#endif
#ifdef N_PLAT_MSW4
	dserr = NWDSOpenConnToNDSServer(ctx, server, &conn);
#else
	if (server[0] == '/') {
		dserr = ncp_open_mount(server, &conn);
		if (dserr) {
			fprintf(stderr, "ncp_open_mount failed with %s\n",
				strnwerror(dserr));
			return 111;
		}
	} else {
		struct ncp_conn_spec connsp;
		long err;
		
		memset(&connsp, 0, sizeof(connsp));
		strcpy(connsp.server, server);
		conn = ncp_open(&connsp, &err);
		if (!conn) {
			fprintf(stderr, "ncp_open failed with %s\n",
				strnwerror(err));
			return 111;
		}
	}
	dserr = NWDSAddConnection(ctx, conn);
#endif
	if (dserr) {
		fprintf(stderr, "Cannot bind connection to context: %s\n",
			strnwerror(dserr));
	}
	dserr = NWDSModifyClassDef(ctx, objectname, buf);
	if (dserr) {
		fprintf(stderr, "ModifyClassDef failed with %s\n", 
			strnwerror(dserr));
	} else {
		printf("ModifyClassDef suceeded\n");
	}
	NWCCCloseConn(conn);
	dserr = NWDSFreeContext(ctx);
	if (dserr) {
		fprintf(stderr, "NWDSFreeContext failed with %s\n", strnwerror(dserr));
		return 121;
	}
finished:
	return 0;
}
예제 #7
0
/*************************************************************************
** main
*/
int main (int argc, char** argv) {
	NWDSContextHandle	context;
	NWDSCCODE ccode;
	nint32	iterationHandle;
	nint32	countObjectsSearched;
	nuint32	objCntr,attrCntr,valCntr;
	nuint32	objCount;			
	nuint32	attrCount;			
	char 	admin[MAX_DN_CHARS+1];
	char	password[MAX_VALUE_LEN+1];
	char	objectName[MAX_DN_CHARS+1];
	char	attrName[MAX_SCHEMA_NAME_CHARS+1];
	nuint32	attrValCount;
	nuint32	syntaxID;
	nuint32	attrValSize;
	char*	attrVal;
	nint32	screenCntr=0;
	nuint32 contextFlags;
	
	// buffers
	pBuf_T	searchFilter=NULL;	// search filter
	pBuf_T	retBuf=NULL;		// result buffer for NWDSSearch
	pBuf_T	attrNames=NULL;		// specify which attribute values to return
	Filter_Cursor_T* cur=NULL;	// search expression tree temporary buffer
	Object_Info_T	objectInfo;
		
	/*******************************************************************
	create context and set current context to Root
	 *******************************************************************/
	 
	ccode = NWDSCreateContextHandle(&context);
	
	if((long)context == ERR_CONTEXT_CREATION) {
		 printf("Error creating context.\n");
		 goto Exit1;
	}

	ccode=NWDSSetContext(context, DCK_NAME_CONTEXT, "[Root]");
	if(ccode){
		 printf("Error NWDSSetContext(): %d\n",ccode);
		 goto Exit2;
	}


	ccode= NWDSGetContext(context, DCK_FLAGS, &contextFlags);
	if( ccode != 0) 
	{
		printf("NWDSGetContext (DCK_FLAGS) failed, returns %d\n", ccode);
	}

	contextFlags|= DCV_TYPELESS_NAMES;

/*****************************************************
 In order to see the problem, first compile, and run with the line below
 commented out. The program will display a list of users on the NDS.
 Now, un-comment the line belog, compile, and re-run the NLM, and the 
 NWDSSearch function fails with error code -601
 *****************************************************/
 
/*	contextFlags &= ~DCV_XLATE_STRINGS;  */
	
	ccode= NWDSSetContext( context, DCK_FLAGS, &contextFlags);
	if( ccode != 0) 
	{
		printf("NWDSSetContext (DCK_FLAGS DCV_TYPELESS_NAMES) failed, returns %d\n", ccode);
	}


	/*******************************************************************
	Login to NDS
	*/
	//ccode = NWDSLoginAsServer( context );
	{
		NWCONN_HANDLE conn;

//		ccode = ncp_open_mount("/root/fdnet", &conn);
		ccode = NWCCOpenConnByName(NULL, "FDNET", NWCC_NAME_FORMAT_BIND, 0, 0, &conn);

		if (!ccode)
			NWDSAddConnection(context, conn);
	}
	
	if(ccode){
		switch (ccode) {
			case -601:
				// user object not found
				printf("User object not found: %s\n",admin);
				break;
			case -669:
				// auth failed
				printf("Failed authentication.  Check Password\n");
				break;
			default:
				 printf("Error: NWDSLogin failed (%s) for %s\n",strnwerror(ccode),admin);
		}
		goto Exit2;
	}


	/*******************************************************************
	In order to search, we need:
		A Filter Cursor (to build the search expression)
		A Filter Buffer (to store the expression; used by NWDSSearch)
		A Buffer to store which attributes we need information on
		A Result Buffer (to store the search results)
	*/

	/*******************************************************************
	** Allocate Filter buffer and Cursor and populate
	*/
	ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN,&searchFilter);
	if (ccode < 0) {
		printf("NWDSAllocBuf returned: %d\n", ccode);
		goto Exit3;
	}

	// Initialize the searchFilter buffer
	ccode = NWDSInitBuf(context,DSV_SEARCH_FILTER,searchFilter);
	if (ccode < 0) {
		printf("NWDSInitBuf returned: %d\n", ccode);
		goto Exit4;
	}

	// Allocate a filter cursor to put the search expression 
	ccode = NWDSAllocFilter(&cur);
	if (ccode < 0) {
		printf("NWDSAllocFilter returned: %d\n", ccode);
		goto Exit4;
	}

	// Build the expression tree in cur, then place into searchFilter 
	// Object Class = User
	ccode = NWDSAddFilterToken(cur,FTOK_ANAME,"Object Class",SYN_CLASS_NAME);
	if (ccode < 0) {
			printf("NWDSAddFilterToken returned: %d\n", ccode);
			goto Exit4;
	}

	ccode = NWDSAddFilterToken(cur,FTOK_EQ,NULL,0);
	if (ccode < 0) {
			printf("NWDSAddFilterToken returned: %d\n", ccode);
			goto Exit4;
	}

	ccode = NWDSAddFilterToken(cur,FTOK_AVAL,"User",SYN_CLASS_NAME);
	if (ccode < 0) {
			printf("NWDSAddFilterToken returned: %d\n", ccode);
			goto Exit4;
	}

	// now place the cursor into the searchFilter buffer 
	// NWDSPutFilter frees the expression tree filter (cur)
	//	so if it succeeds, set cur to NULL so it won't be
	//	freed below 
	ccode = NWDSPutFilter(context,searchFilter,cur,NULL);
	if (ccode < 0) {
			printf("NWDSPutFilter returned: %d\n", ccode);
			goto Exit4;
	}
	else
		cur=NULL;

	/*******************************************************************
	** Specify which attributes we want information on
	*/
	// allocate and initialize the attrNames buffer 
	ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN,&attrNames);
	if (ccode < 0) {
			printf("NWDSAllocBuf returned: %d\n", ccode);
			goto Exit4;
	}
	ccode = NWDSInitBuf(context,DSV_SEARCH,attrNames);
	if (ccode < 0) {
			printf("NWDSInitBuf returned: %d\n", ccode);
			goto Exit4;
	}

	// specify the attributes to retrieve for the objects
	// In this case: Given Name and Full Name
	ccode = NWDSPutAttrName(context,attrNames,"Given Name");
	if (ccode < 0) {
			printf("NWDSPutAttrName returned: %d\n", ccode);
			goto Exit4;
	}
	ccode = NWDSPutAttrName(context,attrNames,"Full Name");
	if (ccode < 0) {
			printf("NWDSPutAttrName returned: %d\n", ccode);
			goto Exit4;
	}
	ccode = NWDSPutAttrName(context,attrNames,"Surname");
	if (ccode < 0) {
			printf("NWDSPutAttrName returned: %d\n", ccode);
			goto Exit4;
	}
	ccode = NWDSPutAttrName(context,attrNames,"Title");
	if (ccode < 0) {
			printf("NWDSPutAttrName returned: %d\n", ccode);
			goto Exit4;
	}

	/*******************************************************************
	** Allocate a result buffer
	*/
	ccode = NWDSAllocBuf(65500,&retBuf);
	if (ccode < 0) {
			printf("NWDSAllocBuf returned: %d\n", ccode);
			goto Exit4;
	}

	/*******************************************************************
	** We are now ready to do the search
	*/
	iterationHandle = NO_MORE_ITERATIONS;
	// while NWDSSearch still can get some objects...
	do {
		ccode = NWDSSearch(context,
				"[Root]",
				DS_SEARCH_SUBTREE,
				FALSE,		// don't dereference aliases
				searchFilter,
				TRUE,		// we want attributes and values
				FALSE,		// only want information in attrNames
				attrNames,
				&iterationHandle,
				0,		// reserved
				&countObjectsSearched,
				retBuf);
		if (ccode) {
			printf("NWDSSearch returned: %s\n", strnwerror(ccode));
			goto Exit4;
		}

		// count the object returned in the buffer
		ccode = NWDSGetObjectCount(context,retBuf,&objCount);
		if (ccode) {
			printf("NWDSGetObjectCount returned: %d\n", ccode);
			goto Exit4;
		}

		printf("Objects found: %d\n",objCount);
		printf("-----------------------------------------\n");
		screenCntr+=2;

		// for the number of objects returned...
		for (objCntr=0;objCntr<objCount;objCntr++) {
			// get an object name
			ccode = NWDSGetObjectName(context,retBuf,objectName,&attrCount,&objectInfo);
			if (ccode) {
				printf("NWDSGetObjectName returned: %d\n", ccode);
				goto Exit4;
			}
			printf("%s\n",objectName);
			screenCntr++;

			// for the number of attributes returned with the object...
			for (attrCntr=0;attrCntr<attrCount;attrCntr++) {
				// get the attribute name
				ccode = NWDSGetAttrName(context,retBuf,attrName,&attrValCount,&syntaxID);
				if (ccode) {
					printf("NWDSGetAttrName returned: %d\n", ccode);
					goto Exit4;
				}
				// compute and allocate space for the value
				ccode = NWDSComputeAttrValSize(context,retBuf,syntaxID,&attrValSize);
				if (ccode) {
					printf("NWDSComputeAttrValSize returned: %d\n", ccode);
					goto Exit4;
				}
				attrVal = malloc(attrValSize);
				// for the number of values returned with the attribute...
				for (valCntr=0;valCntr<attrValCount;valCntr++) {
					// get the value
					ccode = NWDSGetAttrVal(context,retBuf,syntaxID,attrVal);
					if (ccode) {
						printf("NWDSGetAttrVal returned: %d\n", ccode);
						goto Exit4;
					}
					printf("  %s =\t%s\n",attrName,attrVal);
					screenCntr++;
				} // valCntr
				free(attrVal);
			} // attrCntr
			printf("\n");
		} // objCntr
	} while ((nuint32)iterationHandle != NO_MORE_ITERATIONS);


Exit4:
	if (retBuf)
		NWDSFreeBuf(retBuf);
	if (cur)
		NWDSFreeFilter(cur, NULL);
	if (searchFilter)
		NWDSFreeBuf(searchFilter);
	if (attrNames)
		NWDSFreeBuf(attrNames);
Exit3:
//	NWDSLogout(context);
Exit2:
	NWDSFreeContext(context);
Exit1:
	exit(0);
}