Print this page
9856 pkcs11_tpm.so.1 changes syslog facility


 272  *              licenses to the intellectual property of any Contributor
 273  *              under this Agreement, whether expressly, by implication,
 274  *              estoppel or otherwise. All rights in the Program not
 275  *              expressly granted under this Agreement are reserved.
 276  *
 277  *
 278  *              This Agreement is governed by the laws of the State of New
 279  *              York and the intellectual property laws of the United
 280  *              States of America. No party to this Agreement will bring a
 281  *              legal action under this Agreement more than one year after
 282  *              the cause of action arose. Each party waives its rights to
 283  *              a jury trial in any resulting litigation.
 284  *
 285  *
 286  *
 287  * (C) COPYRIGHT International Business Machines Corp. 2001, 2002
 288  */
 289 /*
 290  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 291  * Use is subject to license terms.


 292  */
 293 
 294 #include <alloca.h>
 295 #include <libgen.h>
 296 #include <sys/varargs.h>
 297 
 298 #include "tpmtok_int.h"
 299 
 300 extern  API_Proc_Struct_t  *Anchor;
 301 extern int logging;
 302 
 303 void logit(int, char *, ...);

 304 static int enabled = 0;

 305 
 306 void
 307 loginit() {


 308         if (!enabled) {
 309                 enabled = 1;
 310                 openlog("tpmtoken", LOG_PID | LOG_NDELAY, LOG_DAEMON);
 311                 (void) setlogmask(LOG_UPTO(LOG_DEBUG));
 312                 logit(LOG_DEBUG, "Logging enabled %d enabled", enabled);
 313         }

 314 }
 315 
 316 void
 317 logterm()
 318 {

 319         closelog();
 320         enabled = 0;

 321 }
 322 
 323 /*ARGSUSED*/
 324 void
 325 logit(int type, char *fmt, ...)
 326 {
 327 #ifdef DEBUG
 328         va_list pvar;
 329         char buffer[BUFSIZ];
 330 
 331         if (enabled) {
 332                 if (type <= logging) {
 333                         va_start(pvar, fmt);
 334                         (void) vsnprintf(buffer, sizeof (buffer), fmt, pvar);
 335                         va_end(pvar);
 336                         syslog(type, buffer);
 337                 }
 338         }
 339 #else
 340         return;
 341 #endif /* DEBUG */
 342 
 343 }
 344 
 345 void
 346 AddToSessionList(pSess)
 347         Session_Struct_t *pSess;
 348 {
 349         Session_Struct_t *pCur;
 350 
 351         (void) pthread_mutex_lock(&(Anchor->SessListMutex));
 352 
 353         pCur = Anchor->SessListBeg;
 354 
 355         if (! pCur) {
 356                 (void) pthread_mutex_lock(&(Anchor->ProcMutex));
 357                 Anchor->SessListBeg = pSess;
 358                 (void) pthread_mutex_unlock(&(Anchor->ProcMutex));
 359                 pSess->Previous = pSess->Next = NULL;
 360         } else {
 361                 while (pCur->Next != NULL) {
 362                         pCur = pCur->Next;
 363                 }
 364                 pCur->Next = pSess;
 365                 pSess->Previous = pCur;
 366                 pSess->Next = NULL;
 367         }
 368 
 369         (void) pthread_mutex_unlock(&(Anchor->SessListMutex));
 370 }
 371 
 372 void
 373 RemoveFromSessionList(pSess)
 374         Session_Struct_t *pSess;
 375 {
 376         Session_Struct_t *pCur, *pTmp;
 377 
 378         (void) pthread_mutex_lock(&(Anchor->SessListMutex));
 379 
 380         pCur = Anchor->SessListBeg;
 381         /*
 382          * Just in case check that there really is a list although
 383          * the call to ValidSession should have caught this already.
 384          * But someone may have removed the session already
 385          * while we were validating the call.
 386          */
 387         if (pCur) {
 388                 if (pCur == pSess) {
 389                         (void) pthread_mutex_lock(&(Anchor->ProcMutex));
 390                         pTmp = pSess->Next;
 391                         Anchor->SessListBeg = pSess->Next;
 392                         if (pTmp) {
 393                                 pTmp->Previous = NULL;
 394                         }




 272  *              licenses to the intellectual property of any Contributor
 273  *              under this Agreement, whether expressly, by implication,
 274  *              estoppel or otherwise. All rights in the Program not
 275  *              expressly granted under this Agreement are reserved.
 276  *
 277  *
 278  *              This Agreement is governed by the laws of the State of New
 279  *              York and the intellectual property laws of the United
 280  *              States of America. No party to this Agreement will bring a
 281  *              legal action under this Agreement more than one year after
 282  *              the cause of action arose. Each party waives its rights to
 283  *              a jury trial in any resulting litigation.
 284  *
 285  *
 286  *
 287  * (C) COPYRIGHT International Business Machines Corp. 2001, 2002
 288  */
 289 /*
 290  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 291  * Use is subject to license terms.
 292  *
 293  * Copyright 2018 Gary Mills
 294  */
 295 
 296 #include <alloca.h>
 297 #include <libgen.h>
 298 #include <sys/varargs.h>
 299 
 300 #include "tpmtok_int.h"
 301 
 302 extern  API_Proc_Struct_t  *Anchor;
 303 extern int logging;
 304 
 305 void logit(int, char *, ...);
 306 #ifdef DEBUG
 307 static int enabled = 0;
 308 #endif /* DEBUG */
 309 
 310 void
 311 loginit()
 312 {
 313 #ifdef DEBUG
 314         if (!enabled) {
 315                 enabled = 1;
 316                 openlog("tpmtoken", LOG_PID | LOG_NDELAY, LOG_DAEMON);
 317                 (void) setlogmask(LOG_UPTO(LOG_DEBUG));
 318                 logit(LOG_DEBUG, "Logging enabled %d enabled", enabled);
 319         }
 320 #endif /* DEBUG */
 321 }
 322 
 323 void
 324 logterm()
 325 {
 326 #ifdef DEBUG
 327         closelog();
 328         enabled = 0;
 329 #endif /* DEBUG */
 330 }
 331 
 332 /*ARGSUSED*/
 333 void
 334 logit(int type, char *fmt, ...)
 335 {
 336 #ifdef DEBUG
 337         va_list pvar;
 338         char buffer[BUFSIZ];
 339 
 340         if (enabled) {
 341                 if (type <= logging) {
 342                         va_start(pvar, fmt);
 343                         (void) vsnprintf(buffer, sizeof (buffer), fmt, pvar);
 344                         va_end(pvar);
 345                         syslog(type, buffer);
 346                 }
 347         }
 348 #else
 349         return;
 350 #endif /* DEBUG */
 351 
 352 }
 353 
 354 void
 355 AddToSessionList(Session_Struct_t *pSess)

 356 {
 357         Session_Struct_t *pCur;
 358 
 359         (void) pthread_mutex_lock(&(Anchor->SessListMutex));
 360 
 361         pCur = Anchor->SessListBeg;
 362 
 363         if (! pCur) {
 364                 (void) pthread_mutex_lock(&(Anchor->ProcMutex));
 365                 Anchor->SessListBeg = pSess;
 366                 (void) pthread_mutex_unlock(&(Anchor->ProcMutex));
 367                 pSess->Previous = pSess->Next = NULL;
 368         } else {
 369                 while (pCur->Next != NULL) {
 370                         pCur = pCur->Next;
 371                 }
 372                 pCur->Next = pSess;
 373                 pSess->Previous = pCur;
 374                 pSess->Next = NULL;
 375         }
 376 
 377         (void) pthread_mutex_unlock(&(Anchor->SessListMutex));
 378 }
 379 
 380 void
 381 RemoveFromSessionList(Session_Struct_t *pSess)

 382 {
 383         Session_Struct_t *pCur, *pTmp;
 384 
 385         (void) pthread_mutex_lock(&(Anchor->SessListMutex));
 386 
 387         pCur = Anchor->SessListBeg;
 388         /*
 389          * Just in case check that there really is a list although
 390          * the call to ValidSession should have caught this already.
 391          * But someone may have removed the session already
 392          * while we were validating the call.
 393          */
 394         if (pCur) {
 395                 if (pCur == pSess) {
 396                         (void) pthread_mutex_lock(&(Anchor->ProcMutex));
 397                         pTmp = pSess->Next;
 398                         Anchor->SessListBeg = pSess->Next;
 399                         if (pTmp) {
 400                                 pTmp->Previous = NULL;
 401                         }