static int accept_client(int servfd, pid_t *pid, char *locale, size_t locale_len, uint_t *flagsp) { int connfd; struct sockaddr_un cliaddr; socklen_t clilen; int flags; clilen = sizeof (cliaddr); connfd = accept(servfd, (struct sockaddr *)&cliaddr, &clilen); if (connfd == -1) return (-1); if (pid != NULL) { if (get_client_ident(connfd, pid, locale, locale_len, flagsp) == -1) { (void) shutdown(connfd, SHUT_RDWR); (void) close(connfd); return (-1); } (void) write(connfd, "OK\n", 3); } flags = fcntl(connfd, F_GETFD, 0); if (flags != -1) (void) fcntl(connfd, F_SETFD, flags | O_NONBLOCK | FD_CLOEXEC); return (connfd); }
Tango::DevLong DServer::un_lock_device(const Tango::DevVarLongStringArray *in_data) { NoSyncModelTangoMonitor mon(this); cout4 << "In un_lock_device command for device " << in_data->svalue[0] << endl; // // Get client identification // Tango::client_addr *cl = get_client_ident(); if (cl == NULL) { Except::throw_exception((const char*)"API_CantGetClientIdent", (const char*)"Cannot retrieve client identification", (const char*)"DServer::un_lock_device"); } cout4 << "Client identification = " << *cl << endl; if ((cl->client_ident == false) && (in_data->lvalue[0] == 0)) { Except::throw_exception((const char*)"API_ClientTooOld", (const char*)"Your client cannot un-lock devices. You are using a too old Tango release. Please, update to tango V7 or more", (const char*)"DServer::un_lock_device"); } // // Get the device and unlock it // DevLong ctr = 0; Tango::Util *tg = Tango::Util::instance(); for (unsigned int loop = 0;loop < in_data->svalue.length();++loop) { string d_name(in_data->svalue[loop]); if (d_name == get_name()) ctr = ext->lock_ctr; else { DeviceImpl *the_dev = tg->get_device_by_name(d_name); ctr = the_dev->unlock((bool)in_data->lvalue[0]); } if (loop > 0) ctr = 0; } return ctr; }
static int accept_client(int servfd, pid_t *pid, char *locale, size_t locale_len) { int connfd; struct sockaddr_un cliaddr; socklen_t clilen; clilen = sizeof (cliaddr); connfd = accept(servfd, (struct sockaddr *)&cliaddr, &clilen); if (connfd == -1) return (-1); if (get_client_ident(connfd, pid, locale, locale_len) == -1) { (void) shutdown(connfd, SHUT_RDWR); (void) close(connfd); return (-1); } (void) write(connfd, "OK\n", 3); return (connfd); }
static void reject_client(int servfd, pid_t clientpid) { int connfd; struct sockaddr_un cliaddr; socklen_t clilen; char nak[MAXPATHLEN]; clilen = sizeof (cliaddr); connfd = accept(servfd, (struct sockaddr *)&cliaddr, &clilen); /* * After getting its ident string, tell client to get lost. */ if (get_client_ident(connfd, NULL, NULL, 0, NULL) == 0) { (void) snprintf(nak, sizeof (nak), "%lu\n", clientpid); (void) write(connfd, nak, strlen(nak)); } (void) shutdown(connfd, SHUT_RDWR); (void) close(connfd); }
void DServer::lock_device(const Tango::DevVarLongStringArray *in_data) { NoSyncModelTangoMonitor mon(this); string dev_name(in_data->svalue[0]); int lock_validity = in_data->lvalue[0]; cout4 << "In lock_device command for device " << dev_name << ", lock validity = " << lock_validity << endl; // // Get client identification // Tango::client_addr *cl = get_client_ident(); if (cl == NULL) { Except::throw_exception((const char*)"API_CantGetClientIdent", (const char*)"Cannot retrieve client identification", (const char*)"DServer::lock_device"); } cout4 << "Client identification = " << *cl << endl; if (cl->client_ident == false) { Except::throw_exception((const char*)"API_ClientTooOld", (const char*)"Your client cannot lock devices. You are using a too old Tango release. Please, update to tango V7 or more", (const char*)"DServer::lock_device"); } // // Transform device name to lower case // Tango::Util *tg = Tango::Util::instance(); string local_dev_name(get_name()); transform(local_dev_name.begin(),local_dev_name.end(),local_dev_name.begin(),::tolower); string d_name_lower(dev_name); transform(d_name_lower.begin(),d_name_lower.end(),d_name_lower.begin(),::tolower); // // Refuse to lock the admin device // if (d_name_lower == local_dev_name) { Except::throw_exception((const char *)"API_DeviceUnlockable", (const char *)"Impossible to lock device server administration device", (const char *)"DServer::lock_device"); } // // Get device ptr // DeviceImpl *the_dev; the_dev = tg->get_device_by_name(dev_name); // // Refuse to lock database device // string &cl_name = the_dev->get_device_class()->get_name(); if (::strcmp(cl_name.c_str(),DATABASE_CLASS) == 0) { Except::throw_exception((const char *)"API_DeviceUnlockable", (const char *)"Impossible to lock database device", (const char *)"DServer::lock_device"); } // // Mark the device as locked // the_dev->lock(cl,lock_validity); }
void DServer::re_lock_devices(const Tango::DevVarStringArray *dev_name_list) { NoSyncModelTangoMonitor mon(this); cout4 << "In re_lock_devices command" << endl; CORBA::ULong loop; CORBA::ULong nb_dev = dev_name_list->length(); for (loop = 0;loop < nb_dev;loop++) cout4 << "Device to re-lock: " << (*dev_name_list)[loop] << endl; // // Get client identification // Tango::client_addr *cl = get_client_ident(); if (cl == NULL) { Except::throw_exception((const char*)"API_CantGetClientIdent", (const char*)"Cannot retrieve client identification", (const char*)"DServer::re_lock_devices"); } cout4 << "Client identification = " << *cl << endl; if (cl->client_ident == false) { Except::throw_exception((const char*)"API_ClientTooOld", (const char*)"Your client cannot re_lock devices. You are using a too old Tango release. Please, update to tango V7 or more", (const char*)"DServer::re_lock_devices"); } // // ReLock the devices // If we have an error in this loop, memorize it and throw the exception at the // end of the loop // Tango::Util *tg = Tango::Util::instance(); DevErrorList errors; long nb_error = 0; for (loop = 0;loop < nb_dev;loop++) { string d_name((*dev_name_list)[loop]); // // Get device ptr // DeviceImpl *the_dev = NULL; try { the_dev = tg->get_device_by_name(d_name); } catch (Tango::DevFailed &e) { errors.length(nb_error + 1); errors[nb_error].desc = CORBA::string_dup(e.errors[0].desc.in()); errors[nb_error].reason = CORBA::string_dup(e.errors[0].reason.in()); errors[nb_error].origin = CORBA::string_dup(e.errors[0].origin.in()); errors[nb_error].severity = e.errors[0].severity; nb_error++; } // // ReLock the device // try { the_dev->relock(cl); } catch (Tango::DevFailed &e) { errors.length(nb_error + 1); errors[nb_error].desc = CORBA::string_dup(e.errors[0].desc.in()); errors[nb_error].reason = CORBA::string_dup(e.errors[0].reason.in()); errors[nb_error].origin = CORBA::string_dup(e.errors[0].origin.in()); errors[nb_error].severity = e.errors[0].severity; nb_error++; } } // // Throw the exception if we had one during the loop // if (nb_error != 0) { throw Tango::DevFailed(errors); } }