Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update USER and LOGNAME environmental variables #17

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Vim swap files
.*.swp

# Object files
*.o
*.ko
Expand Down Expand Up @@ -32,3 +35,6 @@
*.dSYM/

su-exec
su-exec-static
su-exec-debug
license.inc
32 changes: 26 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@

CFLAGS ?= -Wall -Werror -g
CFLAGS ?= -Wall -Werror -Iinclude
LDFLAGS ?=

PROG := su-exec
SRCS := $(PROG).c
INCS := license.inc

PREFIX := /usr/local
INSTALL_DIR := $(PREFIX)/bin
MAN_DIR := $(PREFIX)/share/man/man8

all: $(PROG)

$(PROG): $(SRCS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
license.inc: LICENSE
xxd -i $^ > $@

$(PROG): $(SRCS) $(INCS)
$(CC) $(CFLAGS) -o $@ $(SRCS) $(LDFLAGS)
strip $@

$(PROG)-static: $(SRCS) $(INCS)
$(CC) $(CFLAGS) -o $@ $(SRCS) -static $(LDFLAGS)
strip $@

$(PROG)-static: $(SRCS)
$(CC) $(CFLAGS) -o $@ $^ -static $(LDFLAGS)
$(PROG)-debug: $(SRCS) $(INCS)
$(CC) -g $(CFLAGS) -o $@ $(SRCS) $(LDFLAGS)

install:
install -d 0755 $(DESTDIR)$(INSTALL_DIR)
install -m 0755 $(PROG) $(DESTDIR)$(INSTALL_DIR)
install -d 0755 $(DESTDIR)$(MAN_DIR)
install -m 0644 su-exec.1 $(DESTDIR)$(MAN_DIR)

clean:
rm -f $(PROG) $(PROG)-static
rm -f $(PROG) $(PROG)-static $(PROG)-debug $(INCS)

106 changes: 106 additions & 0 deletions include/static_assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copied from https://github.com/wc-duck/dbgtools/blob/master/include/dbgtools/static_assert.h
*/
/*
dbgtools - platform independent wrapping of "nice to have" debug functions.

version 0.1, october, 2013

https://github.com/wc-duck/dbgtools

Copyright (C) 2013- Fredrik Kihlander

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

Fredrik Kihlander
*/

#ifndef DBGTOOLS_STATIC_ASSERT_INCLUDED
#define DBGTOOLS_STATIC_ASSERT_INCLUDED

/**
* Compile-time check that condition is true, if false a compile-time error will be generated.
* This macro tries to use a built in variant of static assert to generate as good errors as possible but fall back to a generic implementation
* if that is not available.
*
* @note msg will be ignored and an "as good as possible" message will get displayed instead if compiler has no built in support for static assert.
*
* @note macro do unfortunately not work within structs in its c-implementation =/
* @note on compilers that do not support __COUNTER__ static_assert_counter.h will be used to generate a counter. This however forces the user to include
* static_assert.h in each file where it is used ( as should be done anyways ).
*
* @example STATIC_ASSERT( sizeof( int ) == 4, "size of int is not 4!" );
*/
#define STATIC_ASSERT(cond, msg)
#undef STATIC_ASSERT

// ... clang ...
#if defined( __clang__ )
# if defined( __cplusplus ) && __has_feature(cxx_static_assert)
# define STATIC_ASSERT( cond, msg ) static_assert( cond, msg )
# elif __has_feature(c_static_assert)
# define STATIC_ASSERT( cond, msg ) _Static_assert( cond, msg )
# endif

// ... msvc ...
#elif defined( _MSC_VER ) && ( defined(_MSC_VER) && (_MSC_VER >= 1600) )
# define STATIC_ASSERT( cond, msg ) static_assert( cond, msg )

// ... gcc ...
#elif defined( __cplusplus )
# if __cplusplus >= 201103L || ( defined(_MSC_VER) && (_MSC_VER >= 1600) )
# define STATIC_ASSERT( cond, msg ) static_assert( cond, msg )
# endif
#elif defined( __STDC__ )
# if defined( __STDC_VERSION__ )
# if __STDC_VERSION__ >= 201112L
# define STATIC_ASSERT( cond, msg ) _Static_assert( cond, msg )
# else
# define STATIC_ASSERT( cond, msg ) _Static_assert( cond, msg )
# endif
# endif
#endif

/* if we couldn't detect a builtin static assert, lets define one! */
#ifndef STATIC_ASSERT
# if defined( __COUNTER__ )
# define DBGTOOLS_STATIC_ASSERT_MACRO_TOKENS_DO(line) DBGTOOLS_STATIC_ASSERT_MACRO_TOKENS_DO1(__COUNTER__,line)
# else
# define DBGTOOLS_STATIC_ASSERT_MACRO_TOKENS_DO(line) DBGTOOLS_STATIC_ASSERT_MACRO_TOKENS_DO1(DBG_TOOLS_STATIC_ASSERT_COUNTER,line)
# endif
# define DBGTOOLS_STATIC_ASSERT_MACRO_TOKENS_DO1(count,line) DBGTOOLS_STATIC_ASSERT_MACRO_TOKENS_DO2(count,line)
# define DBGTOOLS_STATIC_ASSERT_MACRO_TOKENS_DO2(count,line) static_assert_##count##_at_line_##line
#
# if defined( _MSC_VER )
# if defined( __cplusplus )
template<bool> struct DBG_TOOLS_STATIC_ASSERT_IMPL;
template<> struct DBG_TOOLS_STATIC_ASSERT_IMPL<true> {};
# define STATIC_ASSERT( cond, msg ) struct DBGTOOLS_STATIC_ASSERT_MACRO_TOKENS_DO( __LINE__ ) { DBG_TOOLS_STATIC_ASSERT_IMPL<(cond)> a; }
# else
# define STATIC_ASSERT( cond, msg ) enum { DBGTOOLS_STATIC_ASSERT_MACRO_TOKENS_DO( __LINE__ ) = 1 / (!!(cond)) }
# endif
# else
# define STATIC_ASSERT( cond, msg ) typedef char DBGTOOLS_STATIC_ASSERT_MACRO_TOKENS_DO( __LINE__ )[ (cond) ? 1 : -1 ] __attribute__ ((unused))
# endif
#endif

#endif

// This inclusion is outside the ifdef on purpose.
#if !defined( __COUNTER__ )
# include "static_assert_counter.h"
#endif
Loading