示例#1
0
int wb_dbms_env::open(const char *v_host, const char *v_user, const char *v_passwd,
                      const char *v_dbName, unsigned int v_port, const char *v_socket)
{

    host(v_host);
    user(v_user);
    passwd(v_passwd);
    dbName(v_dbName);
    port(v_port);
    socket(v_socket);

    m_con = mysql_init(NULL);

    MYSQL *con = mysql_real_connect(m_con, host(), user(), passwd(), dbName(), port(), socket(), 0);
    if (con == 0) {
        printf("Failed to connect to database: Error: %s\n", mysql_error(m_con));
        return 1;
    }

    char sql[255];

    sprintf(sql, "use %s", dbName());
    int rc = mysql_query(m_con, sql);
    if (rc) {
        printf("%s\n", mysql_error(m_con));
        printf("%s\n", sql);
        return rc;
    } else {
        printf("database open %s\n", sql);
    }

    return 0;
}
示例#2
0
文件: mysql.cpp 项目: sequoiar/SilkJS
JSVAL connect(JSARGS args) {
	HandleScope scope;
    String::AsciiValue host(args[0]->ToString());
    String::AsciiValue user(args[1]->ToString());
    String::AsciiValue passwd(args[2]->ToString());
    String::AsciiValue db(args[3]->ToString());
    int port = 3306;
    if (args.Length() > 4) {
        port = args[4]->IntegerValue();
    }
	if (!handle) {
		handle = mysql_init(NULL);
		
//		handle = mysql_real_connect(handle, "localhost", "mschwartz", "", "sim", 3306, NULL, 0);
		handle = mysql_real_connect(handle, *host, *user, *passwd, *db, port, NULL, 0);
		if (!handle) {
			printf("MYSQL ERROR '%d'\n", mysql_errno(handle));
			return False();
		}
	    currentDb = strdup(*db);
		my_bool reconnect = 1;
		mysql_options(handle, MYSQL_OPT_RECONNECT, &reconnect);
	}
	else if (strcmp(*db, currentDb)) {
	    if (mysql_select_db(handle, *db)) {
    		return ThrowException(Exception::Error(String::New(mysql_error(handle))));
	    }
	    delete [] currentDb;
	    currentDb = strdup(*db);
	}
	mysql_ping(handle);
	return Undefined();
}	
示例#3
0
MYSQL *wb_dbms_env::createDb(void)
{
    m_con = mysql_init(NULL);

    MYSQL *con = mysql_real_connect(m_con, host(), user(), passwd(), 0, port(), socket(), 0);
    // printf("Tried to connect to database, con %x: Status: %s\n", (int)con, mysql_error(m_con));
    if (con == 0) {
        printf("Failed to connect to database: Error: %s\n", mysql_error(m_con));
        return 0;
    }

    char sql[255];

    sprintf(sql, "create database %s", dbName());
    int rc = mysql_query(m_con, sql);
    if (rc) {
        printf("%s\n", mysql_error(m_con));
        printf("%s\n", sql);
        return 0;
    }

    sprintf(sql, "use %s", dbName());
    rc = mysql_query(m_con, sql);
    if (rc) {
        printf("%s\n", mysql_error(m_con));
        printf("%s\n", sql);
        return 0;
    }

    return con;
}
示例#4
0
文件: passwd.c 项目: jsravn/darkpawns
int main(int argc, char *argv[])
{
  if (argc != 4)
    printf("Usage: %s playerfile-name player-name new-password\n", argv[0]);
  else
    passwd(argv[1], argv[2], argv[3]);

  return (0);
}
示例#5
0
void PasswdManager::create_default_file()
{
    std::wofstream passwd(wstring_to_string(this->passwd_file_path));
    passwd.imbue(utf8_locale);
    if (!std::experimental::filesystem::exists(this->passwd_file_path)) {
        throw std::runtime_error("Невозможно создать passwd");
    }
    passwd << "ADMIN:1:0:1:1:" << std::endl;
    passwd.close();
}
示例#6
0
KURL NetworkAccount::getUrl() const
{
    KURL url;
    url.setProtocol(protocol());
    url.setUser(login());
    url.setPass(passwd());
    url.setHost(host());
    url.setPort(port());
    return url;
}
示例#7
0
int wb_dbms_env::create()
{
    struct stat sb;
    char name[512];

    cdh_ToLower(m_fileName, m_fileName);

    printf("wb_dbms_env::create: %s\n", m_fileName);
    /* Create the directory, read/write/access owner and group. */
    if (stat(m_fileName, &sb) != 0) {
        if (mkdir(m_fileName, S_IRWXU | S_IRWXG) != 0) {
            fprintf(stderr, "wb_dbms_env::create: mkdir: %s, %s\n", m_fileName, strerror(errno));
            return errno;
        }
    }

    sprintf(name, "%s/%s", m_fileName, "connection.dmsql");

    if (stat(name, &sb) != 0) {
        FILE *fp;

        fp = fopen(name, "w+b");
        if (fp == NULL) {
            printf("** Cannot open file: %s, %s\n", name, strerror(errno));
            return errno;
        }

        fprintf(fp, "HOST...: %s\n", m_host);
        fprintf(fp, "USER...: %s\n", user());
        if ( !passwd() || strcmp( passwd(), "") == 0)
            fprintf(fp, "PASSWD.: (null)\n");
        else
            fprintf(fp, "PASSWD.: %s\n", passwd());
        fprintf(fp, "DB_NAME: %s\n", m_dbName);
        fprintf(fp, "PORT...: %d\n", port());
        fprintf(fp, "SOCKET.: %s\n", socket());

        fclose(fp);
    }

    return 0;
}
示例#8
0
wb_dbms_env::wb_dbms_env(const char *v_host, const char *v_user, const char *v_passwd,
                         const char *v_dbName, unsigned int v_port, const char *v_socket) :
    m_con(0), m_fileName(0), m_host(0), m_user(0), m_passwd(0), m_dbName(0), m_port(0), m_socket(0), m_exists(false)
{
    host(v_host);
    user(v_user);
    passwd(v_passwd);
    dbName(v_dbName);
    port(v_port);
    socket(v_socket);
}
示例#9
0
void good(void) {
    //[try_catch_good_seq
    try {
        file passwd("/etc/passwd");
        BOOST_SCOPE_EXIT( (&passwd) ) {
            passwd.close();
        } BOOST_SCOPE_EXIT_END
    } catch(...) {
        std::clog << "could not get user info" << std::endl;
        throw;
    }
    //]
}
示例#10
0
MYSQL *wb_dbms_env::openDb()
{
    m_con = mysql_init(NULL);

    MYSQL *con = mysql_real_connect(m_con, host(), user(), passwd(), dbName(), port(), socket(), 0);
    // printf("Tried to connect to database, con %x: Status: %s\n", (int)con, mysql_error(m_con));
    if (con == 0) {
        printf("Failed to connect to database: Error: %s\n", mysql_error(m_con));
        return 0;
    }

    return con;
}
示例#11
0
static bool test_auth(acl::redis_connection& redis)
{
	acl::string passwd("hello");

	redis.clear();
	if (redis.auth(passwd.c_str()) == false)
	{
		printf("auth failed, passwd: %s, eof: %s\r\n",
			passwd.c_str(), redis.eof() ? "yes" : "no");
		return false;
	}
	printf("auth ok, passwd: %s\r\n", passwd.c_str());
	return true;
}
示例#12
0
int wb_dbms_env::create(const char *v_fileName, const char *v_host, const char *v_user,
                        const char *v_passwd, const char *v_dbName, unsigned int v_port,
                        const char *v_socket)
{
    fileName(v_fileName);
    host(v_host);
    user(v_user);
    passwd(v_passwd);
    dbName(v_dbName);
    port(v_port);
    socket(v_socket);

    create();

    return 0;
}
示例#13
0
文件: terminal.c 项目: thigley/THOS
int runCommand(){
	int i = 0;
	int argc = splitString(textBuffer, ' ');
	for(i =0;i<argc;i++){argv[i]=stringArray[i];}
	
	if(k_strcmp(argv[0], "")==0){}
	else if(k_strcmp(argv[0], "clear")==0){ clearScreen(); typeOffset = 0;}
	else if(k_strcmp(argv[0], "history")==0){ printHistory();}
	else if(k_strcmp(argv[0], "pong")==0){ pong();}
	else if(k_strcmp(argv[0], "help")==0){ listCommands();}
	else if(k_strcmp(argv[0], "welcome")==0){ welcome();}
	else if(k_strcmp(argv[0], "splash")==0){ splash();}
	else if(k_strcmp(argv[0], "ls")==0){ ls(argc, argv); }
	else if(k_strcmp(argv[0], "cat")==0){ cat(argc, argv); }
	else if(k_strcmp(argv[0], "rm")==0){ rm(argc, argv); }
	else if(k_strcmp(argv[0], "chmod")==0){ chmod(argc, argv); }
	else if(k_strcmp(argv[0], "te")==0){ te(argc, argv); }
	else if(k_strcmp(argv[0], "cp")==0){ cp(argc, argv); }
	else if(k_strcmp(argv[0], "diff")==0){ diff(argc, argv); }
	else if(k_strcmp(argv[0], "wc")==0){ wc(argc, argv); }
	else if(k_strcmp(argv[0], "su")==0){ su(argc, argv); }
	else if(k_strcmp(argv[0], "chown")==0){ chown(argc, argv); }
	else if(k_strcmp(argv[0], "echo")==0){ echo(argc, argv); }
	else if(k_strcmp(argv[0], "adduser")==0){ adduser(argc, argv); }
	else if(k_strcmp(argv[0], "deluser")==0){ deluser(argc, argv); }
	else if(k_strcmp(argv[0], "listus")==0){ listus(); }
	else if(k_strcmp(argv[0], "passwd")==0){ passwd(argc, argv); }

	else if(k_strcmp(argv[0], "mkdir")==0){ mkdir(argc, argv); }
	else if(k_strcmp(argv[0], "rmdir")==0){ rmdir(argc, argv); }
	else if(k_strcmp(argv[0], "cd")==0){ cd(argc, argv); }
	else if(k_strcmp(argv[0], "pwd")==0){ pwd(argc, argv); }
	else if(k_strcmp(argv[0], "mv")==0){ mv(argc, argv); }

	// else check files
	else {
		printToConsole("Error: Unknown command '");
		printToConsole(argv[0]);
		printToConsole("'\n");
	}

	return 0;
}
示例#14
0
const wxString wxLIRCCSession::GetServerPassword()
{
	wxString passwd( m_svrpwd, wxConvUTF8 );
	return passwd;
}
示例#15
0
int wb_dbms_env::open(void)
{
    char var[32];
    char value[32];
    char buf[512];
    char *s;
    char *valp;
    int rc;

    cdh_ToLower(m_fileName, m_fileName);

    sprintf(buf, "%s/%s", m_fileName, "connection.dmsql");

    FILE *fp = fopen(buf, "r");
    if (fp == NULL) {
        printf("** Cannot open file: %s, %s\n", buf, strerror(errno));
        return errno;
    }

    while ((s = fgets(buf, sizeof(buf) - 1, fp))) {
        if (*s == '#')
            continue;

        rc = sscanf(s, " %[A-Z_] %*[^ ] %s", var, value);
        if (rc < 1)
            continue;
        if (rc == 1)
            valp = 0;
        else
            valp = value;

        if (strcmp(valp, "(null)") == 0)
            valp = 0;

        if (strcmp(var, "HOST") == 0) {
            host(valp);
        }
        else if (strcmp(var, "USER") == 0) {
            user(valp);
        }
        else if (strcmp(var, "PASSWD") == 0) {
            passwd(valp);
        }
        else if (strcmp(var, "DB_NAME") == 0) {
            dbName(valp);
        }
        else if (strcmp(var, "PORT") == 0) {
            if (valp == 0)
                port(0);
            else
                port(atoi(valp));
        }
        else if (strcmp(var, "SOCKET") == 0) {
            socket(valp);
        }
        else {
            printf("Unknown connection parameter! : %s\n", var);
        }
    }

    fclose(fp);

    m_exists = true;

    return 0;
}
示例#16
0
/**
 * This function performs Agent authentication to retrieve the agent
 * agent configuration data from the OpenSSO server
 */
am_status_t AgentProfileService::agentLogin()
{
    std::string userName(boot_info.agent_name);
    std::string passwd(boot_info.agent_passwd);
    const Properties& config =
        *reinterpret_cast<Properties *>(boot_info.properties);
    am_status_t status = AM_SUCCESS;

    Log::log(logModule, Log::LOG_DEBUG, 
         "AgentProfileService()::agentLogin() :%s", userName.c_str());
    AuthService authSvc(config);

    const char *thisfunc = "AgentProfileService::agentLogin()";
    std::string orgName;
    std::string moduleName;

    // Get all the parameters.
    // Right now we just handle username/password callback for LDAP module.
    // in the future we may want to handle different callbacks depending
    // on the module.
    orgName = config.get(AM_POLICY_ORG_NAME_PROPERTY,
                            DEFAULT_AGENT_ORG_NAME);
    moduleName = config.get(AM_POLICY_MODULE_NAME_PROPERTY,
                               DEFAULT_AGENT_AUTH_MODULE);

    // Create Auth context, do login.
    try {
        // The following is necessary check, which resolves this case:
        // opensso/am server not running and agent running. When server is up,
        // then agent will be able to authenticate itself and initializes ok.
        if(mAuthURL.empty()) {
            if(isRESTServiceAvailable()==AM_REST_SERVICE_NOT_AVAILABLE){
                setRepoType(LOCAL_CONFIG);
            } else{
                setRepoType(CENTRAL_CONFIG);
            }
        }
        std::string certName, namingURLs;   // dummy strings for linux compile.
        AuthContext authC(orgName, certName, namingURLs);
        Log::log(logModule, Log::LOG_DEBUG, 
            "AgentProfileService()::agentLogin() :%s", mAuthURL.c_str());
        authC.authSvcInfo.setFromString(mAuthURL);

        authSvc.create_auth_context_cac(authC);
        Log::log(logModule, Log::LOG_DEBUG, 
            "AgentProfileService()::agentLogin() :%s", mAuthURL.c_str());
        authSvc.login(authC, AM_AUTH_INDEX_MODULE_INSTANCE, moduleName);

        std::vector<am_auth_callback_t>& callbacks = authC.getRequirements();
        int nCallbacks = callbacks.size();
        if (nCallbacks > 0) {
            bool userNameIsSet = false;
            bool passwdIsSet = false;
            for (int i = nCallbacks-1; i >= 0; --i) {
                am_auth_callback_t& cb = callbacks[i];
                switch(cb.callback_type) {
                    case NameCallback:
                        Log::log(logModule, Log::LOG_DEBUG,
                         "%s: Setting name callback to '%s'.",
                         thisfunc, userName.c_str());
                        cb.callback_info.name_callback.response = 
                            userName.c_str();
                        userNameIsSet = true;
                        break;
                    case PasswordCallback:
                        Log::log(logModule, Log::LOG_DEBUG,
                         "%s: Setting password callback.", thisfunc);
                        cb.callback_info.password_callback.response = 
                            passwd.c_str();
                        passwdIsSet = true;
                        break;
                    default:
                        // ignore unexpected callback.
                        Log::log(logModule, Log::LOG_WARNING,
                         "%s: Unexpected callback type %d ignored.",
                         thisfunc, cb.callback_type);
                        continue;
                        break;
                }
            }

            authSvc.submitRequirements(authC);

            am_auth_status_t auth_sts = authC.getStatus();
            switch(auth_sts) {
                case AM_AUTH_STATUS_SUCCESS:
                break;
                case AM_AUTH_STATUS_FAILED:
                case AM_AUTH_STATUS_NOT_STARTED:
                case AM_AUTH_STATUS_IN_PROGRESS:
                case AM_AUTH_STATUS_COMPLETED:
                default:
                    status =  AM_AUTH_FAILURE;
                    Log::log(logModule, Log::LOG_ERROR,
                     "Agent failed to login to OpenSSO server, auth status %d.",
                     auth_sts);
                    break;
            }
        }
        else {
            Log::log(logModule, Log::LOG_ERROR,
                 "%s: Agent cannot login to OpenSSO server: Expected auth callbacks "
                 "for agent login not found.", thisfunc);
            status =  AM_AUTH_FAILURE;
        }

        // set the agent SSO Token.
        agentSSOToken = authC.getSSOToken();
        setEncodedAgentSSOToken(agentSSOToken);

        // save the auth context for logging out when service is destroyed
        mAuthCtx = authC;

        Log::log(logModule, Log::LOG_DEBUG, 
             "%s: Successfully logged in as %s.",
             thisfunc, userName.c_str());
    } catch(...) {
        Log::log(logModule, Log::LOG_DEBUG, 
             "%s: login failed for agent profile:  %s.",
             thisfunc, userName.c_str());
        status =  AM_AUTH_FAILURE;
    }

    return status;

}
示例#17
0
/*
 * This function does the actual job of retrieving the agent configuration data
 * if the repository type is local or issuing the REST call to Opensso server
 * to get the latest agent configuration data if the repository type is
 * centralized
 */
