MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
auth.h File Reference
#include <unistd.h>
#include <string.h>
Include dependency graph for auth.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  AuthMethod
 
class  NoAuth
 

Functions

AuthMethodReadAuthMethod (const DataManager *pDM, MBDynParser &HP)
 

Function Documentation

AuthMethod* ReadAuthMethod ( const DataManager pDM,
MBDynParser HP 
)

Definition at line 451 of file auth.cc.

References IncludeParser::GetLineData(), HighParser::GetStringWithDelims(), HighParser::GetWord(), HighParser::IsKeyWord(), LASTKEYWORD, MBDYN_EXCEPT_ARGS, SAFENEW, SAFENEWWITHCONSTRUCTOR, and SAFESTRDUP.

452 {
453  AuthMethod* pAuth = NULL;
454 
455  const char* sKeyWords[] = {
456  "noauth",
457  "password",
458  "pwdb",
459  "pam",
460  "sasl",
461  NULL
462  };
463 
464  enum KeyWords {
465  UNKNOWN = -1,
466 
467  NOAUTH = 0,
468  PASSWORD,
469  PWDB,
470  PAM,
471  SASL,
472 
474  };
475 
476  /* tabella delle parole chiave */
477  KeyTable K(HP, sKeyWords);
478 
479  /* lettura del tipo di drive */
480  KeyWords CurrKeyWord = KeyWords(HP.GetWord());
481 
482  switch (CurrKeyWord) {
483  /* auth is always successful */
484  case NOAUTH:
485  SAFENEW(pAuth, NoAuth);
486  break;
487 
488  /* auth is based on user id and password */
489  case PASSWORD: {
490 #ifdef HAVE_CRYPT
491  if (!HP.IsKeyWord("user")) {
492  silent_cerr("ReadAuthMethod: user expected at line "
493  << HP.GetLineData() << std::endl);
495  }
496 
497  const char* tmp = HP.GetStringWithDelims();
498  if (strlen(tmp) == 0) {
499  silent_cerr("ReadAuthMethod: Need a legal user id at line "
500  << HP.GetLineData() << std::endl);
502  }
503 
504  std::string user(tmp);
505 
506  if (!HP.IsKeyWord("credentials")) {
507  silent_cerr("ReadAuthMethod: credentials expected at line "
508  << HP.GetLineData() << std::endl);
510  }
511 
512  if (HP.IsKeyWord("prompt")) {
513  tmp = getpass("password: ");
514  } else {
515  tmp = HP.GetStringWithDelims();
516  }
517 
518  if (tmp[0] == '\0') {
519  silent_cout("ReadAuthMethod: null credentials at line "
520  << HP.GetLineData() << std::endl);
521  }
522 
523  std::string cred(tmp);
524  memset((char *)tmp, '\0', strlen(tmp));
525 
526  std::string salt_format;
527  if (HP.IsKeyWord("salt" "format")) {
528  tmp = HP.GetStringWithDelims();
529  salt_format = tmp;
530  }
531 
533  PasswordAuth,
534  PasswordAuth(user.c_str(), cred.c_str(), salt_format.c_str()));
535  memset(cred.c_str(), '\0', cred.size());
536 
537  break;
538 #else /* !HAVE_CRYPT */
539  silent_cerr("ReadAuthMethod: line " << HP.GetLineData()
540  << ": no working crypt(3)" << std::endl);
542 #endif /* !HAVE_CRYPT */
543  }
544 
545  case PAM: {
546 #ifdef USE_PAM
547  char* user = NULL;
548  if (HP.IsKeyWord("user")) {
549  const char *tmp = HP.GetStringWithDelims();
550  if (strlen(tmp) == 0) {
551  silent_cerr("ReadAuthMethod: Need a legal user id at line "
552  << HP.GetLineData() << std::endl);
554  }
555 
556  SAFESTRDUP(user, tmp);
557  }
558 
559  SAFENEWWITHCONSTRUCTOR(pAuth, PAM_Auth, PAM_Auth(user));
560  break;
561 #else /* !USE_PAM */
562  silent_cerr("ReadAuthMethod: line " << HP.GetLineData()
563  << ": no PAM support" << std::endl);
565 #endif /* !USE_PAM */
566  }
567 
568  case SASL: {
569 #ifdef HAVE_SASL2
570  mbdyn_sasl_t mbdyn_sasl = MBDYN_SASL_INIT;
571  mbdyn_sasl.use_sasl = MBDYN_SASL_SERVER;
572 
573  if (HP.IsKeyWord("mechanism") || HP.IsKeyWord("mech")) {
574  const char *s = HP.GetStringWithDelims();
575  if (s != NULL) {
576  SAFESTRDUP(mbdyn_sasl.sasl_mech, s);
577  } else {
578  silent_cerr("ReadAuthMethod: unable to get SASL mech at line "
579  << HP.GetLineData() << std::endl);
580  }
581  }
582 
583  SAFENEWWITHCONSTRUCTOR(pAuth, SASL2_Auth, SASL2_Auth(&mbdyn_sasl));
584  break;
585 #else /* !HAVE_SASL2 */
586  silent_cerr("ReadAuthMethod: line " << HP.GetLineData()
587  << ": no SASL2 support" << std::endl);
589 #endif /* !HAVE_SASL2 */
590  }
591 
592  case PWDB:
593  silent_cerr("ReadAuthMethod: PWDB not implemented yet" << std::endl);
594 
595  default:
597  }
598 
599  return pAuth;
600 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
Definition: auth.h:58
#define SAFENEW(pnt, item)
Definition: mynewmem.h:695
virtual bool IsKeyWord(const char *sKeyWord)
Definition: parser.cc:910
virtual const char * GetStringWithDelims(enum Delims Del=DEFAULTDELIM, bool escape=true)
Definition: parser.cc:1228
KeyWords
Definition: dataman4.cc:94
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
virtual int GetWord(void)
Definition: parser.cc:1083
#define SAFESTRDUP(pnt, src)
Definition: mynewmem.h:707
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697

Here is the call graph for this function: