char * lutil_getpass( const char *prompt ) { static char pbuf[PBUF]; FILE *fi; int c; unsigned i; #if defined(HAVE_TERMIOS_H) || defined(HAVE_SGTTY_H) TERMIO_TYPE ttyb; TERMFLAG_TYPE flags; RETSIGTYPE (*sig)( int sig ); #endif if( prompt == NULL ) prompt = _("Password: "******"->getpass(%s)\n", prompt); #endif #if defined(HAVE_TERMIOS_H) || defined(HAVE_SGTTY_H) if ((fi = fopen(TTY, "r")) == NULL) fi = stdin; else setbuf(fi, (char *)NULL); if (fi != stdin) { if (GETATTR(fileno(fi), &ttyb) < 0) perror("GETATTR"); sig = SIGNAL (SIGINT, SIG_IGN); flags = GETFLAGS( ttyb ); SETFLAGS( ttyb, flags & ~ECHO ); if (SETATTR(fileno(fi), &ttyb) < 0) perror("SETATTR"); } #else fi = stdin; #endif fprintf(stderr, "%s", prompt); fflush(stderr); i = 0; while ( (c = getc(fi)) != EOF && c != '\n' && c != '\r' ) if ( i < (sizeof(pbuf)-1) ) pbuf[i++] = c; #if defined(HAVE_TERMIOS_H) || defined(HAVE_SGTTY_H) /* tidy up */ if (fi != stdin) { fprintf(stderr, "\n"); fflush(stderr); SETFLAGS( ttyb, flags ); if (SETATTR(fileno(fi), &ttyb) < 0) perror("SETATTR"); (void) SIGNAL (SIGINT, sig); (void) fclose(fi); } #endif if ( c == EOF ) return( NULL ); pbuf[i] = '\0'; return (pbuf); }
///////////////////////////////////// // Name: // Purpose: // Output: // Return: ///////////////////////////////////// PROTECTED void * GFXPageGet(DWORD ID, LONGLONG *pCounter) { gfxPage *page; //page where obj resides int pIndex = ID / NUMPP; // Page index int bIndex = ID % NUMPP; // Block index if (pIndex >= g_gfxList.nPages) return NULL; // Trivially fail if client cannot exist page = g_gfxList.Pages [pIndex]; // Refer to client page if (GETFLAGS(page->status,GFX_SPOT_ONE << bIndex)) // Check whether block is in use { if(pCounter) *pCounter=page->stuff [bIndex].counter; return page->stuff [bIndex].data; // If so, return client data } return NULL;// Client is unavailable }
///////////////////////////////////// // Name: // Purpose: // Output: // Return: ///////////////////////////////////// PROTECTED void GFXPageAdd(void *item, gfxID *pID) { assert(item); // Verify that Data points to valid memory DWORD pIndex, bIndex; // Index of client page; index of client block gfxPage *page; FLAGS Mask = GFX_SPOT_ONE; // Mask used to test page availability if (g_gfxList.nPages * NUMPP == g_gfxList.nStuff) // Check whether all pages are full { pIndex = g_gfxList.nPages; // Get index of new page page = _GFXPageAdd(); // Append a new page to the manager } else // Pages are available { for (pIndex = 0; pIndex < g_gfxList.nPages; ++pIndex) // Loop through all pages if (g_gfxList.Pages [pIndex]->status != GFX_PAGE_FULL) break; // Break if page has openings page = g_gfxList.Pages [pIndex]; // Obtain refence to page } for (bIndex = 0; bIndex < NUMPP; ++bIndex) // Scan block occupancy flags { if (!GETFLAGS(page->status,Mask)) break; // Break if block is open Mask <<= GFX_NEXT_SPOT; // Update mask for next block } SETFLAG(page->status,Mask); // Indicate block is in use page->stuff[bIndex].data = item; // set obj ptr pID->ID = pIndex * NUMPP + bIndex; // Obtain obj ID page->stuff[bIndex].counter = pID->counter = ++g_uCounter; ++g_gfxList.nStuff; // Increment item count }
PRIVATE void _GFXPageClean(gfxPage *page) { gfxItem *obj = page->stuff, *nextObj; // Reference to objs on page if (page->status == GFX_PAGE_EMPTY) return; // Trivial success if page is empty while(page->status != GFX_PAGE_EMPTY) // Scan through all objects { nextObj = obj; nextObj++; if (GETFLAGS(page->status,GFX_SPOT_ONE)) // Check whether block is occupied { // destroy obj? obj->counter=0; obj->data=0; } obj=nextObj; page->status >>= GFX_PREV_SPOT; // Update mask for next block } }
char * lutil_getpass( const char *prompt ) { #if !defined(HAVE_POSIX_TERMIOS) && !defined(HAVE_SGTTY_H) static char buf[256]; int i, c; if( prompt == NULL ) prompt = "Password: "******"->getpass(%s)\n", prompt); #endif printf("%s", prompt); i = 0; while ( (c = getch()) != EOF && c != '\n' && c != '\r' ) buf[i++] = c; if ( c == EOF ) return( NULL ); buf[i] = '\0'; return (buf); #else int no_pass = 0; char i, j, k; TERMIO_TYPE ttyb; TERMFLAG_TYPE flags; static char pbuf[513]; register char *p; register int c; FILE *fi; RETSIGTYPE (*sig)( int sig ); if( prompt == NULL ) prompt = "Password: "******"->getpass(%s)\n", prompt); #endif /* * Stolen from the getpass() routine. Can't use the plain * getpass() for two reasons. One is that LDAP passwords * can be really, really long - much longer than 8 chars. * The second is that we like to make this client available * out of inetd via a Merit asynch port, and we need to be * able to do telnet control codes to turn on and off line * blanking. */ if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL) fi = stdin; else setbuf(fi, (char *)NULL); sig = SIGNAL (SIGINT, SIG_IGN); if (fi != stdin) { if (GETATTR(fileno(fi), &ttyb) < 0) perror("GETATTR"); } flags = GETFLAGS( ttyb ); SETFLAGS( ttyb, flags & ~ECHO ); if (fi != stdin) { if (SETATTR(fileno(fi), &ttyb) < 0) perror("SETATTR"); } /* blank the line if through Merit */ if (fi == stdin) { printf("%c%c%c", 255, 251, 1); fflush(stdout); (void) scanf("%c%c%c", &i, &j, &k); fflush(stdin); } /* fetch the password */ fprintf(stdout, "%s", prompt); fflush(stdout); for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) { if (c == '\r') break; if (p < &pbuf[512]) *p++ = c; } if (c == EOF) no_pass = 1; else { *p = '\0'; if (*(p - 1) == '\r') *(p - 1) = '\0'; } /* unblank the line if through Merit */ if (fi == stdin) { printf("%c%c%c", 255, 252, 1); fflush(stdout); (void) scanf("%c%c%c", &i, &j, &k); fflush(stdin); printf("\n"); fflush(stdout); } fprintf(stdout, "\n"); fflush(stdout); /* tidy up */ SETFLAGS( ttyb, flags ); if (fi != stdin) { if (SETATTR(fileno(fi), &ttyb) < 0) perror("SETATTR"); } (void) SIGNAL (SIGINT, sig); if (fi != stdin) (void) fclose(fi); else i = getchar(); if (no_pass) return(NULL); return(pbuf); #endif }