Loading...
Searching...
No Matches
XrdSutRndm Class Reference

`#include <XrdSutRndm.hh>`

Collaboration diagram for XrdSutRndm:

## Public Member Functions

| XrdSutRndm ()
virtual | ~XrdSutRndm ()

## Static Public Member Functions

static char * | GetBuffer (int len, int opt=-1)
static int | GetRndmTag (XrdOucString &rtag)
static int | GetString (const char *copt, int len, XrdOucString &s)
static int | GetString (int opt, int len, XrdOucString &s)
static unsigned int | GetUInt ()
static bool | Init (bool force=0)

## Static Public Attributes

static bool | fgInit = 0

## Detailed Description

Definition at line 43 of file XrdSutRndm.hh.

## Constructor & Destructor Documentation

## XrdSutRndm()

XrdSutRndm::XrdSutRndm | ( |  | ) |

inline

Definition at line 48 of file XrdSutRndm.hh.

{ if (!fgInit) fgInit = XrdSutRndm::Init(); }
XrdSutRndm::fgInit
static bool fgInit
Definition XrdSutRndm.hh:46
XrdSutRndm::Init
static bool Init(bool force=0)
Definition XrdSutRndm.cc:62

References fgInit, and Init().

Here is the call graph for this function:

## ~XrdSutRndm()

virtual XrdSutRndm::~XrdSutRndm | ( |  | ) |

inline virtual

Definition at line 49 of file XrdSutRndm.hh.

{ }

## Member Function Documentation

## GetBuffer()

char * XrdSutRndm::GetBuffer | ( | int | len,
|  | int | opt = -1 )

static

Definition at line 179 of file XrdSutRndm.cc.

{
// Static method to fill randomly a buffer.
// Returns the pointer to the buffer if ok, 0 in case of error.
// If opt has one of the following values, the random bytes are
// chosen between the corrsponding subset:
// opt = 0 any printable char
// 1 letters and numbers (upper and lower case)
// 2 hex characters (upper and lower case)
// 3 crypt like [a-zA-Z0-9./]
// The caller is responsible to destroy the buffer
EPNAME("Rndm::GetBuffer");
DEBUG("enter: len: " <<len);
// Init Random machinery ... if needed
if (!fgInit) {
Init();
fgInit = 1;
}
// randomize
char *buf = new char[len];
if (!buf) {
errno = ENOSPC;
return 0;
}
// Filtering ?
bool filter = (opt >= 0 && opt <= 3);
kXR_int32 k = 0;
kXR_int32 i, m, frnd, j = 0, l = 0;
while (k < len) {
frnd = rand();
for (m = 0; m < 32; m += 8) {
i = 0xFF & (frnd >> m);
bool keep = 1;
if (filter) {
j = i / 32;
l = i - j * 32;
keep = (XrdSutCharMsk[opt][j%4] & (1 << l));
}
if (keep) {
buf[k] = i;
k++;
}
if (k == len)
break;
}
}
return buf;
}
kXR_int32
int kXR_int32
Definition XPtypes.hh:89
DEBUG
#define DEBUG(x)
Definition XrdBwmTrace.hh:54
EPNAME
#define EPNAME(x)
Definition XrdBwmTrace.hh:56
XrdSutCharMsk
static kXR_int32 XrdSutCharMsk[4][4]
Definition XrdSutBucket.cc:40

References DEBUG, EPNAME, fgInit, Init(), and XrdSutCharMsk.

Referenced by XrdCryptosslCipher::XrdCryptosslCipher(), and XrdCryptosslFactory::XrdCryptosslFactory().

Here is the call graph for this function:
Here is the caller graph for this function:

## GetRndmTag()

int XrdSutRndm::GetRndmTag | ( | XrdOucString & | rtag | ) |

static

Definition at line 235 of file XrdSutRndm.cc.

{
// Static method generating a 64 bit random tag (8 chars in [a-zA-Z0-9./])
// saved in rtag.
// Return 0 in case of success; in case of error, -1 is returned
// and errno set accordingly (see XrdSutRndm::GetString)
return XrdSutRndm::GetString(3,8,rtag);
}
XrdSutRndm::GetString
static int GetString(int opt, int len, XrdOucString &s)
Definition XrdSutRndm.cc:120

References GetString().

Here is the call graph for this function:

## GetString() [1/2]

int XrdSutRndm::GetString | ( | const char * | copt,
|  | int | len,
|  | XrdOucString & | s )

static

Definition at line 97 of file XrdSutRndm.cc.

