Exemple #1
0
static NWDSCCODE __NWDSGenerateObjectKeyPairStep3(
		NWCONN_HANDLE		conn,
		nuint8*			connPublicKey
) {
	free(connPublicKey);
	NWCCCloseConn(conn);
	return 0;
}
Exemple #2
0
NWDSCCODE NWDSResetNDSStatistics(
		NWDSContextHandle	ctx,
		const NWDSChar*		serverName
) {
	NWCONN_HANDLE conn;
	NWDSCCODE dserr;
	
	dserr = NWDSOpenConnToNDSServer(ctx, serverName, &conn);
	if (dserr)
		return dserr;
	dserr = __NWDSResetNDSStatistics(conn);
	NWCCCloseConn(conn);
	return dserr;	
}
Exemple #3
0
NWDSCCODE NWDSGetNDSStatistics(
		NWDSContextHandle	ctx,
		const NWDSChar*		serverName,
		size_t			statsInfoLen,
		NDSStatsInfo_T*		statsInfo) {
	NWCONN_HANDLE conn;
	NWDSCCODE dserr;
	
	dserr = NWDSOpenConnToNDSServer(ctx, serverName, &conn);
	if (dserr)
		return dserr;
	dserr = __NWDSGetNDSStatistics(conn, 0x01FFFFFF, statsInfoLen, statsInfo);
	NWCCCloseConn(conn);
	return dserr;	
}
Exemple #4
0
static NWDSCCODE __NWDSGenerateObjectKeyPairStep1(
		NWDSContextHandle	ctx, 
		const NWDSChar*		objectName,
		NWCONN_HANDLE*		conn,
		NWObjectID*		objectID,
		NWObjectID*		oldPseudoID,
		nuint8			rndseed[4],
		nuint8**		connPublicKey
) {
	NWDSCCODE err;
	NWDSContextHandle unictx;
	NWCONN_HANDLE lconn;

	*connPublicKey = NULL;

	err = NWDSResolveName2DR(ctx, objectName, DS_RESOLVE_DEREF_ALIASES | DS_RESOLVE_WRITEABLE,
		&lconn, objectID);
	if (err)
		return err;
	err = __NWDSBeginLoginV0(lconn, *objectID, oldPseudoID, rndseed);
	if (err)
		goto err_free_conn;
	err = NWDSDuplicateContextHandle(ctx, &unictx);
	if (err)
		goto err_free_conn;
	unictx->dck.flags = DCV_TYPELESS_NAMES | DCV_XLATE_STRINGS;
	err = NWDSSetContext(unictx, DCK_LOCAL_CHARSET, "WCHAR_T//");
	if (err)
		goto err_free_ctx_conn;
	err = __NWDSGetPublicKeyFromConnection(unictx, lconn, connPublicKey);
	NWDSFreeContext(unictx);
	if (err)
		goto err_free_conn;
	*conn = lconn;
	return 0;
err_free_ctx_conn:;
	NWDSFreeContext(unictx);
err_free_conn:;
	NWCCCloseConn(*conn);
	return err;
}
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;
}
Exemple #6
0
NWDSCCODE NWDSGetCountByClassAndName(
		NWDSContextHandle ctx,
		const NWDSChar* objectName,
		const NWDSChar* className,
		const NWDSChar* subordinateName,
		NWObjectCount* count
) {
	NWDSCCODE err;
	NWCONN_HANDLE conn;
	NWObjectID objID;
	nuint32 iterHandle;
	nuint32 lcnt;
	Buf_T* buf;
	nuint8 spare[(4 + MAX_DN_BYTES) * 2];
	Buf_T nameb;
		
	if (!count)
		return ERR_NULL_POINTER;
	NWDSSetupBuf(&nameb, spare, sizeof(spare));
	if (subordinateName)
		err = NWDSPutAttrVal_XX_STRING(ctx, &nameb, subordinateName);
	else
		err = NWDSBufPutLE32(&nameb, 0);
	if (err)
		return err;
	if (className)
		err = NWDSPutAttrVal_XX_STRING(ctx, &nameb, subordinateName);
	else
		err = NWDSBufPutLE32(&nameb, 0);
	if (err)
		return err;
	*count = 0;
	err = NWDSResolveName2(ctx, objectName, DS_RESOLVE_READABLE,
		&conn, &objID);
	if (err)
		return err;
	lcnt = 0;
	iterHandle = NO_MORE_ITERATIONS;
	err = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &buf);
	if (err)
		goto quit_handle;
	do {
		NWObjectCount cnt;

		NWDSRewindBuf(buf);
		err = __NWDSListV1(ctx, conn, objID, 0, &iterHandle, 0, &nameb,
			buf);
		if (err)
			goto quit;
		err = NWDSGetObjectCount(ctx, buf, &cnt);
		if (err)
			goto quit;
		lcnt += cnt;
	} while (iterHandle != NO_MORE_ITERATIONS);
quit:;
	*count = lcnt;
	NWDSFreeBuf(buf);
quit_handle:;
	NWCCCloseConn(conn);
	return err;
} 	
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;
}
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;
}
Exemple #10
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;               
}
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;
}