/*
* The Etc module provides access to information typically stored in
* files in the /etc directory on Unix systems.
*
* The information accessible consists of the information found in the
* /etc/passwd and /etc/group files, plus information about the system's
* temporary directory (/tmp) and configuration directory (/etc).
*
* The Etc module provides a more reliable way to access information about
* the logged in user than environment variables such as +$USER+.
*
* == Example:
*
* require 'etc'
*
* login = Etc.getlogin
* info = Etc.getpwnam(login)
* username = info.gecos.split(/,/).first
* puts "Hello #{username}, I see your login name is #{login}"
*
* Note that the methods provided by this module are not always secure.
* It should be used for informational purposes, and not for security.
*
* All operations defined in this module are class methods, so that you can
* include the Etc module into your class.
*/
void
Init_etc(void)
{
VALUE mEtc;
mEtc = rb_define_module("Etc");
rb_define_module_function(mEtc, "getlogin", etc_getlogin, 0);
rb_define_module_function(mEtc, "getpwuid", etc_getpwuid, -1);
rb_define_module_function(mEtc, "getpwnam", etc_getpwnam, 1);
rb_define_module_function(mEtc, "setpwent", etc_setpwent, 0);
rb_define_module_function(mEtc, "endpwent", etc_endpwent, 0);
rb_define_module_function(mEtc, "getpwent", etc_getpwent, 0);
rb_define_module_function(mEtc, "passwd", etc_passwd, 0);
rb_define_module_function(mEtc, "getgrgid", etc_getgrgid, -1);
rb_define_module_function(mEtc, "getgrnam", etc_getgrnam, 1);
rb_define_module_function(mEtc, "group", etc_group, 0);
rb_define_module_function(mEtc, "setgrent", etc_setgrent, 0);
rb_define_module_function(mEtc, "endgrent", etc_endgrent, 0);
rb_define_module_function(mEtc, "getgrent", etc_getgrent, 0);
rb_define_module_function(mEtc, "sysconfdir", etc_sysconfdir, 0);
rb_define_module_function(mEtc, "systmpdir", etc_systmpdir, 0);
sPasswd = rb_struct_define_under(mEtc, "Passwd",
"name",
#ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
"passwd",
#endif
"uid",
"gid",
#ifdef HAVE_STRUCT_PASSWD_PW_GECOS
"gecos",
#endif
"dir",
"shell",
#ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
"change",
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_QUOTA
"quota",
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_AGE
"age",
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_CLASS
"uclass",
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
"comment",
#endif
#ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
"expire",
#endif
NULL);
#if 0
/* Define-const: Passwd
*
* Passwd is a Struct that contains the following members:
*
* name::
* contains the short login name of the user as a String.
* passwd::
* contains the encrypted password of the user as a String.
* an 'x' is returned if shadow passwords are in use. An '*' is returned
* if the user cannot log in using a password.
* uid::
* contains the integer user ID (uid) of the user.
* gid::
* contains the integer group ID (gid) of the user's primary group.
* dir::
* contains the path to the home directory of the user as a String.
* shell::
* contains the path to the login shell of the user as a String.
//.........这里部分代码省略.........
/**
* Load a Ruby file then run the function corresponding to the service by
* passing the conf, inputs and outputs parameters by refernce as Ruby Hash.
*
* @param main_conf the conf maps containing the main.cfg settings
* @param request the map containing the HTTP request
* @param s the service structure
* @param real_inputs the maps containing the inputs
* @param real_outputs the maps containing the outputs
* @return SERVICE_SUCCEEDED or SERVICE_FAILED if the service run, -1
* if the service failed to load or throw error at runtime.
*/
int zoo_ruby_support(maps** main_conf,map* request,service* s,maps **real_inputs,maps **real_outputs){
#if RUBY_API_VERSION_MAJOR >= 2 || RUBY_API_VERSION_MINOR == 9
ruby_sysinit(&argc,&argv);
RUBY_INIT_STACK;
#endif
ruby_init();
maps* m=*main_conf;
maps* inputs=*real_inputs;
maps* outputs=*real_outputs;
map* tmp0=getMapFromMaps(*main_conf,"lenv","cwd");
char *ntmp=tmp0->value;
map* tmp=NULL;
ruby_init_loadpath();
ruby_script("ZOO_EMBEDDED_ENV");
VALUE klass=rb_define_module("Zoo");
rb_define_const(klass,"SERVICE_SUCCEEDED",INT2FIX(3));
rb_define_const(klass,"SERVICE_FAILED",INT2FIX(4));
typedef VALUE (*HOOK)(...);
rb_define_module_function(klass,"Translate",reinterpret_cast<HOOK>(RubyTranslate),-1);
rb_define_module_function(klass,"UpdateStatus",reinterpret_cast<HOOK>(RubyUpdateStatus),-1);
int error = 0;
ID rFunc=Qnil;
tmp=getMap(s->content,"serviceProvider");
if(tmp!=NULL){
#if RUBY_VERSION_MINOR == 8
const char* script = ruby_sourcefile = rb_source_filename(tmp->value);
rb_protect(LoadWrap, reinterpret_cast<VALUE>(script), &error);
#else
rb_load_protect(rb_str_new2(tmp->value), 0, &error);
#endif
if(error) {
ruby_trace_error(m);
return -1;
}
#if RUBY_VERSION_MINOR == 8
ruby_exec();
#else
ruby_exec_node(NULL);
#endif
}
else{
map* err=createMap("text","Unable to parse serviceProvider please check your zcfg file.");
addToMap(err,"code","NoApplicableCode");
printExceptionReportResponse(m,err);
return -1;
}
int res=SERVICE_FAILED;
rFunc=rb_intern(s->name);
if(rFunc!=Qnil){
VALUE arg1=RubyHash_FromMaps(m);
VALUE arg2=RubyHash_FromMaps(inputs);
VALUE arg3=RubyHash_FromMaps(outputs);
VALUE rArgs[3]={arg1,arg2,arg3};
if (!rArgs)
return -1;
struct my_callback data;
data.obj=Qnil;
data.method_id=rFunc;
data.nargs=3;
data.args[0]=rArgs[0];
data.args[1]=rArgs[1];
data.args[2]=rArgs[2];
typedef VALUE (*HOOK)(VALUE);
VALUE tres=rb_protect(reinterpret_cast<HOOK>(FunCallWrap),(VALUE)(&data),&error);
if (TYPE(tres) == T_FIXNUM) {
res=FIX2INT(tres);
freeMaps(real_outputs);
free(*real_outputs);
freeMaps(main_conf);
free(*main_conf);
*main_conf=mapsFromRubyHash(arg1);
*real_outputs=mapsFromRubyHash(arg3);
#ifdef DEBUG
dumpMaps(*main_conf);
dumpMaps(*real_outputs);
#endif
}else{
ruby_trace_error(m);
res=-1;
}
}
else{
char tmpS[1024];
sprintf(tmpS, "Cannot find the %s function in the %s file.\n", s->name, tmp->value);
map* tmps=createMap("text",tmpS);
//.........这里部分代码省略.........
/*
* INIT
*/
void
Init_ossl_cipher(void)
{
#if 0
mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL */
#endif
/* Document-class: OpenSSL::Cipher
*
* Provides symmetric algorithms for encryption and decryption. The
* algorithms that are available depend on the particular version
* of OpenSSL that is installed.
*
* === Listing all supported algorithms
*
* A list of supported algorithms can be obtained by
*
* puts OpenSSL::Cipher.ciphers
*
* === Instantiating a Cipher
*
* There are several ways to create a Cipher instance. Generally, a
* Cipher algorithm is categorized by its name, the key length in bits
* and the cipher mode to be used. The most generic way to create a
* Cipher is the following
*
* cipher = OpenSSL::Cipher.new('<name>-<key length>-<mode>')
*
* That is, a string consisting of the hyphenated concatenation of the
* individual components name, key length and mode. Either all uppercase
* or all lowercase strings may be used, for example:
*
* cipher = OpenSSL::Cipher.new('AES-128-CBC')
*
* For each algorithm supported, there is a class defined under the
* Cipher class that goes by the name of the cipher, e.g. to obtain an
* instance of AES, you could also use
*
* # these are equivalent
* cipher = OpenSSL::Cipher::AES.new(128, :CBC)
* cipher = OpenSSL::Cipher::AES.new(128, 'CBC')
* cipher = OpenSSL::Cipher::AES.new('128-CBC')
*
* Finally, due to its wide-spread use, there are also extra classes
* defined for the different key sizes of AES
*
* cipher = OpenSSL::Cipher::AES128.new(:CBC)
* cipher = OpenSSL::Cipher::AES192.new(:CBC)
* cipher = OpenSSL::Cipher::AES256.new(:CBC)
*
* === Choosing either encryption or decryption mode
*
* Encryption and decryption are often very similar operations for
* symmetric algorithms, this is reflected by not having to choose
* different classes for either operation, both can be done using the
* same class. Still, after obtaining a Cipher instance, we need to
* tell the instance what it is that we intend to do with it, so we
* need to call either
*
* cipher.encrypt
*
* or
*
* cipher.decrypt
*
* on the Cipher instance. This should be the first call after creating
* the instance, otherwise configuration that has already been set could
* get lost in the process.
*
* === Choosing a key
*
* Symmetric encryption requires a key that is the same for the encrypting
* and for the decrypting party and after initial key establishment should
* be kept as private information. There are a lot of ways to create
* insecure keys, the most notable is to simply take a password as the key
* without processing the password further. A simple and secure way to
* create a key for a particular Cipher is
*
* cipher = OpenSSL::AES256.new(:CFB)
* cipher.encrypt
* key = cipher.random_key # also sets the generated key on the Cipher
*
* If you absolutely need to use passwords as encryption keys, you
* should use Password-Based Key Derivation Function 2 (PBKDF2) by
* generating the key with the help of the functionality provided by
* OpenSSL::PKCS5.pbkdf2_hmac_sha1 or OpenSSL::PKCS5.pbkdf2_hmac.
*
* Although there is Cipher#pkcs5_keyivgen, its use is deprecated and
* it should only be used in legacy applications because it does not use
* the newer PKCS#5 v2 algorithms.
*
* === Choosing an IV
*
* The cipher modes CBC, CFB, OFB and CTR all need an "initialization
* vector", or short, IV. ECB mode is the only mode that does not require
* an IV, but there is almost no legitimate use case for this mode
* because of the fact that it does not sufficiently hide plaintext
//.........这里部分代码省略.........
开发者ID:sho-h,项目名称:ruby,代码行数:101,代码来源:ossl_cipher.c
示例13: rb_define_module
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "rbzoom.h"
#ifdef MAKING_RDOC_HAPPY
mZoom = rb_define_module("ZOOM");
#endif
/* Document-class: ZOOM::Connection
* The Connection object is a session with a target.
*/
static VALUE cZoomConnection;
static VALUE
rbz_connection_make (ZOOM_connection connection)
{
return connection != NULL
? Data_Wrap_Struct (cZoomConnection,
NULL,
请发表评论