i.mx6 SU.C Test

Source: Internet
Author: User

/************************************************************************* * i.mx6 su.c Test * Description: * Today suddenly want to analyze Su's source code, look at its working mechanism. * 2016-8-10 Shenzhen Nanshan Ping Shan village Zengjianfeng **************************************************** ********************/First, SU source code modification:/** * * Copyright, the Android Open Source Project * * * Licensed under the Apache License, Version 2.     0 (the "License");     * * Do not use this file except in compliance with the License. * * Obtain a copy of the License at * * * *http://www.apache.org/licenses/LICENSE-2.0* * * unless required by applicable law or agreed to writing, software * Distributed under the License     is distributed on a "as is" BASIS, * * without warranties or CONDITIONS of any KIND, either express OR implied.    * * See the License for the specific language governing permissions and * * Limitations under the License. */        #defineLog_tag "Su"#include<stdio.h>#include<stdlib.h>#include<string.h>#include<sys/types.h>#include<dirent.h>#include<errno.h>#include<unistd.h>#include<time.h>#include<pwd.h>#include<Private/android_filesystem_config.h>/** SU can is given a specific command to exec.     UID _must_ is * specified for this (ie ARGC = 3). * Usage: * Su-ls-l * su*/    intMainintargcChar**argv) {        structpasswd *PW; intuid, GID, myuid; /*Until We have something better, only root and the shell can use Su.*/myUID=Getuid (); //if (myuid! = Aid_root && myUID! = Aid_shell) {//fprintf (stderr, "su:uid%d not allowed to su\n", myUID); //     //return 1; // }            if(ARGC <2) {UID= GID =0; } Else{PW= Getpwnam (argv[1]); if(PW = =0) {UID= GID = Atoi (argv[1]); } Else{UID= pw->Pw_uid; GID= pw->Pw_gid; }        }            //if (setgid (GID) | | setuid (UID)) {//fprintf (stderr, "su:permission denied\n"); //return 1; // }            /*User specified command for exec.*/        if(ARGC = =3 ) {            if(EXECLP (argv[2], argv[2], NULL) <0) {fprintf (stderr,"Su:exec failed for%s error:%s\n", argv[2], strerror (errno)); return-errno; }        } Else if(Argc >3) {            /*Copy The rest of the args from main.*/            Char*EXEC_ARGS[ARGC-1]; memset (Exec_args,0,sizeof(Exec_args)); memcpy (Exec_args,&argv[2],sizeof(Exec_args)); if(EXECVP (argv[2], Exec_args) <0) {fprintf (stderr,"Su:exec failed for%s error:%s\n", argv[2], strerror (errno)); return-errno; }        }            /*Default exec shell.*/EXECLP ("/system/bin/sh","SH", NULL); fprintf (stderr,"su:exec failed\n"); return 1; } Two, permissions: chmod4775/system/xbin/Su III, call:Private StaticString cmdlist[] = {        "su 0 netcfg can0 down",        "su 0 IP link set can0 type can bitrate 1000000 triple-sampling on",        "su 0 netcfg can0 up",    };

i.mx6 SU.C Test

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.