void NLMsignals(void) { ++NLM_threadCnt; NLM_mainThreadGroupID = GetThreadGroupID(); signal(SIGTERM, NLM_SignalHandler); signal(SIGINT, NLM_SignalHandler); }
void NLM_SignalHandler(int sig) #pragma on(unreferenced); { int handlerThreadGroupID; switch(sig) { case SIGTERM: NLM_exiting = TRUE; handlerThreadGroupID = GetThreadGroupID(); SetThreadGroupID(NLM_mainThreadGroupID); /* NLM SDK functions may be called here */ while (NLM_threadCnt != 0) ThreadSwitchWithDelay(); SetThreadGroupID(handlerThreadGroupID); break; case SIGINT: signal(SIGINT, NLM_SignalHandler); break; } return; }
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; }