void main (int argc, char** argv) { FILE* pfile = NULL; int k; int thechar; char* defaultDir; fnInitGpfGlobals(); SetCurrentNameSpace(NWOS2_NAME_SPACE); defaultDir = (char *)getenv("PERL_ROOT"); if (!defaultDir || (strlen(defaultDir) == 0)) defaultDir = "sys:\\perl\\scripts"; chdir(defaultDir); k = 1; while (k < argc) { // open the next file and print it out pfile = fopen(argv[k],"r"); if (pfile) { while ((thechar = getc(pfile)) != EOF) { if (thechar != 0x0d) printf("%c",thechar); } fclose (pfile); } k++; } }
NETDB_DEFINE_CONTEXT /* Make the CLIB Inet stuff link */ #include <netinet/in.h> #include <arpa/inet.h> NETINET_DEFINE_CONTEXT int netware_init ( void ) { int rc = 0; unsigned int myHandle = GetNLMHandle(); /* import UnAugmentAsterisk dynamically for NW4.x compatibility */ void (*pUnAugmentAsterisk)(int) = (void(*)(int)) ImportSymbol(myHandle, "UnAugmentAsterisk"); /* import UseAccurateCaseForPaths dynamically for NW3.x compatibility */ void (*pUseAccurateCaseForPaths)(int) = (void(*)(int)) ImportSymbol(myHandle, "UseAccurateCaseForPaths"); if(pUnAugmentAsterisk) pUnAugmentAsterisk(1); if(pUseAccurateCaseForPaths) pUseAccurateCaseForPaths(1); UnimportSymbol(myHandle, "UnAugmentAsterisk"); UnimportSymbol(myHandle, "UseAccurateCaseForPaths"); /* set long name space */ if((SetCurrentNameSpace(4) == 255)) { rc = 1; } if((SetTargetNameSpace(4) == 255)) { rc = rc + 2; } return rc; }
int main(int argc, char** argv) { /* * Hook the unload routine in */ signal( SIGTERM, SigTermSignalHandler ) ; /* * Initialize the memory allocator. Allow use of malloc and start * with a 60K heap. For each page request approx 8KB is allocated. * 60KB allows for several concurrent page requests. If more space * is required, malloc will be used for the overflow. */ bopen(NULL, (60 * 1024), B_USE_MALLOC); P( 1 ) ; /* * Switch to LONG name-space. If LONG is not loaded, WEBS will default * to 8.3 */ SetCurrentNameSpace( 4 ) ; /* * Initialize the web server */ if (initWebs() < 0) { return -1; } #ifdef WEBS_SSL_SUPPORT websSSLOpen(); #endif P( 20 ) ; /* * Basic event loop. SocketReady returns true when a socket is ready for * service. SocketSelect will block until an event occurs. SocketProcess * will actually do the servicing. */ while (!finished) { if (socketReady(-1) || socketSelect(-1, 1000)) { socketProcess(-1); ThreadSwitch() ; } websCgiCleanup(); emfSchedProcess(); } NLMcleanup() ; return 0; }
int main(int argc, char *argv[]) { FILE *tfp, *f; char user[MAX_STRING_LEN]; char realm[MAX_STRING_LEN]; char line[MAX_STRING_LEN]; char l[MAX_STRING_LEN]; char w[MAX_STRING_LEN]; char x[MAX_STRING_LEN]; char command[MAX_STRING_LEN]; int found; tn = NULL; signal(SIGINT, (void (*)(int)) interrupted); if (argc == 5) { if (strcmp(argv[1], "-c")) usage(); #ifdef NETWARE UnAugmentAsterisk(TRUE); SetCurrentNameSpace(NW_NS_LONG); SetTargetNameSpace(NW_NS_LONG); #endif if (!(tfp = fopen(argv[2], "w"))) { fprintf(stderr, "Could not open passwd file %s for writing.\n", argv[2]); perror("fopen"); exit(1); } printf("Adding password for %s in realm %s.\n", argv[4], argv[3]); add_password(argv[4], argv[3], tfp); fclose(tfp); exit(0); } else if (argc != 4) usage(); tn = tmpnam(NULL); if (!(tfp = fopen(tn, "w"))) { fprintf(stderr, "Could not open temp file.\n"); exit(1); } if (!(f = fopen(argv[1], "r"))) { fprintf(stderr, "Could not open passwd file %s for reading.\n", argv[1]); fprintf(stderr, "Use -c option to create new one.\n"); exit(1); } ap_cpystrn(user, argv[3], sizeof(user)); ap_cpystrn(realm, argv[2], sizeof(realm)); found = 0; while (!(getline(line, MAX_STRING_LEN, f))) { if (found || (line[0] == '#') || (!line[0])) { putline(tfp, line); continue; } strcpy(l, line); getword(w, l, ':'); getword(x, l, ':'); if (strcmp(user, w) || strcmp(realm, x)) { putline(tfp, line); continue; } else { printf("Changing password for user %s in realm %s\n", user, realm); add_password(user, realm, tfp); found = 1; } } if (!found) { printf("Adding user %s in realm %s\n", user, realm); add_password(user, realm, tfp); } fclose(f); fclose(tfp); #ifndef NETWARE #if defined(OS2) || defined(WIN32) sprintf(command, "copy \"%s\" \"%s\"", tn, argv[1]); #else sprintf(command, "cp %s %s", tn, argv[1]); #endif system(command); #else if (!(tfp = fopen(tn, "r"))) { fprintf(stderr, "Could not open temp file.\n"); exit(1); } if (!(f = fopen(argv[1], "w"))) { fprintf(stderr, "Could not open %s.\n", argv[1]); exit(1); } copy_file(f, tfp); #endif unlink(tn); return 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; }
void Restore (NWCONN_HANDLE ConnHandle, char* FileName, char* Logfilename) { char Line [1024]; char* Next; char Buffer [512]; FILE* BackupFile; FILE* Logfile; char FirstParam [512]; char Rights [12]; char Object [300]; int ArgNo; char Op [8]; NWDSCCODE res; BYTE OldNameSpace; // save the default namespace OldNameSpace = SetCurrentNameSpace (NW_NS_LONG); // attempt to open the backup file if ((BackupFile = fopen (FileName, "r")) == NULL) printf ("Couldn\'t open file: %s\n", FileName); else { if (Logfilename) { if ((Logfile = fopen (Logfilename, "w")) == NULL) { printf ("Couldn't open %s\n", Logfilename); Logfile = NULL; } } else Logfile = NULL; // read file line by line - also, check that the NLM hasn't been terminated while ((!feof (BackupFile)) && (!NlmExiting)) { fgets (Line, 1024, BackupFile); if (!feof (BackupFile)) { Next = Line; ArgNo = 0; // use GetParams to iteratively get the equivalent argvs while (strcmp ((Next = GetParam (Next, Buffer, 512)), "") != 0 || strcmp (Buffer, "") != 0) { // copy string depending on the argument number ArgNo++; if (ArgNo == 1) { if (stricmp (Buffer, "RIGHTS") != 0 && stricmp (Buffer, "cx") != 0) break; else strncpy (Op, Buffer, 8); } else if (ArgNo == 2) strcpy (FirstParam, Buffer); else if (ArgNo == 3) { strncpy (Rights, Buffer, 12); Rights [11] = 0; } else if (ArgNo == 4) { if (strncmp (Buffer, "/NAME=", 6) == 0 || strncmp (Buffer, "/name=", 6) == 0) TrimQuotes (Object, Buffer, MAX_DN_CHARS); else if (stricmp (Buffer, "/F") == 0) strcpy (Object, "/F"); else strcpy (Object, ""); } else break; } // if the syntax is valid call the appropriate function to // set trustee rights or IRFs if (stricmp (Op, "RIGHTS") ==0 && ArgNo == 4) { if (strncmp (Object, "/F", 2) == 0 || strncmp (Object, "/f", 2) == 0) { // printf ("IRF: %s, %s\n", FirstParam, Rights); // if (Clear != 0) // InheritedRights (ConnHandle, 0, FirstParam, NW_NS_LONG, "RWCFEMA"); res = InheritedRights (ConnHandle, 0, FirstParam, NW_NS_LONG, Rights); DisplayOutput (FirstParam, Rights, "/F", res, Logfile); } if (strncmp (Object, "/NAME=", 6) == 0 || strncmp (Object, "/name=", 6) == 0) { // printf ("Rights: %s, %s, %s\n", FirstParam, Rights, Object); // if (Clear != 0) // TrusteeRights (ConnHandle, 0, FirstParam, NW_NS_LONG, Object+6, "REM"); res = TrusteeRights (ConnHandle, 0, FirstParam, NW_NS_LONG, Object+6, Rights); DisplayOutput (FirstParam, Rights, Object+6, res, Logfile); } } // code to change context if (stricmp (Op, "cx") == 0 && ArgNo == 2) { if ((res = NWDSSetContext (NDSContext, DCK_NAME_CONTEXT, FirstParam)) != 0) printf ("NWDSSetContext returned: %d\n", res); } } } // close the file and restore the original name space fclose (BackupFile); if (Logfile) fclose (Logfile); SetTargetNameSpace (OldNameSpace); } }
/* * Let's do it. We end up doing a lot of file opening and closing, * but what do we care? This application isn't run constantly. */ int main(int argc, char *argv[]) { FILE *ftemp = NULL; FILE *fpw = NULL; char user[MAX_STRING_LEN]; char password[MAX_STRING_LEN]; char record[MAX_STRING_LEN]; char line[MAX_STRING_LEN]; char pwfilename[MAX_STRING_LEN]; char *arg; int found = 0; int alg = ALG_CRYPT; int newfile = 0; int nofile = 0; int noninteractive = 0; int i; int args_left = 2; tempfilename = NULL; signal(SIGINT, (void (*)(int)) interrupted); /* * Preliminary check to make sure they provided at least * three arguments, we'll do better argument checking as * we parse the command line. */ if (argc < 3) { return usage(); } /* * Go through the argument list and pick out any options. They * have to precede any other arguments. */ for (i = 1; i < argc; i++) { arg = argv[i]; if (*arg != '-') { break; } while (*++arg != '\0') { if (*arg == 'c') { newfile++; } else if (*arg == 'n') { nofile++; args_left--; } else if (*arg == 'm') { alg = ALG_APMD5; } else if (*arg == 's') { alg = ALG_APSHA; } else if (*arg == 'p') { alg = ALG_PLAIN; } else if (*arg == 'd') { alg = ALG_CRYPT; } else if (*arg == 'b') { noninteractive++; args_left++; } else { return usage(); } } } /* * Make sure we still have exactly the right number of arguments left * (the filename, the username, and possibly the password if -b was * specified). */ if ((argc - i) != args_left) { return usage(); } #ifdef NETWARE UnAugmentAsterisk(TRUE); SetCurrentNameSpace(NW_NS_LONG); SetTargetNameSpace(NW_NS_LONG); #endif if (newfile && nofile) { fprintf(stderr, "%s: -c and -n options conflict\n", argv[0]); return ERR_SYNTAX; } if (nofile) { i--; } else { if (strlen(argv[i]) > (sizeof(pwfilename) - 1)) { fprintf(stderr, "%s: filename too long\n", argv[0]); return ERR_OVERFLOW; } strcpy(pwfilename, argv[i]); if (strlen(argv[i + 1]) > (sizeof(user) - 1)) { fprintf(stderr, "%s: username too long (>%lu)\n", argv[0], (unsigned long)(sizeof(user) - 1)); return ERR_OVERFLOW; } } strcpy(user, argv[i + 1]); if ((arg = strchr(user, ':')) != NULL) { fprintf(stderr, "%s: username contains illegal character '%c'\n", argv[0], *arg); return ERR_BADUSER; } if (noninteractive) { if (strlen(argv[i + 2]) > (sizeof(password) - 1)) { fprintf(stderr, "%s: password too long (>%lu)\n", argv[0], (unsigned long)(sizeof(password) - 1)); return ERR_OVERFLOW; } strcpy(password, argv[i + 2]); } #ifdef WIN32 if (alg == ALG_CRYPT) { alg = ALG_APMD5; fprintf(stderr, "Automatically using MD5 format on Windows.\n"); } #elif defined(TPF) || defined(NETWARE) if (alg == ALG_CRYPT) { alg = ALG_APMD5; fprintf(stderr, "Automatically using MD5 format.\n"); } #endif #if (!(defined(WIN32) || defined(TPF) || defined(NETWARE))) if (alg == ALG_PLAIN) { fprintf(stderr,"Warning: storing passwords as plain text might " "just not work on this platform.\n"); } #endif if (! nofile) { /* * Only do the file checks if we're supposed to frob it. * * Verify that the file exists if -c was omitted. We give a special * message if it doesn't. */ if ((! newfile) && (! exists(pwfilename))) { fprintf(stderr, "%s: cannot modify file %s; use '-c' to create it\n", argv[0], pwfilename); perror("fopen"); exit(ERR_FILEPERM); } /* * Verify that we can read the existing file in the case of an update * to it (rather than creation of a new one). */ if ((! newfile) && (! readable(pwfilename))) { fprintf(stderr, "%s: cannot open file %s for read access\n", argv[0], pwfilename); perror("fopen"); exit(ERR_FILEPERM); } /* * Now check to see if we can preserve an existing file in case * of password verification errors on a -c operation. */ if (newfile && exists(pwfilename) && (! readable(pwfilename))) { fprintf(stderr, "%s: cannot open file %s for read access\n" "%s: existing auth data would be lost on " "password mismatch", argv[0], pwfilename, argv[0]); perror("fopen"); exit(ERR_FILEPERM); } /* * Now verify that the file is writable! */ if (! writable(pwfilename)) { fprintf(stderr, "%s: cannot open file %s for write access\n", argv[0], pwfilename); perror("fopen"); exit(ERR_FILEPERM); } } /* * All the file access checks (if any) have been made. Time to go to work; * try to create the record for the username in question. If that * fails, there's no need to waste any time on file manipulations. * Any error message text is returned in the record buffer, since * the mkrecord() routine doesn't have access to argv[]. */ i = mkrecord(user, record, sizeof(record) - 1, noninteractive ? password : NULL, alg); if (i != 0) { fprintf(stderr, "%s: %s\n", argv[0], record); exit(i); } if (nofile) { printf("%s\n", record); exit(0); } /* * We can access the files the right way, and we have a record * to add or update. Let's do it.. */ errno = 0; tempfilename = tmpnam(tname_buf); if ((tempfilename == NULL) || (*tempfilename == '\0')) { fprintf(stderr, "%s: unable to generate temporary filename\n", argv[0]); if (errno == 0) { errno = ENOENT; } perror("tmpnam"); exit(ERR_FILEPERM); } ftemp = fopen(tempfilename, "w+"); if (ftemp == NULL) { fprintf(stderr, "%s: unable to create temporary file '%s'\n", argv[0], tempfilename); perror("fopen"); exit(ERR_FILEPERM); } /* * If we're not creating a new file, copy records from the existing * one to the temporary file until we find the specified user. */ if (! newfile) { char scratch[MAX_STRING_LEN]; fpw = fopen(pwfilename, "r"); while (! (getline(line, sizeof(line), fpw))) { char *colon; if ((line[0] == '#') || (line[0] == '\0')) { putline(ftemp, line); continue; } strcpy(scratch, line); /* * See if this is our user. */ colon = strchr(scratch, ':'); if (colon != NULL) { *colon = '\0'; } if (strcmp(user, scratch) != 0) { putline(ftemp, line); continue; } found++; break; } } if (found) { fprintf(stderr, "Updating "); } else { fprintf(stderr, "Adding "); } fprintf(stderr, "password for user %s\n", user); /* * Now add the user record we created. */ putline(ftemp, record); /* * If we're updating an existing file, there may be additional * records beyond the one we're updating, so copy them. */ if (! newfile) { copy_file(ftemp, fpw); fclose(fpw); } /* * The temporary file now contains the information that should be * in the actual password file. Close the open files, re-open them * in the appropriate mode, and copy them file to the real one. */ fclose(ftemp); fpw = fopen(pwfilename, "w+"); ftemp = fopen(tempfilename, "r"); copy_file(fpw, ftemp); fclose(fpw); fclose(ftemp); unlink(tempfilename); return 0; }