/* *---------------------------------------------------------------------- * * main -- * * Prompts the user for information needed to create a new * account. Sticks all the info into a buffer and mails it * to the person who will create the account. * * Results: * None. * * Side effects: * Sends mail. * *---------------------------------------------------------------------- */ void main() { static char login_name[BUFFER_SIZE]; static char full_name[BUFFER_SIZE]; static char group[BUFFER_SIZE]; static char home_phone[BUFFER_SIZE]; static char office[BUFFER_SIZE]; static char office_phone[BUFFER_SIZE]; static char project[BUFFER_SIZE]; static char encrypted_passwd[BUFFER_SIZE]; static char machine[BUFFER_SIZE]; const char *shell; char *p; int y; char buffer[0x1000]; struct group *grp; struct passwd *pwd; for (;;) { printf("Please enter the following information:\n"); for (;;) { getString(":", "Login name ", login_name); if ((pwd = getpwnam(login_name)) != NULL) { char *p = pwd->pw_gecos; while (*p && *p != ',') { ++p; } *p = '\0'; printf("Sorry, `%s' is already in use: %s\n", login_name, pwd->pw_gecos); continue; } break; } getString(":", "Full name ", full_name); for (;;) { getString(":", "Group ", group); if (isdigit(*group)) { grp = getgrgid(atoi(group)); } else { grp = getgrnam(group); } if (grp == NULL) { printf("%s is not a valid group\n", group); printf("Please try again\n"); continue; } break; } getString(":,", "Office ", office); getString(":,", "Office phone", office_phone); getString(":,", "Home phone ", home_phone); shell = getShell(); getPasswd(encrypted_passwd); getString("", "Project ", project); getString("", "Machine to forward mail to", machine); printf("\n\n\n"); printf("Login name: %s\n", login_name); printf("Full name: %s\n", full_name); printf("Group: %s %d\n", grp->gr_name, grp->gr_gid); printf("Office: %s\n", office); printf("Office phone: %s\n", office_phone); printf("Home phone: %s\n", home_phone); printf("Shell: %s\n", shell); printf("Project: %s\n", project); printf("Mail forwarded to: %s\n", machine); printf("\n"); if (yes("Is this correct?")) { break; } } sprintf(buffer, "%s\n%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n%s%s\n", "Request for New Account", "-----------------------", "Login name: ", login_name, "password: "******"Full name: ", full_name, "Group: ", grp->gr_name, "Office: ", office, "Office phone: ", office_phone, "Home phone: ", home_phone, "Shell: ", shell, "Project: ", project, "Mail forwarded to: ", machine); printf("Sending mail to %s ...", MAIL_WHO); mail(MAIL_WHO, buffer); printf("\nThank you. The account will be ready in a few days.\n"); exit(0); }
void SslCredential::loadPrivCertStore() { // Get a handle to the system store or pkcs#12 file qpid::sys::ssl::SslOptions& opts = qpid::sys::ssl::SslOptions::global; if (opts.certFilename.empty()) { // opening a system store, names are not case sensitive std::string store = opts.certStore.empty() ? "my" : opts.certStore; std::transform(store.begin(), store.end(), store.begin(), ::tolower); // map confusing GUI name to actual registry store name if (store == "personal") store = "my"; certStore = ::CertOpenStore(CERT_STORE_PROV_SYSTEM_A, 0, NULL, CERT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONLY_FLAG | CERT_SYSTEM_STORE_CURRENT_USER, store.c_str()); if (!certStore) { HRESULT status = GetLastError(); loadError.set(Msg() << "Could not open system certificate store: " << store, status); return; } QPID_LOG(debug, "SslConnector using certifcates from system store: " << store); } else { // opening the store from file and populating it with a private key HANDLE certFileHandle = NULL; certFileHandle = CreateFile(opts.certFilename.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (INVALID_HANDLE_VALUE == certFileHandle) { HRESULT status = GetLastError(); loadError.set(Msg() << "Failed to open the file holding the private key: " << opts.certFilename, status); return; } std::vector<BYTE> certEncoded; DWORD certEncodedSize = 0L; const DWORD fileSize = GetFileSize(certFileHandle, NULL); if (INVALID_FILE_SIZE != fileSize) { certEncoded.resize(fileSize); bool result = false; result = ReadFile(certFileHandle, &certEncoded[0], fileSize, &certEncodedSize, NULL); if (!result) { // the read failed, return the error as an HRESULT HRESULT status = GetLastError(); CloseHandle(certFileHandle); loadError.set(Msg() << "Reading the private key from file failed " << opts.certFilename, status); return; } } else { HRESULT status = GetLastError(); loadError.set(Msg() << "Unable to read the certificate file " << opts.certFilename, status); return; } CloseHandle(certFileHandle); CRYPT_DATA_BLOB blobData; blobData.cbData = certEncodedSize; blobData.pbData = &certEncoded[0]; // get passwd from file and convert to null terminated wchar_t (Windows UCS2) std::string passwd = getPasswd(opts.certPasswordFile); if (loadError.pending()) return; int pwlen = passwd.length(); std::vector<wchar_t> pwUCS2(pwlen + 1, L'\0'); int nwc = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, passwd.data(), pwlen, &pwUCS2[0], pwlen); if (!nwc) { HRESULT status = GetLastError(); loadError.set("Error converting password from UTF8", status); return; } certStore = PFXImportCertStore(&blobData, &pwUCS2[0], 0); if (certStore == NULL) { HRESULT status = GetLastError(); loadError.set("Failed to open the certificate store", status); return; } QPID_LOG(debug, "SslConnector using certificate from pkcs#12 file: " << opts.certFilename); } }