Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

tenv.c File Reference

#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <stdio.h>

Go to the source code of this file.

Functions

VOID DumpEnvironment (PVOID env)
VOID SetEnvironment (PVOID *env, PCHAR Name, PCHAR Value)
int _cdecl main (int argc, char **argv, char **envp)


Function Documentation

VOID DumpEnvironment PVOID  env  ) 
 

Definition at line 27 of file tenv.c.

Referenced by main(), and SetEnvironment().

00028 { 00029 PWCHAR s = env; 00030 00031 while (*s) { 00032 printf( "%79.79ws\n", s ); 00033 while (*s++) { 00034 } 00035 } 00036 }

int _cdecl main int  argc,
char **  argv,
char **  envp
 

Definition at line 93 of file tenv.c.

References DumpEnvironment(), NT_SUCCESS, NTSTATUS(), NULL, RtlCreateEnvironment(), SetEnvironment(), Status, and TRUE.

00098 { 00099 int i; 00100 PVOID env; 00101 PVOID nenv; 00102 NTSTATUS Status; 00103 char bigbuf[4100]; 00104 00105 for (i=0; i<argc; i++) { 00106 printf( "argv[ %d ] = %s\n", i, argv[ i ] ); 00107 } 00108 00109 i = 0; 00110 while (envp[ i ]) { 00111 printf( "envp[ %d ] = %s\n", i, envp[ i ] ); 00112 i++; 00113 } 00114 00115 for (i=0 ; i<4099 ; i++) 00116 bigbuf[i] = (i%26) + (((i&1) == 0) ? 'a' : 'A'); 00117 bigbuf[4099] = '\0'; 00118 00119 env = NtCurrentPeb()->ProcessParameters->Environment; 00120 Status = RtlCreateEnvironment(TRUE, &nenv); // clone current 00121 if (!NT_SUCCESS( Status )) { 00122 printf( "Unable to create clone environment - %X\n", Status ); 00123 return 1; 00124 } 00125 00126 // First, check with process environment 00127 DumpEnvironment( &env); 00128 SetEnvironment( &env, "aaaa", "12345" ); 00129 SetEnvironment( &env, "aaaa", "1234567890" ); 00130 SetEnvironment( &env, "aaaa", "1" ); 00131 SetEnvironment( &env, "aaaa", "" ); 00132 SetEnvironment( &env, "aaaa", NULL ); 00133 SetEnvironment( &env, "AAAA", "12345" ); 00134 SetEnvironment( &env, "AAAA", "1234567890" ); 00135 SetEnvironment( &env, "AAAA", "1" ); 00136 SetEnvironment( &env, "AAAA", "" ); 00137 SetEnvironment( &env, "AAAA", NULL ); 00138 SetEnvironment( &env, "MMMM", "12345" ); 00139 SetEnvironment( &env, "MMMM", "1234567890" ); 00140 SetEnvironment( &env, "MMMM", "1" ); 00141 SetEnvironment( &env, "MMMM", "" ); 00142 SetEnvironment( &env, "MMMM", NULL ); 00143 SetEnvironment( &env, "ZZZZ", "12345" ); 00144 SetEnvironment( &env, "ZZZZ", "1234567890" ); 00145 SetEnvironment( &env, "ZZZZ", "1" ); 00146 SetEnvironment( &env, "ZZZZ", "" ); 00147 SetEnvironment( &env, "ZZZZ", NULL ); 00148 SetEnvironment( &env, "BIGBUF", bigbuf ); 00149 SetEnvironment( &env, "BIGBUF", NULL ); 00150 00151 // Second, check with non-process environment 00152 DumpEnvironment(nenv); 00153 SetEnvironment( &nenv, "aaaa", "12345" ); 00154 SetEnvironment( &nenv, "aaaa", "1234567890" ); 00155 SetEnvironment( &nenv, "aaaa", "1" ); 00156 SetEnvironment( &nenv, "aaaa", "" ); 00157 SetEnvironment( &nenv, "aaaa", NULL ); 00158 SetEnvironment( &nenv, "AAAA", "12345" ); 00159 SetEnvironment( &nenv, "AAAA", "1234567890" ); 00160 SetEnvironment( &nenv, "AAAA", "1" ); 00161 SetEnvironment( &nenv, "AAAA", "" ); 00162 SetEnvironment( &nenv, "AAAA", NULL ); 00163 SetEnvironment( &nenv, "MMMM", "12345" ); 00164 SetEnvironment( &nenv, "MMMM", "1234567890" ); 00165 SetEnvironment( &nenv, "MMMM", "1" ); 00166 SetEnvironment( &nenv, "MMMM", "" ); 00167 SetEnvironment( &nenv, "MMMM", NULL ); 00168 SetEnvironment( &nenv, "ZZZZ", "12345" ); 00169 SetEnvironment( &nenv, "ZZZZ", "1234567890" ); 00170 SetEnvironment( &nenv, "ZZZZ", "1" ); 00171 SetEnvironment( &nenv, "ZZZZ", "" ); 00172 SetEnvironment( &nenv, "ZZZZ", NULL ); 00173 SetEnvironment( &nenv, "BIGBUF", bigbuf ); 00174 SetEnvironment( &nenv, "BIGBUF", NULL ); 00175 return( 0 ); 00176 }

VOID SetEnvironment PVOID *  env,
PCHAR  Name,
PCHAR  Value
 

Definition at line 46 of file tenv.c.

References DumpEnvironment(), Name, NT_SUCCESS, NTSTATUS(), NULL, RtlAnsiStringToUnicodeString(), RtlFreeUnicodeString(), RtlInitString(), RtlSetEnvironmentVariable(), Status, and TRUE.

Referenced by main().

00051 { 00052 NTSTATUS Status; 00053 STRING NameString, ValueString; 00054 UNICODE_STRING uNameString, uValueString; 00055 00056 RtlInitString( &NameString, Name ); 00057 Status = RtlAnsiStringToUnicodeString(&uNameString, &NameString, TRUE); 00058 if (!NT_SUCCESS( Status )) { 00059 printf( " - failed converting to Unicode, Status == %X\n", Status ); 00060 DumpEnvironment(*env); 00061 printf( "\n" ); 00062 return; 00063 } 00064 if (Value != NULL) { 00065 RtlInitString( &ValueString, Value ); 00066 Status = RtlAnsiStringToUnicodeString(&uValueString, &ValueString, TRUE); 00067 printf( "TENV: set variable (%X) %Z=%Z\n", *env, &NameString, &ValueString ); 00068 Status = RtlSetEnvironmentVariable( env, &uNameString, &uValueString ); 00069 printf( "TENV: (%X)", *env); 00070 RtlFreeUnicodeString(&uNameString); 00071 RtlFreeUnicodeString(&uValueString); 00072 } 00073 else { 00074 printf( "TENV: delete variable (%X) %Z\n", *env, &NameString ); 00075 Status = RtlSetEnvironmentVariable( env, &uNameString, NULL ); 00076 printf( "TENV: (%X)", *env, &NameString, &ValueString ); 00077 RtlFreeUnicodeString(&uNameString); 00078 } 00079 00080 if (NT_SUCCESS( Status )) { 00081 printf( "\n" ); 00082 } 00083 else { 00084 printf( " - failed, Status == %X\n", Status ); 00085 } 00086 DumpEnvironment(*env); 00087 printf( "\n" ); 00088 }


Generated on Sat May 15 19:45:44 2004 for test by doxygen 1.3.7