/*=========================================================================== FUNCTION: WriteLine DESCRIPTION This function displays lines of text on the screen, taking into account the number of text lines printed so far and the number of lines available for output. If all available lines are exhausted, this function returns without doing anything. If the last available line of the screen is reached, this function prints "..." to indicate that some lines may not have been printed due to lack of space. Otherwise, this function prints the line on the screen by calling DisplayOutput, and updates the count of lines printed based on how many lines DisplayOutput used to print the text. PROTOTYPE: static void WriteLine(CallDemoApp * pMe, char *pszStr, AECHAR *pszwStr, boolean isWideChar) PARAMETERS: pMe: [in]: Contains a pointer to this app's data structure. pszStr: [in]: The character string to be displayed on the screen. DEPENDENCIES Assumes the pMe->m_cLineNum gets initialized to the starting line for text display on the screen, and that pMe->m_cMaxLine contains the last available line for output on the screen. RETURN VALUE None. SIDE EFFECTS None ===========================================================================*/ static void WriteLine(CallDemoApp * pMe, char *pszStr, AECHAR *pszwStr, boolean isWideChar) { // If all available lines used, return if (pMe->m_cLineNum > pMe->m_cMaxLine) return; // If we've reached last available line, print an // ellipsis indicator if (pMe->m_cLineNum == pMe->m_cMaxLine) { DisplayOutput(pMe->a.m_pIShell, pMe->a.m_pIDisplay, pMe->m_cLineNum++, "...", NULL, FALSE); return; } // There are lines available for printing. Print the string passed as // input and update the count of lines available pMe->m_cLineNum += DisplayOutput(pMe->a.m_pIShell, pMe->a.m_pIDisplay, pMe->m_cLineNum, pszStr, pszwStr, isWideChar); return; } // End of WriteLine
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); } }
void DoSort(FILE *fp) { /* Step1 a Open the file and generate linked list */ trnx *t; char line[BUFFER]; char *tokens; char *op,*timeval,*amt,*description; int errCheck = 1; /* Generate a list and Initialise it */ My402List list; memset(&list,0,sizeof(My402List)); (void)My402ListInit(&list); /* */ fgets(line,BUFFER,fp); while (!feof(fp)) { /* Perform the necessary error checks for the line */ errCheck = errorCheckLine(line); if (errCheck == 0) { exit(0); } /* Extract each element in the file and store it each attribute of transaction. */ t = malloc(sizeof(trnx)); tokens = malloc(strlen(line)); amt = malloc(strlen(line)); strcpy(tokens,line); op = strtok(tokens,"\t"); timeval = strtok(NULL,"\t"); amt = strtok(NULL,"\t"); description = strtok(NULL,"\t"); /* Error Check for each of the tokens in the line */ /* Operator */ errCheck = 1; errCheck = errCheckOp(t,op); if (errCheck == 0) { fputs("Operator is invalid.Must be +/-\n",stderr); exit(0); } /* Time */ errCheck = 1; errCheck = errCheckTime(&list,t,timeval); if (errCheck == 0) { fputs("Timestamp is invalid.\n",stderr); exit(0); } /* Amount */ errCheck = 1; errCheck = errCheckAmount(t,amt); if (errCheck == 0) { fputs("Amount is invalid.\n",stderr); exit(0); } /* Description */ errCheck = errCheckDesc(t,description); if (errCheck == 0) { exit(0); } /* Create node in the list */ (void)My402ListAppend(&list,(void *)t); /* Get next element in the list */ //free(tokens); //free(amt); fgets(line,BUFFER,fp); } fclose(fp); //PrintList(&list); BubbleSortList(&list,list.num_members); //PrintList(&list); DisplayOutput(&list); }
int GetTrustees (NWCONN_HANDLE ConnHandle, NWDIR_HANDLE DirHandle, pnstr8 Path, nuint16 NameSpace, nuint16 SubDir, FILE* fh) { int i; // Used for iterating through trustee lists NW_ENTRY_INFO* EntryInfo; // Netware structure for file / folder info NW_ENTRY_INFO2* Children; // List of child files and folders NWET_INFO* TrusteeInfo; // Netware structure for holding a list of trustees nuint16 NumEntries; // Pointer to the number of entries returned by NDS Api functions SEARCH_SEQUENCE* Seq; // Sequence number used by NDS Api NWDSCCODE res; // Variable to store the result of functions - 0=Success nuint16 FileFlag; // Specifies a file or folder nuint32 IterHandle; // Iteration handle for NDS functions pnstr8 Trustee; // String to hold trustee name after its been converted from ObjectID pnstr8 IRights; // String represent the inherited rights filter pnstr8 Rights; // String to represent rights pnstr8 DosPath; // String to hold Path converted to Netware (DOS) notation NWDIR_HANDLE* TempDirHandle; // Temporary directory handle to use for getting subfolders pnstr8 NextPath; // String to hold the name of the subfolder EntryInfo = (NW_ENTRY_INFO*) malloc (sizeof (NW_ENTRY_INFO)); TrusteeInfo = (NWET_INFO*) malloc (sizeof (NWET_INFO)); Trustee = (pnstr8) malloc (sizeof (nstr8) * MAX_DN_CHARS+1); IRights = (pnstr8) malloc (sizeof (nstr8) * 10); Rights = (pnstr8) malloc (sizeof (nstr8) * 10); DosPath = (pnstr8) malloc (sizeof (nstr8) * 256); if (EntryInfo && TrusteeInfo && Trustee && IRights && Rights && DosPath) { // Find out whether Path is a file or folder, and get the inherited rights filter if ((res = NWGetNSEntryInfo (ConnHandle, DirHandle, Path, NW_NS_LONG, NW_NS_LONG, SA_ALL, IM_ATTRIBUTES | IM_RIGHTS | IM_NAME, EntryInfo)) != 0) printf ("NWGetNSEntryInfo returned: %d\n", res); // Print the inherited rights as a string - all the rights are ORed together to make an nuint16. if ((EntryInfo->inheritedRightsMask & TA_ALL) != TA_ALL) { strcpy (IRights, ""); if ((EntryInfo->inheritedRightsMask & TA_NONE) == TA_NONE) strcat (IRights, "S"); if ((EntryInfo->inheritedRightsMask & TA_READ) == TA_READ) strcat (IRights, "R"); if ((EntryInfo->inheritedRightsMask & TA_WRITE) == TA_WRITE) strcat (IRights, "W"); if ((EntryInfo->inheritedRightsMask & TA_CREATE) == TA_CREATE) strcat (IRights, "C"); if ((EntryInfo->inheritedRightsMask & TA_DELETE) == TA_DELETE) strcat (IRights, "E"); if ((EntryInfo->inheritedRightsMask & TA_MODIFY) == TA_MODIFY) strcat (IRights, "M"); if ((EntryInfo->inheritedRightsMask & TA_SEARCH) == TA_SEARCH) strcat (IRights, "F"); if ((EntryInfo->inheritedRightsMask & TA_OWNERSHIP) == TA_OWNERSHIP)strcat (IRights, "A"); // printf ("%s\t%s\t/F\n", Path, IRights); DisplayOutput (Path, IRights, "/F", SUCCESS, NULL); if (fh) fprintf (fh,"RIGHTS \"%s\" %s /F\n", Path, IRights); } // Get the short path name, as NWIntScanForTrustees will only work with the default name space if ((res = GetShortPath (ConnHandle, DirHandle, Path, NameSpace, DosPath, 256, &FileFlag)) != 0) { printf ("GetShortPath returned: %d\n", res); return 1; } IterHandle = 0; // Iteratively scan for trustees until there are no more while (NWIntScanForTrustees (ConnHandle, 0, DosPath, &IterHandle, &NumEntries, TrusteeInfo, 0) == 0) { // arrays of 20 trustees are returned for (i=0;i<20;i++) { // if an entry hasn't been populated, it is set to 0L if (TrusteeInfo->trusteeList[i].objectID != 0L) { // An object id is returned representing a trustee, so convert to a string if ((res = NWDSMapIDToName (NDSContext, ConnHandle, TrusteeInfo->trusteeList[i].objectID, Trustee)) != 0) printf ("NWDSMapIDToName returned: %d\n", res); else { // Convert the rights to a string, again rights are ORed together strcpy (Rights, ""); if ((TrusteeInfo->trusteeList[i].objectRights & TR_SUPERVISOR) == TR_SUPERVISOR) strcat (Rights, "S"); if ((TrusteeInfo->trusteeList[i].objectRights & TR_READ) == TR_READ) strcat (Rights, "R"); if ((TrusteeInfo->trusteeList[i].objectRights & TR_WRITE) == TR_WRITE) strcat (Rights, "W"); if ((TrusteeInfo->trusteeList[i].objectRights & TR_CREATE) == TR_CREATE) strcat (Rights, "C"); if ((TrusteeInfo->trusteeList[i].objectRights & TR_DELETE) == TR_DELETE) strcat (Rights, "E"); if ((TrusteeInfo->trusteeList[i].objectRights & TR_MODIFY) == TR_MODIFY) strcat (Rights, "M"); if ((TrusteeInfo->trusteeList[i].objectRights & TR_FILE_SCAN) == TR_FILE_SCAN) strcat (Rights, "F"); if ((TrusteeInfo->trusteeList[i].objectRights & TR_ACCESS_CTRL) == TR_ACCESS_CTRL) strcat (Rights, "A"); //printf ("%s\t%s\t/NAME=%s\n", Path, Rights, Trustee); DisplayOutput (Path, Rights, Trustee, SUCCESS, NULL); if (fh) fprintf (fh,"RIGHTS \"%s\" %s /NAME=\"%s\"\n", Path, Rights, Trustee); } } } } // If we're examining a directory, then scan files and folder within the directory // NOTE: all the variable assigned here are malloc'ed so that only the pointers go on the stack // in recursive calls. I changed this because I was getting some stack overflow problems // on large directory structure on NW5.1 // added a check to see if the NLM was exiting via the sig handler - if it is, stop processing and clean up if (((EntryInfo->attributes & A_DIRECTORY) == A_DIRECTORY) && (SubDir != 0) && (NlmExiting == FALSE)) { Children = (NW_ENTRY_INFO2*) malloc (sizeof (NW_ENTRY_INFO2)); Seq = (SEARCH_SEQUENCE*) malloc (sizeof (SEARCH_SEQUENCE)); TempDirHandle = (NWDIR_HANDLE*) malloc (sizeof (NWDIR_HANDLE)); if (Children && Seq && TempDirHandle) { if ((res = NWAllocTempNSDirHandle2 (ConnHandle, DirHandle, Path, NW_NS_LONG, TempDirHandle, NW_NS_LONG)) != 0) printf ("NWAllocTempNSDirHandle2 returned: %d\n", res); Seq->searchDirNumber = -1; while (NWScanNSEntryInfo2 (ConnHandle, *TempDirHandle, NW_NS_LONG, SA_ALL, Seq, "*" ,IM_NAME, Children) == 0) { if ((NextPath = (char*) malloc (sizeof (char) * (strlen (Children->entryName) + strlen (Path) + 2))) == NULL) printf ("Couldn't allocate memory\n"); else { strcpy (NextPath, Path); strcat (NextPath, "\\"); strcat (NextPath, Children->entryName); // Iterativly call GetTrustees on subfolders GetTrustees (ConnHandle, 0, NextPath, NameSpace, SubDir, fh); free (NextPath); } } NWDeallocateDirectoryHandle (ConnHandle, *TempDirHandle); } if (Children) free (Children); if (Seq) free (Seq); if (TempDirHandle) free (TempDirHandle); } } // cleanup if (EntryInfo) free (EntryInfo); if (TrusteeInfo) free (TrusteeInfo); if (Trustee) free (Trustee); if (IRights) free (IRights); if (Rights) free (Rights); if (DosPath) free (DosPath); return 0; }