am_status_t AgentProfileService::fetchAndUpdateAgentConfigCacheInternal
                           (AgentConfigurationRefCntPtr& agentConfig)
{
    //check for REMOTE/LOCAL, then fetch attributes 
    //set latestConfigkey to the current time and then update AgentConfigCache
    //with a new entry that has the latestConfigKey as the key and agentConfig
    //as the value.

    const char *thisfunc = "fetchAndUpdateAgentConfigCache()";
    am_properties_t properties;
    am_status_t status;
//    am_status_t authStatus = AM_FAILURE;
    std::string userName(boot_info.agent_name);
    std::string passwd(boot_info.agent_passwd);
    std::string sharedAgentProfileName(boot_info.shared_agent_profile_name);
    std::string realmName(boot_info.realm_name);
    const char* agentConfigFile = boot_info.agent_config_file;
//    const Properties& propPtr =
//        *reinterpret_cast<Properties *>(boot_info.properties);

    if (getRepoType() == LOCAL_CONFIG) {
        am_properties_create(&properties);
        status = am_properties_load(properties,agentConfigFile);
        if (status != AM_SUCCESS ) {
            am_web_log_error("%s: Identity REST Services Endpoint URL not"
                " available. Also failed to load local agent configuration file"
                ", %s. Please check for any configuration errors during "
                "installation.", thisfunc, agentConfigFile);
        }
    }
    else {
            am_properties_t tmpPropPtr;
            status = am_properties_create(&tmpPropPtr);
            
            if (status == AM_SUCCESS) {
                status = getAgentAttributes(agentSSOToken, 
                            sharedAgentProfileName,
                            realmName,
                            tmpPropPtr);               
                if (status == AM_SUCCESS) {
                    const char* repoType = NULL;
                    boolean_t repoKeyPresent;
                    repoKeyPresent = am_properties_is_set(tmpPropPtr,
                        AM_WEB_AGENT_REPOSITORY_LOCATION_PROPERTY);
                    
                    if( repoKeyPresent == B_TRUE) {
                        status = am_properties_get(tmpPropPtr,
                            AM_WEB_AGENT_REPOSITORY_LOCATION_PROPERTY,
                            &repoType );
                        if (status == AM_SUCCESS) {
                            if (strcasecmp(repoType, AGENT_PROPERTIES_LOCAL) == 0) {
                                //LOCAL repo type
                                am_web_log_info("%s:Repository type property is "
                                                "set to %s in agent profile, "
                                                "%s. ", thisfunc, repoType, 
                                                userName.c_str());
                                am_properties_create(&properties);
                                status = am_properties_load(properties,
                                                            agentConfigFile);
                                if (status != AM_SUCCESS) {
                                   am_web_log_error("%s: Repository type property "
                                                    "is set to %s in agent "
                                                    "profile, %s. But Agent "
                                                    "failed to load local %s "
                                                    "file", thisfunc, repoType, 
                                                    userName.c_str(), 
                                                    agentConfigFile);
                                }                               
                            }  else if (strcasecmp(repoType, 
                                       AGENT_PROPERTIES_CENTRALIZED) == 0) {
                                // REMOTE repo type
                                am_properties_create(&properties);
                                am_properties_copy(tmpPropPtr, &properties);
                            } else { //treat as misconfiguration
                                am_web_log_error("%s: Repository type property is "
                                    "present  in agent profile, %s, "
                                    "but invalid value is present, %s."
                                    "Sepcify valid value (local|centralized) "
                                    "to make agent function properly.",
                                    thisfunc, userName.c_str(), repoType);
                                status = AM_REPOSITORY_TYPE_INVALID;
                            }
                        } else { //treat as misconfiguration
                            am_web_log_error("%s:Repository type property is "
                                "present in agent profile, %s, "
                                "but invalid value is present, %s."
                                "Sepcify valid value (local|centralized) "
                                "to make agent function properly.",
                                thisfunc, userName.c_str(), repoType);
                            status = AM_REPOSITORY_TYPE_INVALID;
                        }
                        
                    } else { // repository property doesn't exist
                        am_web_log_warning("%s:Repository type property is not "
                                            "present in agent profile, %s. "
                                            "So Agent tries to load "
                                            "from local %s file", thisfunc,
                                            userName.c_str(), agentConfigFile);
                        am_properties_create(&properties);
                        status = am_properties_load(properties,agentConfigFile);
                        if (status != AM_SUCCESS) {
                            am_web_log_error("%s: Agent failed to load local"
                                             "file, %s", thisfunc, agentConfigFile);
                        }                        
                    }
                } else {
                    am_web_log_error("%s:There is an error while fetching"
                                     " attributes by user %s, using REST service. "
                                     "Status: %s ", thisfunc,
                                     userName.c_str(), 
                                     am_status_to_string(status));
                    status = AM_REST_ATTRS_SERVICE_FAILURE;
                }                
            }
            am_properties_destroy(tmpPropPtr);
    }
    //Insert the AMAgentConfiguration object in the hast table with the current
    //time stamp as its key.
    if (status == AM_SUCCESS ) {
        // AgentConfigurationRefCntPtr agentConfig;
        agentConfig = new AgentConfiguration(properties);
        status = load_bootinfo_to_properties(&boot_info, 
                agentConfig->getProperties());
        agentConfigCache.populateAgentConfigCacheTable(agentConfig);
    }
    return status;
}
示例#18
0
void NetworkAccount::writeConfig(KConfig/*Base*/ & config)   /*const*/
{
    KMAccount::writeConfig(config);

    config.writeEntry("login", login());
    config.writeEntry("store-passwd", storePasswd());

    if(storePasswd())
    {
        // write password to the wallet if possbile and necessary
        bool passwdStored = false;
        if(mPasswdDirty)
        {
            Wallet *wallet = kmkernel->wallet();
            if(wallet && wallet->writePassword("account-" + QString::number(mId), passwd()) == 0)
            {
                passwdStored = true;
                mPasswdDirty = false;
                mStorePasswdInConfig = false;
            }
        }
        else
        {
            passwdStored = !mStorePasswdInConfig; // already in the wallet
        }
        // if wallet is not available, write to config file, since the account
        // manager deletes this group, we need to write it always
        if(!passwdStored && (mStorePasswdInConfig || KMessageBox::warningYesNo(0,
                             i18n("KWallet is not available. It is strongly recommended to use "
                                  "KWallet for managing your passwords.\n"
                                  "However, KMail can store the password in its configuration "
                                  "file instead. The password is stored in an obfuscated format, "
                                  "but should not be considered secure from decryption efforts "
                                  "if access to the configuration file is obtained.\n"
                                  "Do you want to store the password for account '%1' in the "
                                  "configuration file?").arg(name()),
                             i18n("KWallet Not Available"),
                             KGuiItem(i18n("Store Password")),
                             KGuiItem(i18n("Do Not Store Password")))
                             == KMessageBox::Yes))
        {
            config.writeEntry("pass", encryptStr(passwd()));
            mStorePasswdInConfig = true;
        }
    }

    // delete password from the wallet if password storage is disabled
    if(!storePasswd() && !Wallet::keyDoesNotExist(
                Wallet::NetworkWallet(), "kmail", "account-" + QString::number(mId)))
    {
        Wallet *wallet = kmkernel->wallet();
        if(wallet)
            wallet->removeEntry("account-" + QString::number(mId));
    }

    config.writeEntry("host", host());
    config.writeEntry("port", static_cast<unsigned int>(port()));
    config.writeEntry("auth", auth());
    config.writeEntry("use-ssl", useSSL());
    config.writeEntry("use-tls", useTLS());

    mSieveConfig.writeConfig(config);
}
示例#19
0
main()
{
    Emp E[Max];
    int opc,num,band,bandd,opcion,u,c,j,b;
    char password[x],password1[x];
    char usuario[x],usuario1[x];
    do{
        printf("\n\n\t\t<< MENU >>");
        printf("\n\n\t\t1. Capturar ");
        printf("\n\n\t\t2. Eliminar");
        printf("\n\n\t\t3. Mostrar");
        printf("\n\n\t\t4. Consulta");
        printf("\n\n\t\t5. Sueldo Mensual");
        printf("\n\n\t\t6. Password");
        printf("\n\n\t\t7. Salir");
        printf("\n\n\t-->Elige una Opcion: ");
        scanf("%d",&opc);
        switch(opc){
            case 1:
                band=1;
                printf("\n\t\t << Captura de Datos >>\n");
                printf("\n\t-->No. de Empleados a Capturar: ");
                scanf("%d",&num);
                IDEmp(E,num);
                Captura(E,num);
            break;
            case 2:
                if(band==1){
                    if(bandd==1){
                        b=1;
                        j=1;
                        while(j<=3 && b==1){
                            b=0;
                            passwd(password1,usuario1);
                            u=strcmpi(password,password1);
                            c=strcmpi(usuario,usuario1);
                            if(u==0 && c==0){
                                printf("\n\n\t\t << Eliminar Datos >>\n");
                                Eliminar(E,num);
                            }
                            else
                                printf("\n\n\t-->Datos Incorrectos");
                            j++;
                            }
                            if(j=3)
                                printf("\n\n\t-->Se Agotaron los Intentos");
                    }
                    else
                        printf("\n\n\t-->Es Necesario un Usuario Registrado");
                }
                else
                    printf("\n\n\t-->No hay Datos Capturados");
            break;
            case 3:
                if(band==1){
                    printf("\n\t\t << Mostrar Datos >>\n");
                    Mostrar(E,num);
                }
                else
                    printf("\n\n\t-->No hay Datos Capturados");
            break;
            case 4:
                if(band==1){
                    printf("\n\t\t << Consulta de Datos >>\n");
                    Consulta(E,num);
                }
                else
                    printf("\n\n\t-->No hay Datos Capturados");
            break;
            case 5:
                if(band==1){
                    printf("\n\t\t << Calcular Sueldo Mensual >>\n");
                    SueldoMensual(E,num);
                }
                else
                    printf("\n\n\t-->No hay Datos Capturados");
            break;
            case 6:
                do{
                    printf("\n\n\t\t<< Menu Password >>");
                    printf("\n\n\t\t1. Crear Password");
                    printf("\n\n\t\t2. Modificar Password");
                    printf("\n\n\t\t3. Salir");
                    printf("\n\n\t-->Elige una Opcion: ");
                    scanf("%d",&opcion);
                    switch(opcion){
                        case 1:
                            bandd=1;
                            printf("\n\n\t\t<< Crear Usuario >>");
                            passwd(password,usuario);
                            printf("\n\n\t-->Datos Guardados");
                        break;
                        case 2:
                            if(bandd==1){
                                printf("\n\n\t\t<< Modificar Usuario >>");
                                printf("\n\n\t\tDatos Actuales: ");
                                passwd(password1,usuario1);
                                u=strcmpi(password,password1);
                                c=strcmpi(usuario,usuario1);
                                if(u==0 && c==0){
                                    printf("\n\n\t\tNuevos Datos: ");
                                    passwd(password1,usuario1);
                                    printf("\n\n\t-->Datos Guardados");
                                }
                                else
                                    printf("\n\n\t-->Datos Incorrectos");
                            }
                            else
                                printf("\n\n\t-->No Existe Contrasena");
                        break;
                        case 3:
                            printf("\n\n\t\t-->Regresar\n");
                        break;
                        default:
                            printf("\n\n\t-->La Opcion es Incorrecta");
                    }
                }while(opcion!=3);
            break;
            case 7:
                printf("\n\n\t-->Gracias por su Visita\n");
            break;
            default:
                printf("\n\n\t-->Opcion Incorrecta");
        }
    }while(opc!=7);
}
示例#20
0
文件: s3fs.cpp 项目: anandu/s3fslite
int main(int argc, char *argv[]) {
    memset(&s3fs_oper, 0, sizeof(s3fs_oper));

    struct fuse_args custom_args = FUSE_ARGS_INIT(argc, argv);
    fuse_opt_parse(&custom_args, NULL, NULL, my_fuse_opt_proc);

    if (bucket.size() == 0) {
        std::cout << argv[0] << ": " << "missing bucket" << std::endl;
        exit(1);
    }

    if (AWSSecretAccessKey.size() == 0) {
        std::string line;
        std::ifstream passwd("/etc/passwd-s3fs");
        while (!getline(passwd, line).eof()) {
            if (line[0]=='#')
                continue;
            size_t pos = line.find(':');
            if (pos != std::string::npos) {
                // is accessKeyId missing?
                if (AWSAccessKeyId.size() == 0)
                    AWSAccessKeyId = line.substr(0, pos);
                // is secretAccessKey missing?
                if (AWSSecretAccessKey.size() == 0) {
                    if (line.substr(0, pos) == AWSAccessKeyId)
                        AWSSecretAccessKey =
                            line.substr(pos + 1, std::string::npos);
                }
            }
        }
    }

    if (AWSAccessKeyId.size() == 0) {
        std::cout << argv[0] << ": " << "missing accessKeyId.. see "
            "/etc/passwd-s3fs or use, e.g., -o accessKeyId=aaa" << std::endl;
        exit(1);
    }
    if (AWSSecretAccessKey.size() == 0) {
        std::cout << argv[0] << ": " << "missing secretAccessKey... see "
            "/etc/passwd-s3fs or use, e.g., -o secretAccessKey=bbb" <<
            std::endl;
        exit(1);
    }

    s3fs_oper.getattr = s3fs_getattr;
    s3fs_oper.readlink = s3fs_readlink;
    s3fs_oper.mknod = s3fs_mknod;
    s3fs_oper.mkdir = s3fs_mkdir;
    s3fs_oper.unlink = s3fs_unlink;
    s3fs_oper.rmdir = s3fs_rmdir;
    s3fs_oper.symlink = s3fs_symlink;
    s3fs_oper.rename = s3fs_rename;
    s3fs_oper.link = s3fs_link;
    s3fs_oper.chmod = s3fs_chmod;
    s3fs_oper.chown = s3fs_chown;
    s3fs_oper.truncate = s3fs_truncate;
    s3fs_oper.open = s3fs_open;
    s3fs_oper.read = s3fs_read;
    s3fs_oper.write = s3fs_write;
    s3fs_oper.statfs = s3fs_statfs;
    s3fs_oper.release = s3fs_release;
    s3fs_oper.fsync = s3fs_fsync;
    s3fs_oper.readdir = s3fs_readdir;
    s3fs_oper.init = s3fs_init;
    s3fs_oper.destroy = s3fs_destroy;
    s3fs_oper.utimens = s3fs_utimens;

    // load the list of mime types
    std::string line;
    std::ifstream passwd("/etc/mime.types");
    while (passwd.good() && !getline(passwd, line).eof()) {
        if (line[0] == '#')
            continue;
        std::stringstream tmp(line);
        std::string mimeType;
        tmp >> mimeType;
        while (tmp) {
            std::string ext;
            tmp >> ext;
            if (ext.size() == 0)
                continue;
            mimeTypes[ext] = mimeType;
        }
    }

    attrcache = new Attrcache(bucket, attr_cache);

    // form the host URL
    // if it contains "%s", replace it with the bucket name
    // if not, assume it already has the bucket name embedded
    size_t found = host.find("%s");
    if (found != std::string::npos)
        host.replace(found, 2, bucket);

    int status =
        fuse_main(custom_args.argc, custom_args.argv, &s3fs_oper, NULL);

    delete attrcache;
    return status;
}