{
// Static method to fill string str with len random characters.
// Returns 0 if ok, -1 in case of error.
// copt = "Any" any printable char
// "LetNum" letters and numbers (upper and lower case)
// "Hex" hex characters (upper and lower case)
// "Crypt" crypt like [a-zA-Z0-9./]
//
// (opt is not case sensitive)
int opt = 0;
if (!strncasecmp(copt,"LetNum",6))
opt = 1;
else if (!strncasecmp(copt,"Hex",3))
opt = 2;
else if (!strncasecmp(copt,"Crypt",5))
opt = 3;
return XrdSutRndm::GetString(opt,len,str);
}

References GetString().

Here is the call graph for this function:

## GetString() [2/2]

int XrdSutRndm::GetString | ( | int | opt,
|  | int | len,
|  | XrdOucString & | s )

static

Definition at line 120 of file XrdSutRndm.cc.

{
// Static method to fill string str with len random characters.
// Returns 0 if ok, -1 in case of error.
// opt = 0 any printable char
// 1 letters and numbers (upper and lower case)
// 2 hex characters (upper and lower case)
// 3 crypt like [a-zA-Z0-9./]
EPNAME("Rndm::GetString");
const char *cOpt[4] = { "Any", "LetNum", "Hex", "Crypt" };
// Default option 0
if (opt < 0 || opt > 3) {
opt = 0;
DEBUG("unknown option: " <<opt <<": assume 0");
}
DEBUG("enter: len: " <<len <<" (type: " <<cOpt[opt] <<")");
// Init Random machinery ... if needed
if (!XrdSutRndm::fgInit)
XrdSutRndm::fgInit = XrdSutRndm::Init();
// randomize
char *buf = new char[len+1];
if (!buf) {
errno = ENOSPC;
return -1;
}
kXR_int32 k = 0;
kXR_int32 i, j, l, m, frnd;
while (k < len) {
frnd = rand();
for (m = 7; m < 32; m += 7) {
i = 0x7F & (frnd >> m);
j = i / 32;
l = i - j * 32;
if ((XrdSutCharMsk[opt][j] & (1 << l))) {
buf[k] = i;
k++;
}
if (k == len)
break;
}
}
// null terminated
buf[len] = 0;
DEBUG("got: " <<buf);
// Fill output
str = buf;
delete[] buf;
return 0;
}

References DEBUG, EPNAME, fgInit, Init(), and XrdSutCharMsk.

Referenced by AddPassword(), GetRndmTag(), GetString(), main(), ParseArguments(), and XrdSutResolve().

Here is the call graph for this function:
Here is the caller graph for this function:

## GetUInt()

unsigned int XrdSutRndm::GetUInt | ( |  | ) |

static

Definition at line 247 of file XrdSutRndm.cc.

{
// Static method to return an unsigned int.
// Init Random machinery ... if needed
if (!fgInit) {
Init();
fgInit = 1;
}
// As simple as this
return rand();
}

References fgInit, and Init().

Here is the call graph for this function:

## Init()

bool XrdSutRndm::Init | ( | bool | force = 0 | ) |

static

Definition at line 62 of file XrdSutRndm.cc.

{
// Initialize the random machinery; try using /dev/urandom to avoid
// hanging.
// The bool 'force' can be used to force re-initialization.
EPNAME("Rndm::Init");
const char *randdev = "/dev/urandom";
bool rc = 0;
// We do not do it twice
if (fgInit && !force)
return 1;
int fd;
unsigned int seed = 0;
if ((fd = open(randdev, O_RDONLY)) != -1) {
DEBUG("taking seed from " <<randdev);
if (read(fd, &seed, sizeof(seed)) == sizeof(seed)) rc = 1;
close(fd);
}
if (rc == 0) {
DEBUG(randdev <<" not available: using time()");
seed = time(0); //better use times() + win32 equivalent
rc = 1;
}
srand(seed);
// Flag as initialized
fgInit = 1;
return rc;
}
close
#define close(a)
Definition XrdPosix.hh:48
open
#define open
Definition XrdPosix.hh:76
read
#define read(a, b, c)
Definition XrdPosix.hh:82

References close, DEBUG, EPNAME, fgInit, open, and read.

Referenced by XrdSutRndm(), GetBuffer(), GetString(), GetUInt(), main(), and ParseArguments().

Here is the caller graph for this function:

## Member Data Documentation

## fgInit

bool XrdSutRndm::fgInit = 0

static

Definition at line 46 of file XrdSutRndm.hh.

Referenced by XrdSutRndm(), GetBuffer(), GetString(), GetUInt(), and Init().

The documentation for this class was generated from the following files:

- XrdSutRndm.hh
- XrdSutRndm.cc