How you would change the default target to multiuser.target in Centos7 - centos7

Hello
How you would change the default target to multiuser.target in Centos7 which allows multi user mode but with the graphical user interface not starting
Thank you in advance

Related

How to request serial port permissions with polkit on Linux?

I'm writing a cross-platform app that I would like to run on Linux-based operating systems like Fedora and Ubuntu. I use QSerialPort and it works fine. I can use QSerialPortInfo to get a list of serial ports in the system and present them to the user who can select which one s/he wants to use.
However, on Linux systems, by default the user doesn't have permissions to the serial ports. I know that it is wrong to run my app with sudo and I also know that it is not user friendly to ask the user to run chmod 666 on the serial port manually every time the app is used. So I looked around and it seems to me that polkit is the answer, however I haven't been able to find any example which would show me how to do it.
Can you please tell me how to use polkit (formerly known as policykit) to request permission for my app to use a specific serial port?
EDIT:
What I'm looking for is a way to:
Check if the user has access to the serial port
If not, pop up a dialog that asks for permission (like the Gnome settings app for example)
If the user authenticated successfully, make the serial port available to the app.
Some more thoughts
I do NOT want to set up an udev rule that gives perimission to every serial port
I do NOT want to ask the user to run a script
I do NOT want my app to run as the superuser
I do NOT want any other actions performed as root, just the serial port access
Yes I've found the official polkit docs, but they are not very clear on how to do this.
General thinking:
It is not a good idea to try to make an application "universal".
I understand that you want your software to be easy to use, but for things like this (system's settings), you should rely on the system packagers.
At anytime, polkit can be replaced by another solution, or ressource's name can be changed, or whatever and your application would be no more usable.
I advise you to:
at most, raise a polkit windows that woulde ask for password
or better, to make distribution packages that will do the necessary tweaks through regular scripts
An idea
I didn't do it (but I played a lot in the past with pam :-) )
So here are links that I found and what I understood:
polkit acts the same way as sudo do: it allow you to run program with another identity (explanations)
so you can run your program either as root or as one having enough right access to the serial
So you could create:
an install script that allow to run your program with the good identity (e.g. example). That way you would ask root password once (at the install for creating the polkit policy), and each time the user wanted to run your program. That identity maybe root or any identity as long as that identity has R/W access.
a policy file: you can look either at 1 or documentation
a script for lauching your program containing something like this: pkexec <path>/<pgm>
Here are some pointers:
an admin guide to polkit: 3
(I'm a debian user but I like their docs)
the official documentation: https://www.freedesktop.org/software/polkit/docs/master/index.html

C++: Remotely hibernate a PC

How can I hibernate a Windows machine that runs Windows 7 or 8 over my LAN from another PC?
Is there a WinAPI function for that? Or do I have to send special magic packets or something like this?
All I know is that PsShutdown.exe is able to do it (allegedly. I haven't tried it).
I don't want to use third party libraries and I also don't want to run a service on the computer that is supposed to get hibernated. I want to use the existing mechanism.
I'd also like to know if I need to change specific settings on the target computer.
I'm not sure if that's important, but shutdown /s /m \\ComputerName did not work on my target PC.
The TechNet document Restart or Shut Down a Remote Computer and Document the Reason describes the requirements to use the shutdown.exe command against a remote computer.
In order to use this feature, the Remote Registry service must be enabled on the remote computer.
Access to the Remote Registry or membership in the Administrators group on the remote computer is the minimum required to complete this procedure
To the best of my knowledge, the only way to remotely hibernate a machine is to use the same method that psshutdown does: copy an executable to the remote machine and install it as a system service.
The OpenSCManager API allows you to specify a target computer, and you can use the handle it returns to call CreateService and then StartService. The service can delete itself once it has done its work.

Have my GTK application started on startup on Linux

I have an C++ executable that include some GTK code. I want this application to be started on startup of my machine (as root).
I tried with a init script (that is working perfectly when I use it from my user session), but having a look at the log file of my application I see that the latest logged line is before to call Gtk::Application::create() so it seems that it too earlier to initialize GTK.
How can I have my application started after the user session opened so that GTK initialisation is not failing ?
Create a .desktop file of your application, and put it to /etc/xdg/autostart/ for each user, or to $HOME/.config/autostart/ for current user.
If you want to load that application as root for general users, you may choose to use gksu or other tools to authorize priviledge.
Alternatively, you can see how network-manager is designed. It inits network-manager module as a init-script when system starts, and loads nm-applet, which is GUI for ordinary user, when a user session loads. Thus, network-manager can be managed on all the desktop environment (like Gnome, KDEE, xfce...) by desktop users.

Windows Service not launching as local session

Am working on Creating windows service and launching an exe application through this,
from this link i have created a windows service Windows Service
But when i create a setup and deployment and then if i install, the exe which am calling from the service is launched as LOCAL SERVICE.
Still i can the xxx.exe in task manager as LOCAL SERVICE.
I cant figure even with this help : Launching GUI from windows service
How can i launch this exe as the local username which i have logged in ?
You have a number of options for creating a process that runs under a different user from the parent process:
CreateProcessAsUser or CreateProcessWithTokenW. These require you to obtain a primary token that represents a user, calling either LogonUser or DuplicateTokenEx.
CreateProcessWithLogonW which allows you to specify the user name and password as parameters.
However, if you want the process that you create to appear on the interactive desktop, you need to do quite a bit of work. This article covers the details: Launching an interactive process from Windows Service in Windows Vista and later.

How to ask for Administrator privileges in Windows 7?

I wrote an application using Qt under Windows 7. The application starts up with normal user privileges, but I want to gain the Administrator privileges because I want to modify the registry to auto-start the application.
How could I do this?
Take a look at the MSDN sample: UAC self-elevation (CSUACSelfElevation)
Also, Wikipedia actually has a pretty good reference including information on the ShellExecuteEx() "runas" verb and application manifest for elevation requests.
You should embedd correct manifest to your exe:
http://msdn.microsoft.com/en-us/library/windows/desktop/bb756929.aspx.
I know, you said using win32 API, but consider this standard and recommended way.
You do not need administrator privileges to autostart your application.
Simply write the appropriate keys to:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
which does not require administrator privileges (unlike the same path under HKEY_LOCAL_MACHINE).
to auto-startup the application, you don't need admin rights! Instead of adding the registry key under HKLM (where you need admin rights), use HKCU and you're fine.
Note that privileges cannot be changed while the program is running. It has to be killed and restarted with the correct privileges.
To make an application auto start in HKLM, the administrative privilege is needed. But the privilege of an application could not change while running.
So I made a new small application whose task is only write the registry to make the main application auto start.
The main application could call this application with ShellExecuteEx to require administrative privlege.