time_t time(time_t *tvec) { time_t ttvec; if (tvec == NULL) { gtime(&ttvec); return ttvec; } gtime(tvec); return *tvec; }
int update() { float old_time = last_time_updated; last_time_updated = gtime(); dt = last_time_updated - old_time; for (int i = 0; i < frame_time_count-1; i++) last_frame_deltas[i+1] = last_frame_deltas[i]; last_frame_deltas[0] = dt; for (std::vector<Ship*>::iterator it = ship_list.begin(); it != ship_list.end(); ++it) { bool* keylist = 0; if ((*it)->player) { keylist = getkeylistfromkeys(); } else { update_brain(*it); keylist = (*it)->brain->readout(); } applykeys(*it, keylist); delete keylist; } cpSpaceStep(space, dt); removeshells(); return 0; }
int openwindow(Genome* g1=0, Genome* g2=0) { Phys phys; phys.init(g1, g2); Rend rend; rend.init(); while (rend.window->isOpen()) { sf::Event event; while (rend.window->pollEvent(event)) { switch (event.type) { case sf::Event::Closed: { rend.window->close(); break; } case sf::Event::MouseWheelScrolled: { rend.mouse_wheel = event.mouseWheelScroll.delta; break; } case sf::Event::KeyPressed: { if (event.key.code == sf::Keyboard::Key::P && gtime() - phys.last_pressed > 0.3) phys.paused = !phys.paused; break; } default: break; } } if (phys.paused) { phys.last_time_updated = gtime(); } else { phys.update(); } rend.render(&phys); } return 0; }
int main(int argc, char *argv[]) { register char *tzn; struct timeb info; int wf, rc; rc = 0; ftime(&info); if (argc>1 && argv[1][0]=='-' && argv[1][1]=='u') { argc--; argv++; uflag++; } if(argc > 1) { ap = argv[1]; if (gtime()) { printf("date: bad conversion\n"); exit(1); } /* convert to GMT assuming local time */ if (uflag==0) { timbuf += (long)info.timezone*60; /* now fix up local daylight time */ if(localtime(&timbuf)->tm_isdst) timbuf -= 60*60; } time(&timevalue); wtmp[0].ut_time = timevalue; if(stime(&timbuf) < 0) { rc++; printf("date: no permission\n"); // TODO: check! } else if ((wf = open("/usr/adm/wtmp", O_WRONLY|O_CREAT|O_APPEND)) >= 0) { wtmp[1].ut_time = timevalue; //lseek(wf, 0L, 2); write(wf, (char *)wtmp, sizeof(wtmp)); close(wf); } } if (rc==0) time(&timbuf); if(uflag) { ap = asctime(gmtime(&timbuf)); tzn = "GMT"; } else { struct tm *tp; tp = localtime(&timbuf); ap = asctime(tp); tzn = timezone(info.timezone, tp->tm_isdst); } printf("%.20s", ap); if (tzn) printf("%s", tzn); printf("%s", ap+19); exit(rc); }
int maininit() { ship_list.clear(); shell_list.clear(); rshell = 0; nrshell = 0; space = cpSpaceNew(); last_time_updated = gtime(); dt = 1.; paused = 0; last_pressed = 0; cpCollisionHandler *handler = cpSpaceAddCollisionHandler(space, 1, 2); handler->beginFunc = scorecollision; last_frame_deltas = new float[frame_time_count]; for (int i = 0; i < frame_time_count; i++) last_frame_deltas[i] = 1; return 0; }
void TERMWINDOWMEMBER cron_commands(void) { int ich; SetDoWhat(SYSCRON); switch (toupper(ich = iCharNE())) { case 'A': { mPrintfCR(getsysmsg(68)); if (WAITFORmTIMED(CronMutex)) { CronEventListS *theEvent; for (int i = 1; (theEvent = Cron.GetEventNum(i)) != NULL; i++) { theEvent->Event.SetDone(); } RELEASEm(CronMutex); CRmPrintfCR(getsysmsg(69)); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'D': { mPrintfCR(getsysmsg(70)); if (WAITFORmTIMED(CronMutex)) { CronEventC *theEvent = GetEventFromUser(); if (theEvent) { theEvent->SetDone(); } RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'E': { mPrintfCR(getsysmsg(71)); if (WAITFORmTIMED(CronMutex)) { Cron.ReadCronCit(WC_TWp); RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'F': { mPrintfCR(getsysmsg(72)); if (WAITFORmTIMED(CronMutex)) { CronEventC *theEvent = GetEventFromUser(); if (theEvent) { theEvent->Do(); } RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'L': { mPrintfCR(getsysmsg(73)); if (WAITFORmTIMED(CronMutex)) { ListAllEvents(); RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'N': { mPrintfCR(getsysmsg(74)); if (WAITFORmTIMED(CronMutex)) { Cron.SetOnEvent(GetEventFromUser()); RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'P': { Cron.TogglePause(); displayOnOff(getsysmsg(75), Cron.IsPaused()); doCR(); break; } case 'R': { mPrintfCR(getsysmsg(76)); if (WAITFORmTIMED(CronMutex)) { CronEventC *theEvent = GetEventFromUser(); if (theEvent) { theEvent->Reset(); } RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'S': { mPrintfCR(getsysmsg(268)); if (WAITFORmTIMED(CronMutex)) { CronEventC *theEvent = GetEventFromUser(); if (theEvent) { Bool First = TRUE; struct date dt; struct time tm; datestruct ds; timestruct ts; do { if (!HaveConnectionToUser()) { RELEASEm(CronMutex); return; } if (!First) { mPrintfCR(getmsg(156)); } First = FALSE; label usrIn; if (!GetStringWithBlurb(getmsg(266), usrIn, LABELSIZE, ns, B_DATESET)) { RELEASEm(CronMutex); return; } gdate(usrIn, &ds); } while (!ds.Date); First = TRUE; do { if (!HaveConnectionToUser()) { RELEASEm(CronMutex); return; } if (!First) { mPrintfCR(getmsg(121)); } First = FALSE; label usrIn; if (!GetStringWithBlurb(getmsg(230), usrIn, LABELSIZE, ns, B_TIMESET)) { RELEASEm(CronMutex); return; } gtime(usrIn, &ts); } while (ts.Hour < 0); tm.ti_min = (uchar) ts.Minute; tm.ti_hour = (uchar) ts.Hour; tm.ti_sec = (uchar) ts.Second; dt.da_year = ds.Year + 1900; // i hate dostounix dt.da_day = (char) ds.Date; dt.da_mon = (char) (ds.Month + 1); // i hate dostounix time_t tried = dostounix(&dt, &tm); theEvent->SetLastSuccess(tried); theEvent->SetLastTried(tried); label dtstr; strftime(dtstr, LABELSIZE, getmsg(435), tried); CRmPrintf(getmsg(598), dtstr); strftime(dtstr, LABELSIZE, getmsg(434), tried); CRmPrintfCR(getmsg(607), dtstr); } RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case 'Z': { mPrintfCR(getsysmsg(77)); if (WAITFORmTIMED(CronMutex)) { CronEventC *theEvent = GetEventFromUser(); if (theEvent) { theEvent->ToggleZap(); } RELEASEm(CronMutex); } else { CRmPrintfCR(getsysmsg(264)); } break; } case '?': { oChar('?'); showMenu(M_CRON); break; } default: { BadMenuSelection(ich); break; } } }
/* * move blocks between queues if they are ready. * schedule an interrupt for the next interesting time. * * must be called with the link ilocked. */ static void pushlink(Link *link, vlong now) { Block *bp; vlong tout, tin; /* * put another block in the link queue */ ilock(link); if(link->iq == nil || link->oq == nil){ iunlock(link); return; } timerdel(&link->ci); /* * put more blocks into the xmit queue * use the time the last packet was supposed to go out * as the start time for the next packet, rather than * the current time. this more closely models a network * device which can queue multiple output packets. */ tout = link->tout; if(!tout) tout = now; while(tout <= now){ bp = qget(link->oq); if(bp == nil){ tout = 0; break; } /* * can't send the packet before it gets queued */ tin = gtime(bp->rp); if(tin > tout) tout = tin; tout = tout + (BLEN(bp) - Tmsize) * link->delayn; /* * drop packets */ if(link->droprate && nrand(link->droprate) == 0) link->drops++; else{ ptime(bp->rp, tout + link->delay0ns); if(link->tq == nil) link->tq = bp; else link->tqtail->next = bp; link->tqtail = bp; } } /* * record the next time a packet can be sent, * but don't schedule an interrupt if none is waiting */ link->tout = tout; if(!qcanread(link->oq)) tout = 0; /* * put more blocks into the receive queue */ tin = 0; while(bp = link->tq){ tin = gtime(bp->rp); if(tin > now) break; bp->rp += Tmsize; link->tq = bp->next; bp->next = nil; if(!link->indrop) qpassnolim(link->iq, bp); else if(qpass(link->iq, bp) < 0) link->soverflows++; tin = 0; } if(bp == nil && qisclosed(link->oq) && !qcanread(link->oq) && !qisclosed(link->iq)) qhangup(link->iq, nil); link->tin = tin; if(!tin || tin > tout && tout) tin = tout; link->ci.ns = tin - now; if(tin){ if(tin < now) panic("loopback unfinished business"); timeradd(&link->ci); } iunlock(link); }
static void time_end() { printf("took %lu microseconds\n", gtime() - lt); }
static void time_start() { lt = gtime(); }
static int rzdir(Xfs *fs, Dir *d, int fmt, Drec *dp) { int n, flags, i, j, lj, nl, vers, sysl, mode, l, have; uint8_t *s; char *p; char buf[Maxname+UTFmax+1]; uint8_t *q; Rune r; enum { ONAMELEN = 28 }; /* old Plan 9 directory name length */ have = 0; flags = 0; vers = -1; d->qid.path = l32(dp->addr); d->qid.type = 0; d->qid.vers = 0; n = dp->namelen; memset(d->name, 0, Maxname); if(n == 1) { switch(dp->name[0]){ case 1: d->name[1] = '.'; /* fall through */ case 0: d->name[0] = '.'; have = Hname; break; default: d->name[0] = tolower(dp->name[0]); } } else { if(fmt == 'J'){ /* Joliet, 16-bit Unicode */ q = (uint8_t*)dp->name; for(i=j=lj=0; i<n && j<Maxname; i+=2){ lj = j; r = (q[i]<<8)|q[i+1]; j += runetochar(buf+j, &r); } if(j >= Maxname) j = lj; memmove(d->name, buf, j); }else{ if(n >= Maxname) n = Maxname-1; for(i=0; i<n; i++) d->name[i] = tolower(dp->name[i]); } } sysl = dp->reclen-(34+dp->namelen); s = (uint8_t*)dp->name + dp->namelen; if(((uintptr)s) & 1) { s++; sysl--; } if(fs->isplan9 && sysl > 0) { /* * get gid, uid, mode and possibly name * from plan9 directory extension */ nl = *s; if(nl >= ONAMELEN) nl = ONAMELEN-1; if(nl) { memset(d->name, 0, ONAMELEN); memmove(d->name, s+1, nl); } s += 1 + *s; nl = *s; if(nl >= ONAMELEN) nl = ONAMELEN-1; memset(d->uid, 0, ONAMELEN); memmove(d->uid, s+1, nl); s += 1 + *s; nl = *s; if(nl >= ONAMELEN) nl = ONAMELEN-1; memset(d->gid, 0, ONAMELEN); memmove(d->gid, s+1, nl); s += 1 + *s; if(((uintptr)s) & 1) s++; d->mode = l32(s); if(d->mode & DMDIR) d->qid.type |= QTDIR; } else { d->mode = 0444; switch(fmt) { case 'z': if(fs->isrock) strcpy(d->gid, "ridge"); else strcpy(d->gid, "iso9660"); flags = dp->flags; break; case 'r': strcpy(d->gid, "sierra"); flags = dp->r_flags; break; case 'J': strcpy(d->gid, "joliet"); flags = dp->flags; break; case '9': strcpy(d->gid, "plan9"); flags = dp->flags; break; } if(flags & 0x02){ d->qid.type |= QTDIR; d->mode |= DMDIR|0111; } strcpy(d->uid, "cdrom"); if(fmt!='9' && !(d->mode&DMDIR)){ /* * ISO 9660 actually requires that you always have a . and a ;, * even if there is no version and no extension. Very few writers * do this. If the version is present, we use it for qid.vers. * If there is no extension but there is a dot, we strip it off. * (VMS heads couldn't comprehend the dot as a file name character * rather than as just a separator between name and extension.) * * We don't do this for directory names because directories are * not allowed to have extensions and versions. */ if((p=strchr(d->name, ';')) != nil){ vers = strtoul(p+1, 0, 0); d->qid.vers = vers; *p = '\0'; } if((p=strchr(d->name, '.')) != nil && *(p+1)=='\0') *p = '\0'; } if(fs->issusp){ nl = 0; s += fs->suspoff; sysl -= fs->suspoff; for(; sysl >= 4 && have != (Hname|Hmode); sysl -= l, s += l){ if(s[0] == 0 && ((uintptr)s & 1)){ /* MacOS pads individual entries, contrary to spec */ s++; sysl--; } l = s[2]; if(s[0] == 'P' && s[1] == 'X' && s[3] == 1){ /* posix file attributes */ mode = l32(s+4); d->mode = mode & 0777; if((mode & 0170000) == 040000){ d->mode |= DMDIR; d->qid.type |= QTDIR; } have |= Hmode; } else if(s[0] == 'N' && s[1] == 'M' && s[3] == 1){ /* alternative name */ if((s[4] & ~1) == 0){ i = nl+l-5; if(i >= Maxname) i = Maxname-1; if((i -= nl) > 0){ memmove(d->name+nl, s+5, i); nl += i; } if(s[4] == 0) have |= Hname; } } else if(s[0] == 'C' && s[1] == 'E' && s[2] >= 28){ sysl = getcontin(fs->d, s, &s); continue; } else if(s[0] == 'S' && s[1] == 'T') break; } } } d->length = 0; if((d->mode & DMDIR) == 0) d->length = fakemax(l32(dp->size)); d->type = 0; d->dev = 0; d->atime = gtime(dp->date); d->mtime = d->atime; return vers; }
static char * time2text( char *ldtimestr, int dateonly ) { int len; struct tm t; char *p, *timestr, zone, *fmterr = dgettext(TEXT_DOMAIN, "badly formatted time"); time_t gmttime; /* CTIME for this platform doesn't use this. */ #if !defined(SUNOS4) && !defined(BSDI) && !defined(LINUX1_2) && \ !defined(SNI) && !defined(_WIN32) && !defined(macintosh) && !defined(LINUX) char buf[26]; #endif memset( (char *)&t, 0, sizeof( struct tm )); if (( len = (int)strlen( ldtimestr )) < 13 ) { return( fmterr ); } if ( len > 15 ) { /* throw away excess from 4-digit year time string */ len = 15; } else if ( len == 14 ) { len = 13; /* assume we have a time w/2-digit year (len=13) */ } for ( p = ldtimestr; p - ldtimestr + 1 < len; ++p ) { if ( !isdigit( *p )) { return( fmterr ); } } p = ldtimestr; t.tm_year = GET2BYTENUM( p ); p += 2; if ( len == 15 ) { t.tm_year = 100 * (t.tm_year - 19); t.tm_year += GET2BYTENUM( p ); p += 2; } else { /* 2 digit years...assumed to be in the range (19)70 through (20)69 ...less than 70 (for now, 38) means 20xx */ if(t.tm_year < 70) { t.tm_year += 100; } } t.tm_mon = GET2BYTENUM( p ) - 1; p += 2; t.tm_mday = GET2BYTENUM( p ); p += 2; t.tm_hour = GET2BYTENUM( p ); p += 2; t.tm_min = GET2BYTENUM( p ); p += 2; t.tm_sec = GET2BYTENUM( p ); p += 2; if (( zone = *p ) == 'Z' ) { /* GMT */ zone = '\0'; /* no need to indicate on screen, so we make it null */ } gmttime = gtime( &t ); timestr = NSLDAPI_CTIME( &gmttime, buf, sizeof(buf) ); timestr[ strlen( timestr ) - 1 ] = zone; /* replace trailing newline */ if ( dateonly ) { strcpy( timestr + 11, timestr + 20 ); } return( timestr ); }
int ds_bind_init (struct connection *cn) { struct ds_bind_arg * arg = &(cn->cn_start.cs_ds.ds_bind_arg); struct ds_bind_arg * result = &(cn->cn_start.cs_res); struct ds_bind_error * error = &(cn->cn_start.cs_err); Attr_Sequence as; Entry entryptr; extern AttributeType at_password; extern AttributeType at_p_password; struct di_block * dsas = NULL_DI_BLOCK; struct di_block * di_tmp; struct oper_act * on; struct ds_compare_arg * cma; struct DSError err; static struct common_args ca_def = default_common_args; int res; int retval; struct protected_password * pp; #ifndef NO_STATS char buff[LINESIZE]; #endif extern struct SecurityServices *dsap_security; DLOG (log_dsap,LLOG_TRACE,("ds_bind_init")); if ( (arg->dba_version != DBA_VERSION_V1988) || quipu_shutdown) { error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SERVICE; error->dbe_value = DSE_SV_UNAVAILABLE; return(DS_ERROR_CONNECT); } /* We don't support any bilaterally-defined authentication procedures. * Hence, if we get EXTERNAL credentials in the bind, reject them. */ if (arg->dba_auth_type == DBA_AUTH_EXTERNAL) { DLOG(log_dsap, LLOG_EXCEPTIONS, ("EXTERNAL found in credentials")); error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SERVICE; error->dbe_value = DSE_SV_UNAVAILABLE; return (DS_ERROR_CONNECT); } /* If password is present, but zero length, treat as though absent */ if ((arg->dba_auth_type == DBA_AUTH_SIMPLE) && (arg->dba_passwd_len == 0)) arg->dba_auth_type = DBA_AUTH_NONE; switch (arg->dba_auth_type) { case DBA_AUTH_NONE: if (((arg->dba_dn == NULLDN) && auth_bind == 1) || (auth_bind > 1)) { out: ; #ifndef NO_STATS if (arg->dba_dn == NULLDN) LLOG(log_stat, LLOG_TRACE, ("Bind (%d) (rejected)", cn->cn_ad)); else { sprintf (buff,"Bind (%d) (rejected)",cn->cn_ad); pslog (log_stat,LLOG_TRACE,buff,(IFP)dn_print, (caddr_t)arg->dba_dn); } #endif error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SECURITY; error->dbe_value = DSE_SC_AUTHENTICATION; return (DS_ERROR_CONNECT); } break; case DBA_AUTH_SIMPLE: if (auth_bind > 2) goto out; break; case DBA_AUTH_PROTECTED: if (auth_bind > 3) goto out; break; case DBA_AUTH_STRONG: break; case DBA_AUTH_EXTERNAL: goto out; } if (arg->dba_dn == NULLDN) { #ifndef NO_STATS LLOG(log_stat, LLOG_NOTICE, ("Bind (%d) (anonymous)", cn->cn_ad)); #endif cn->cn_authen = DBA_AUTH_NONE; make_dsa_bind_arg(result); return(DS_OK); } /* Now we're sure dba_dn contains a valid pointer, can decode it */ if ( ! check_prefix_list (arg->dba_dn)) { #ifndef NO_STATS sprintf (buff,"Bind (%d) (reject - prefix)",cn->cn_ad); pslog (log_stat,LLOG_TRACE,buff,(IFP)dn_print, (caddr_t)arg->dba_dn); #endif error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SECURITY; error->dbe_value = DSE_SC_ACCESSRIGHTS; return (DS_ERROR_CONNECT); } if ((cn->cn_ctx == DS_CTX_X500_DAP) && !(check_dn_length(arg->dba_dn))) { #ifndef NO_STATS sprintf (buff,"Bind (%d) (reject - DAP length)",cn->cn_ad); pslog (log_stat,LLOG_TRACE,buff,(IFP)dn_print, (caddr_t)arg->dba_dn); #endif error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SECURITY; error->dbe_value = DSE_SC_ACCESSRIGHTS; return (DS_ERROR_CONNECT); } switch (arg->dba_auth_type) { case DBA_AUTH_NONE: /* partially check DN - i.e see if we can say if DEFINATELY does */ /* not exist. If it possibly exists - allow bind, checking it */ /* runs the risk of livelock */ switch (res = really_find_entry(arg->dba_dn, TRUE, NULLDNSEQ, FALSE, &(entryptr), &(err), &(dsas))) { case DS_X500_ERROR: if ((err.dse_type == DSE_NAMEERROR) && (err.ERR_NAME.DSE_na_problem == DSE_NA_NOSUCHOBJECT)) { ds_error_free(&(err)); #ifndef NO_STATS sprintf (buff,"Bind (%d) (no auth - rejected)",cn->cn_ad); pslog (log_stat,LLOG_TRACE,buff,(IFP)dn_print,(caddr_t)arg->dba_dn); #endif error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SECURITY; error->dbe_value = DSE_SC_INVALIDCREDENTIALS; return (DS_ERROR_CONNECT); } /* fall */ default: #ifndef NO_STATS sprintf (buff,"Bind (%d) (no auth)",cn->cn_ad); pslog (log_stat,LLOG_NOTICE,buff,(IFP)dn_print,(caddr_t)arg->dba_dn); #endif if (dsas != NULL_DI_BLOCK) di_desist (dsas); cn->cn_authen = DBA_AUTH_NONE; make_dsa_bind_arg(result); return (DS_OK); } case DBA_AUTH_SIMPLE: #ifndef NO_STATS sprintf (buff,"Bind (%d) (simple)",cn->cn_ad); pslog (log_stat,LLOG_NOTICE,buff,(IFP)dn_print,(caddr_t)arg->dba_dn); #endif /* Can't check simple credentials from DSP (livelock risk). * Hence treat DSP accesses as unauthenticated. */ if (cn->cn_ctx != DS_CTX_X500_DAP) { cn->cn_authen = DBA_AUTH_NONE; make_dsa_bind_arg(result); return(DS_OK); } break; case DBA_AUTH_PROTECTED: #ifndef NO_STATS sprintf (buff,"Bind (%d) (protected)",cn->cn_ad); pslog (log_stat,LLOG_NOTICE,buff,(IFP)dn_print,(caddr_t)arg->dba_dn); #endif if (cn->cn_ctx != DS_CTX_X500_DAP) { cn->cn_authen = DBA_AUTH_NONE; make_dsa_bind_arg(result); return(DS_OK); } else { UTC ut; long c_time, s_time, delta; time(&s_time); ut = str2utct(arg->dba_time1, strlen(arg->dba_time1)); if (ut == NULLUTC) c_time = 0L; /* 1970 is a convenient out-of-date timestamp */ else c_time = gtime(ut2tm(ut)); delta = s_time - c_time; if ((delta < 0) || (delta > bind_window)) { DLOG(log_dsap, LLOG_EXCEPTIONS, ("Time = %s, Delay = %D s : Association rejected", arg->dba_time1, delta)); error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SECURITY; error->dbe_value = DSE_SC_INVALIDCREDENTIALS; return (DS_ERROR_CONNECT); } pp = (struct protected_password *) calloc(1, sizeof(*pp)); /* Ought to check for null pointer ... */ pp->passwd = malloc((unsigned)arg->dba_passwd_len); bcopy(arg->dba_passwd, pp->passwd, arg->dba_passwd_len); pp->n_octets = arg->dba_passwd_len; pp->time1 = strdup(arg->dba_time1); pp->is_protected[0] = (char) 1; } break; case DBA_AUTH_STRONG: #ifndef NO_STATS sprintf (buff,"Bind (%d) (strong)",cn->cn_ad); pslog (log_stat,LLOG_NOTICE,buff,(IFP)dn_print,(caddr_t)arg->dba_dn); #endif /* Strong authentication is not yet supported. * It will eventually be possible to check strong credentials over DSP. * For the moment, accept them and treat as NONE over DSP, but reject * over DAP. */ if (dsap_security && dsap_security->serv_ckpath && dsap_security->serv_cknonce) { int rc; DN real_name; struct Nonce nonce; nonce.non_time1 = arg->dba_time1; nonce.non_time2 = arg->dba_time2; nonce.non_r1.n_bits = arg->dba_r1.n_bits; nonce.non_r1.value = arg->dba_r1.value; nonce.non_r2.n_bits = arg->dba_r2.n_bits; nonce.non_r2.value = arg->dba_r2.value; rc = (dsap_security->serv_cknonce)(&nonce); if (rc != OK) { error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SECURITY; error->dbe_value = rc; return (DS_ERROR_CONNECT); } rc = (dsap_security->serv_ckpath)((caddr_t) arg, _ZTokenToSignDAS, &_ZDAS_mod, arg->dba_cpath, arg->dba_sig, &real_name); if (rc != OK) { error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SECURITY; error->dbe_value = rc; return (DS_ERROR_CONNECT); } else { if(dn_cmp(real_name, arg->dba_dn) == OK) { make_dsa_bind_arg(result); return (DS_OK); } else { sprintf (buff,"User != Authenticated User, ie %s != ", dn2str(arg->dba_dn)); pslog (log_dsap,LLOG_NOTICE,buff,(IFP)dn_print,(caddr_t)real_name); error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SECURITY; error->dbe_value = DSE_SC_AUTHENTICATION; return (DS_ERROR_CONNECT); } } } else { if (cn->cn_ctx != DS_CTX_X500_DAP) { cn->cn_authen = DBA_AUTH_NONE; make_dsa_bind_arg(result); return (DS_OK); } else { error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SERVICE; error->dbe_value = DSE_SV_UNAVAILABLE; return (DS_ERROR_CONNECT); } } } /* If we fall through to here, credentials are simple or protected simple */ if ((res = really_find_entry(arg->dba_dn, TRUE, NULLDNSEQ, FALSE, &(entryptr), &(err), &(dsas))) == DS_OK) { /* is it really OK ??? */ if ((entryptr->e_data == E_TYPE_CONSTRUCTOR) || (entryptr->e_data == E_TYPE_CACHE_FROM_MASTER)) { DN dn_found; DLOG(log_dsap, LLOG_TRACE, ("rfe (bind) returned a constructor")); dn_found = get_copy_dn(entryptr); res = constructor_dsa_info(dn_found,NULLDNSEQ,FALSE,entryptr,&err,&dsas); dn_free (dn_found); } } switch(res) { case DS_OK: /* entryptr filled out - break through to deal with it */ break; case DS_CONTINUE: /* * At this point a remote operation is required to compare * the password given with the password of the entry, so * fire up the remote operation and return without completing. * Mark the operation as a BIND_COMPARE_OP and set the connection * which will need to be restarted. * Generate a compare argument. * Chain the compare operation using the di_blocks. */ cn->cn_start.cs_bind_compare = on = oper_alloc();/* cn knows about on */ on->on_type = ON_TYPE_BIND_COMPARE; on->on_bind_compare = cn; /* on knows about cn */ set_my_chain_args(&(on->on_req.dca_charg), arg->dba_dn); on->on_req.dca_dsarg.arg_type = OP_COMPARE; cma = &(on->on_req.dca_dsarg.arg_cm); cma->cma_common = ca_def; /* struct copy */ /* Set originator/requestor */ if (on->on_req.dca_charg.cha_originator) /* set my set_my_chain_arg */ dn_free(on->on_req.dca_charg.cha_originator); on->on_req.dca_charg.cha_originator = dn_cpy(arg->dba_dn); cma->cma_common.ca_requestor = dn_cpy(arg->dba_dn); cma->cma_common.ca_servicecontrol.svc_prio = SVC_PRIO_HIGH; cma->cma_object = dn_cpy(arg->dba_dn); if (arg->dba_auth_type == DBA_AUTH_SIMPLE) { cma->cma_purported.ava_type = AttrT_cpy (at_password); cma->cma_purported.ava_value = str2AttrV (arg->dba_passwd,str2syntax("octetstring")); } else { cma->cma_purported.ava_type = AttrT_cpy (at_p_password); cma->cma_purported.ava_value = (AttributeValue) calloc(1, sizeof(attrVal)); cma->cma_purported.ava_value->av_syntax = str2syntax("protectedPassword"); cma->cma_purported.ava_value->av_struct = (caddr_t) pp; } on->on_dsas = dsas; for(di_tmp=on->on_dsas; di_tmp!=NULL_DI_BLOCK; di_tmp=di_tmp->di_next) { di_tmp->di_type = DI_OPERATION; di_tmp->di_oper = on; } if(oper_chain(on) == OK) return(DS_CONTINUE); oper_extract(on); cn->cn_start.cs_bind_compare = NULLOPER; error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SERVICE; error->dbe_value = DSE_SV_UNAVAILABLE; return(DS_ERROR_CONNECT); case DS_X500_ERROR: /* User's entry doesn't exist, for example */ LLOG(log_dsap, LLOG_TRACE, ("ds_bind - really_find_entry erred:")); log_ds_error(&(err)); ds_error_free(&(err)); error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SECURITY; error->dbe_value = DSE_SC_INVALIDCREDENTIALS; return(DS_ERROR_CONNECT); default: error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SERVICE; error->dbe_value = DSE_SV_DITERROR; return(DS_ERROR_CONNECT); } if ((as = as_find_type (entryptr->e_attributes, (arg->dba_auth_type == DBA_AUTH_SIMPLE) ? at_password : at_p_password)) == NULLATTR) { /* No password in entry. * Simple authentication is not possible for entities without passwords. * Hence, give the `inappropriate authentication' message. */ error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SECURITY; error->dbe_value = DSE_SC_AUTHENTICATION; return (DS_ERROR_CONNECT); } if (arg->dba_auth_type == DBA_AUTH_SIMPLE) { if (strlen ((char *)as->attr_value->avseq_av.av_struct) != arg->dba_passwd_len) retval = -1; else retval = strncmp ((char *)as->attr_value->avseq_av.av_struct, arg->dba_passwd, arg->dba_passwd_len); } else retval = check_guard( ((struct protected_password *) as->attr_value->avseq_av.av_struct)->passwd, ((struct protected_password *) as->attr_value->avseq_av.av_struct)->n_octets, arg->dba_time1, arg->dba_passwd, arg->dba_passwd_len); if (retval == 0) { /* Password OK! */ cn->cn_authen = arg->dba_auth_type; make_dsa_bind_arg(result); return (DS_OK); } else { /* password wrong ! */ error->dbe_version = DBA_VERSION_V1988; error->dbe_type = DBE_TYPE_SECURITY; error->dbe_value = DSE_SC_INVALIDCREDENTIALS; return (DS_ERROR_CONNECT); } }
// print the file on the default printer void ListPrintFile( void ) { register int i, n; int c, nRows, nBytesPrinted, nFH; long lTemp; POPWINDOWPTR wn; TCHAR szBuffer[MAXLISTLINE+1]; int fKBHit; // disable ^C / ^BREAK handling HoldSignals(); wn = wOpen( 2, 1, 4, strlen( LIST_PRINTING ) + 8, nInverse, LIST_PRINT_TITLE, NULL ); wn->nAttrib = nNormal; wClear(); sprintf( szBuffer, LIST_QUERY_PRINT, LIST_PRINT_FILE_CHAR, LIST_PRINT_PAGE_CHAR ); wWriteListStr( 0, 1, wn, szBuffer ); if ((( c = GetKeystroke( EDIT_ECHO | EDIT_UC_SHIFT | EDIT_BIOS_KEY )) == LIST_PRINT_FILE_CHAR ) || ( c == LIST_PRINT_PAGE_CHAR )) { // save start position lTemp = LFile.lViewPtr; // display "Printing ..." wWriteListStr( 0, 1, wn, LIST_PRINTING ); if (( nFH = _sopen((( gpIniptr->Printer != INI_EMPTYSTR ) ? gpIniptr->StrData + gpIniptr->Printer : _TEXT("LPT1") ), (_O_BINARY | _O_WRONLY | _O_CREAT), _SH_DENYNO, _S_IWRITE | _S_IREAD )) >= 0 ) { if ( setjmp( cv.env ) == -1 ) { _close( nFH ); return; } // reset to beginning of file if ( c == LIST_PRINT_FILE_CHAR ) ListSetCurrent( 0L ); else { nRows = GetScrRows(); ListSetCurrent( LFile.lViewPtr ); } // print the header (filename, date & time) qprintf( nFH, _TEXT("%s %s %s\r\n\r\n"), LFile.szName, gdate( 0 ), gtime( gaCountryInfo.fsTimeFmt ) ); do { // abort printing if a key is hit // kbhit() in DOS tries to read from STDIN, which screws // up a LIST /S pipe _asm { mov ah, 1 int 16h mov fKBHit, 1 jnz KBHDone mov fKBHit, 0 KBHDone: } if ( fKBHit && ( GetKeystroke( EDIT_NO_ECHO | EDIT_BIOS_KEY ) == ESC )) break; i = FormatLine( szBuffer, MAXLISTLINE, LFile.lViewPtr, &nBytesPrinted, TRUE ); LFile.lViewPtr += 16; // replace 0-31 with "." if ( lListFlags & LIST_HEX ) { for ( n = 0; ( n < i ); n++ ) { if ( szBuffer[n] < 32 ) szBuffer[n] = _TEXT('.'); } } if (( c == LIST_PRINT_PAGE_CHAR ) && ( nRows-- <= 0 )) break; } while (( nBytesPrinted > 0 ) && ( qprintf( nFH, _TEXT("%.*s\r\n"), i, szBuffer ) > 0 )); // print a formfeed qputc( nFH, _TEXT('\014') ); _close( nFH ); // restore start position LFile.lViewPtr = lTemp; ListSetCurrent( LFile.lViewPtr ); } else honk(); } wRemove( wn ); // enable ^C / ^BREAK handling EnableSignals(); }